Test Studio allows you to use external data files for data driven testing. This is a suitable option when the data required for the test is more complex and is maintained easier in external type of file or is exported from a different tool.
Let's start by adding a new test in the project and proceed with recording the steps to data drive. We can use the same test sample, described for the data driven test with built-in data.
Open a browser and navigate to the Telerik page to start the recording session. Record the following actions:
Click on the Search icon in the top navigation bar.
Enter 'Test Studio' in the Search field.
Click on the Search button.
To ensure that the search was performed correctly, it is recommended to add a step that waits until the first item of the results list contains the searched product name.
Once you add all necessary steps to the test, close the browser to finish the recording session.
To demonstrate the usage of external data source, let's prepare a sample Excel file. The data we need for this test is listed in a single row and contains different Telerik product names to search in the site.
The first row will be used to refer the column when binding it to the test steps. This is 'ProductName' in the described scenario.
To use the external file in a Test Studio project, you need to add a reference to this file in the project. Select the Project tab in the Test Studio window and hit the Add button from the Data Source section in the ribbon.
For more information, see How to add supported data files in the project.
Now that you have added a data source definition to your test project, you are ready to bind your test to that data source.
Choose a test from the Project Explorer and click the Bind Test button from the Data Source section in the Project ribbon.
When the external data source is set as desired, click the OK button to bind it to the selected test. Now the external file is associated with the test, and you can access the data values in the file and bind them to the steps.
For more information, see How to bind a test to the external data file.
Once the test has a reference to the data source, you can bind the values to the test steps:
Click on the Enter text step (number 3. for the current scenario) and open the Step Properties pane.
The Bindings property is the first in the list. Click the three dots button on the right to open the step fields that you can bind to data.
Depending on the project layout you are using, the Properties pane can have a different location within your project.
The Enter text step allows only its Text field to be data driven and, thus, it is the only one listed.
Click on the drop-down next to the Text field to expand the data source columns list. In this scenario, there is a single column in the list - the productName, so select this one.
Click on the Set button to confirm the selection and close the Properties pane.
See How to bind a step to a data source column for more information.
Apply the same sequence of steps for the wait step. We add a wait step to verify that the search action is completed successfully. Note that the field that you need to bind in the wait step properties is TextToMatch.
Now that the test is set up to take data from the built-in data table, you can see the two data-bound steps and the column they are connected to. To run the test, hit the Execute button and choose a browser for the execution.
Observing the test run, you will see that the 5 steps recorded in the test will be executed three times in a row. The difference in each of these iterations will be the product name entered in the Search field. This name corresponds to the products listed in the data table.
Once the test run finishes, you will see the quick execution results populated in the Test Pane. The results for each iteration are listed separately, and you can switch between them from the Iterations drop-down.
For more information, see how to read the results of a data driven test.