Data Driven Test with External Data
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.
How To Data Drive the Test
Let's start by adding a new test in the project and recording the steps to data drive. We can use the same test sample, described for the data driven test with built-in data.
Record the Steps to Data Drive
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, add a step that waits until the first item of the results list contains the searched product name.
Tip
For more details on wait steps, see here how to record one
For more details on steps using the text from an image, see here how to record such step.
Once you add all necessary steps to the test, close the browser to finish the recording session.
Prepare the Data Source
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.
Note
The first row will be used to refer the column when binding it to the test steps. This is 'productName' in the described scenario.
Add the External Data to the Project
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.
Tip
For more information, see How to add supported data files in the project.
Bind the External Data Source to Test
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.
Confirm Data Binding
When the external data source is configured 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.
Tip
For more information, see How to bind a test to the external data file.
Bind the Data to the Test Steps
Once the test has a reference to the data source, you can bind the values to the test steps:
-
Select the Enter text step (number 8. for the current scenario) and expand it with double-click.
-
Use the
Data Bind
button to open theData binding
dialog. It lists all step's fields which you can use for binding. -
The Enter text step allows only its
Text
field to be data driven so this is the only one listed in theBinding dialog
. Click on the drop-down next to theText
field and expand the data source columns list. In this scenario the data consists of a single column - theproductName
, so select this one.Tip
See How to bind a step to a data source column for more details. -
Confirm the binding with the
OK
button. -
The step gets updated and hints that is bound to some data.
-
Repeat the same sequence of actions for the Wait step. This step verifies that the search action is completed successfully. The field to bind in the Wait step properties is
ExpectedString
.
Execute the Data Driven Test and Review the Results
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.
Tip
For more information, see how to read the results of a data driven test.
Other data driven scenarios
- Test as steps used with data driven testing
- Data drive the find expression of an element in Test Studio
- Use data source columns in coded steps