Data driven testing is a testing methodology where test steps are performed using data input from a data source. The data source can be used for picking data values or even for comparing the expected values during any verification steps.
Different Source can be used as data source in Telerik Test Studio
- Local Data Source
- Excel Spreadsheet
- XML and CSV files
- SQL database
In this chapter we will learn how to perform Data Driven Testing with Telerik Using Excel Workbook.
Adding External Data Source to the Test
All the external data file that are referred, is stored in the data folder of the project. The file stored in this folder will be used to pick data, so all the changes should be made to this only. For example, file path will be something like this:
C:\UserName\User\Documents\Test Studio Projects\Project Name\Data
Let’s convert the test case we recorded in one of the previous tutorial of How to Record and Play in Telerik to a data driven test. Let’s recall the test case:
“Validate that user is able to fill all details in the contact form and send the details”
- Open Browser
- Open http://demoqa.com/
- Click on Contact Tab
- Enter your Name
- Enter Your Email
- Enter Subject
- Enter Your message
- Click on Send
- Verify that the message was sent
So, we already have recorded step for this test case, let’s make it data driven now. Looking at the test case, we can deduce that we will need following data:
- User Defined Message
Now, create an excel sheet with the aforementioned column names. (or provide any relevant column name)
Test Studio uses the first row of the excel worksheet as column name and it recognizes data based on the column name. Data can be entered from the second row.
(I personally prefer to bold the column name to distinguish it from test data.)
Now, the next step is to bind this excel with the test script. With Telerik Test Studio binding test case and test steps are quite easy.
1) Open Test Studio.
2) First, you will have to add a data source to the project. In the test studio home, click on the Project you have created on the left hand side of test studio. In our case, it is “TestProject”.
Once you click on the project name, Add icon will be highlighted.
3) Click on Add icon, following dialog box will appear. Select the type of data source and provide the path where you have same the data source (excel workbook).
4) After providing the file path, click on “Create” button. This will close the dialog box and data sheet will be added to your project.
Now, we have successfully added the data sheet to our project, but how test studio will know which column to use for which test step?
So, what we need to do is to bind each step with the test data column. First, we will have to bind the Test with the worksheet. You can create and use multiple worksheets but one test case can only be mapped to a single worksheet at a time for pulling data.
Add a Worksheet to the Test.
1) Click on the test Name, “Bind Test” icon will be highlighted.
2) Click on “Bind Test” icon, It will open a dialog box.
3) Click on the Select DATA SOURCE drop down. It contains a list of all the Workbooks which has been added to this project.
4) Select the “webTestDataDriven” workbook from the drop down. Once you select it, another dropdown “SELECT TABLE” will appear. The Select table contains a list of all the worksheet inside the workbook.
5) Click on the drop down to view the list and select the sheet name in while you have entered the data values. For us, it’s just Sheet1. Once you selected the sheet, all the data from the sheet will be displayed in the Preview frame.
6) Click on the “Bind” button and your worksheet will be bonded with the Test case.
Now, the next step will be to bind the Test Step with the column name in the Test data sheet.
7) Click on the properties tab in the right hand panel and then click on the button beside Bindings showing
“ . . .”. Once you click on this button, it will open list all the columns contained in the Data sheet added with the test.
8) From the drop down select the column name. Here, column name is search, column name provided by the user in the excel worksheet will appear here.
9) Once you have selected the column name click on the “Set” button.
Once you have added all the columns of the test data sheet to each of your test steps, the steps will be added with a suffix “-DataDriven[$(Column Name)]”
Now, Run the test case by clicking on the execute button in the top or by using Run à To Here to a particular step if you want to verify the data that is being entered.
Let’s run the test to step 7.
We will see that whatever data we have entered throug the excel sheet has been added to the fields based on the test steps.