作爲解決方法創建一個新類並添加此數據源。您可以使用相同的UIMap和相同的代碼,只需添加一個新的Coded UI Test。 「項目」 - >「新建CodedUI測試」。
我已經使用相同的Excel工作簿,但不同的表我的測試如下:
namespace Data_driven_testing
{
/// <summary>
/// Summary description for CodedUITest2
/// </summary>
[CodedUITest]
public class CodedUITest2
{
public CodedUITest2()
{
}
[DataSource("System.Data.Odbc", "Dsn=Excel Files;Driver={Microsoft Excel Driver (*.xls)};dbq=D:\\CodedUI\\Data_driven_testing\\Data_driven_testing\\Data.xls;defaultdir=.;driverid=790;maxbuffersize=2048;pagetimeout=5;readonly=true", "Sheet2$", DataAccessMethod.Sequential), TestMethod]
public void CodedUITestMethod1()
{
this.UIMap.RecordedMethod3Params.UITextBox1EditText = TestContext.DataRow["Input1"].ToString();
this.UIMap.RecordedMethod3Params.UITextBox2EditText = TestContext.DataRow["Input2"].ToString();
this.UIMap.RecordedMethod3();
// To generate code for this test, select "Generate Code for Coded UI Test" from the shortcut menu and select one of the menu items.
// For more information on generated code, see http://go.microsoft.com/fwlink/?LinkId=179463
}
namespace Data_driven_testing
{
/// <summary>
/// Summary description for CodedUITest1
/// </summary>
[CodedUITest]
public class CodedUITest1
{
public CodedUITest1()
{
}
//[TestMethod]
[DataSource("System.Data.Odbc", "Dsn=Excel Files;Driver={Microsoft Excel Driver (*.xls)};dbq=D:\\CodedUI\\Data_driven_testing\\Data_driven_testing\\Data.xls;defaultdir=.;driverid=790;maxbuffersize=2048;pagetimeout=5;readonly=true", "Sheet1$", DataAccessMethod.Sequential), TestMethod]
public void CodedUITestMethod1()
{
this.UIMap.RecordedMethod1Params.UITextBox3Text = TestContext.DataRow["Input1"].ToString();
this.UIMap.RecordedMethod1Params.UITextBox4EditText = TestContext.DataRow["Input1"].ToString();
this.UIMap.RecordedMethod1();
this.UIMap.RecordedMethod2Params.UITextBox5EditText = TestContext.DataRow["Input3"].ToString();
this.UIMap.RecordedMethod2Params.UITextBox6EditText = TestContext.DataRow["Input4"].ToString();
// this.UIMap.RecordedMethod2();
}
提供了錯誤信息,你得到的將幫助我們回答你的問題。 –
@EricScherrer 單元測試適配器無法連接到數據源或讀取數據。 – Adi
將輸入文件放在dll所在的bin \ Debug文件夾中。它應該工作。 – kida