如何使用多个输入文件运行相同的编码UI测试 [英] How can I run the same Coded UI test with multiple input files
问题描述
我正在寻找一种方法,可以使用不同的输入文件来运行相同的编码ui测试类,例如我在应用程序中有一个端到端流程的测试,我希望能够让两个不同的用户在应用程序内部执行不同的工作流程时运行此测试.我不想每次都运行两个测试(在数据输入csv中有两行是可能的).到目前为止,我还没有找到一种方法来做到这一点.任何帮助/指导表示赞赏.
I am looking for a way to be able to run the same coded ui test class with different input files, e.g. I have a test with end to end flow in the app, I want to be able to run this test with two different users doing different workflows once inside the app. I do not want to run both the tests each time (This is possible with having two rows in the data input csv). I wasn't able to find a way of doing this so far. Any help/guidance is appreciated.
推荐答案
我可以想到三种可能性.
I can think of three possibilities.
1.
您可以将CSV安排为具有两组列,例如
You could arrange the CSV to have two groups of columns, eg
UserName1,Password1,DataAa1,DataBb1,UserName2,Password2,DataAa2,DataBb2
在测试方法中,将数据源访问更改为使用类似
Within the test method change the data source accesses to use something like
string testCode = (...) ? "1" : "2";
... = TestContext.DataRow["UserName" + testCode].ToString();
... = TestContext.DataRow["Password" + testCode].ToString();
这需要其他一些内容来指定要使用的数据文件.这可以通过环境变量来完成.
This requires something else to specify which data file to use. That could be done via an environment variable.
2.
解决方案中有三个CSV文件.其中两个是两次运行的CSV文件.例如SourceData1.csv
和SourceData2.csv
.第三个文件是SourceData.csv
,在[DataSource(...)
属性中命名为"|DataDirectory|\\SourceData.csv"
.在".testsettings"文件中,输入批处理文件的名称,该批处理文件选择所需的SourceData1.csv
或SourceData2.csv
文件,并使用xcopy
复制该文件并覆盖SourceData.csv
.
Have three CSV files within the solution. Two of them are the CSV files for the two runs. For example SourceData1.csv
and SourceData2.csv
. The third file is SourceData.csv
and is named in the [DataSource(...)
attribute as "|DataDirectory|\\SourceData.csv"
. In the ".testsettings" file give the name of a batch file that chooses the wanted SourceData1.csv
or SourceData2.csv
file and uses xcopy
to copy that file and overwrite SourceData.csv
.
3.
假设测试当前编写为
[TestMethod, DataSource(...)]
public void MyCodedUiTestMethod() {
...body of the test
}
然后更改为具有两个调用第三个方法的测试方法.这两种方法指定了不同的CSV文件,并且被调用的方法从正在读取的文件中访问值.
Then change to having two test methods that call a third method. These two methods specify different CSV files and the called method accesses values from the whichever file is being read.
[TestMethod, DataSource(... SourceData1.csv ...)]
public void MyFirstCodedUiTestMethod() {
BodyOfTheTest();
}
[TestMethod, DataSource(... SourceData2.csv ...)]
public void MySecondCodedUiTestMethod() {
BodyOfTheTest();
}
public void BodyOfTheTest() {
...body of the test
... = TestContext.DataRow["UserName"].ToString();
... = TestContext.DataRow["Password"].ToString();
}
请注意,TextContext
在该类的所有方法中都是可见的,因此TestContext.DataRow...
表达式可以写在指定[DataSource...]
属性的方法之外.
Note that TextContext
is visible in all methods of the class hence the TestContext.DataRow...
expressions can be written outside the methods that specify the [DataSource...]
attribute.
这篇关于如何使用多个输入文件运行相同的编码UI测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!