An application has to be tested with multiple sets of data. The automation test script written for one input can be used for number of inputs using data driven test in Winrunner. The test script has to be converted into the data driven test by creating a corresponding data table with the sets of data you want to test.
Steps involved in creating data driven tests:
The following steps are involved in converting the test script into the data driven test:
- Adding statements to your script that open and close the data table.
- Adding statements and functions to the test so that it will read from the data table and run in a loop while it applies each set of data.
- Replacing the fixed values in the recorded statements and checkpoint statements with parameters, known as parameterizing the test.
The Data Driver Wizard contains the following features
- The data table.
- The name of the variable used to refer to the data table.
- Different options used to convert the test script into the data driven test script.
When the option "Add statements to create the test" is selected, the TSL statements will be added to the test the define the table variable name, open and close the data table and run the appropriate script selection in a loop for each row in the data table.
When the option "Parameterize the test" is selected and line-by-line option is selected, the Winrunner finds the fixed values in the recorded statements and selected checkpoints. The line-by-line option instructs the wizard to open a screen for each line of the selected test that can be parameterized so that you can choose whether or not to parameterize that line.
The following elements are added to the data driver test script:
The ddt_open statement opens the table and the subsequent lines confirm that the data-driven test opens successfully.
The ddt_get_row_count statement checks how many rows are in the table and therefore how many iterations of the parameterized section of the test to perform.
The for statement sets up the iteration loop.
The ddt_set_row statement tells the test which row of the table to use on each iteration.
The ddt_close statement closes the table.
Adding Data to the Data Table
After parameterizing the test script, the data, which the parameterized test will use, should be added. The data table can be accessed through the option Tools-> data table. An excel sheet opens up with the column names. Add the required data to the data table and save the table.
Major thing to be considered while dealing with data driver wizard is it does not check for things such as object labels that may also vary based on external input. The wizard only finds the fixed points in the test script.
In order to overcome the above problem, "Regular expression" is used. A regular expression is a string that specifies a complex search phrase in order to enable Winrunner to identify objects with varying names or titles. The object labels name has to be changed with a general value in the GUI map editor.
The data driven test can be run now for multiple number of test data. Thus data driven test can be used when the application has to be tested for a number of input data.