Typically, we want to repeat a test with a different data value. This "Data driven" is very easy in coded UI test. In this example, we created a coded UI test to verify that the two digits in the calculator were incremented. Now, let's see how we can turn a simple codedui test into a data-driven test.
1, first create the Coded UI test (create the Coded UI test) (refer to the previous instance);
Then create the dataset. Coded UI test supports multiple data sources. The dataset can be defined in a CSV (comma-separated value) file, an Excel worksheet, an XML file, a database table, or a test case on TFS. In the example, we will use the data CSV file (TESTDATA.CSV) with the following.
Add1 |
Add2 |
Sum |
8 |
2 |
10 |
6 |
2 |
8 |
4 |
2 |
6 |
L Create a Testdata.csv file
"CSV" is the abbreviation for comma separated value (comma separated values), usually a plain text file that can be opened with Notepad. Open Excel, and copy the above data to Excel, select Menu | file | Save As, select CSV format, you can create a CSV file.
For each recording operation, VSTS can abstract it into a method that stores the actions in a static method in the UIMap.Designer.cs class. You can make any modifications to these methods, or you can add an input parameter to the method you want to enter.
2, add the data source to the Coded UI test (add the the data source binding in coded UI test).
1 Open vs Menu | Test view-> Windows-> test View, as shown in Figure 1.
Figure 1 Coded the UI test property to create a data connection
3 through the above operation, open the New Data Source wizard interface, create a data source. Select CSV file-> Click Next, as shown in Figure 2.
Figure 2 New Data Source Wizard