Interview Questions

How to Create a Test Using Winrunner (8)

Introduction To WinRunner Basics


(Continued from previous question...)

How to Create a Test Using Winrunner (8)


Converting a test to a Data-Driven test

User can convert the test to a Data-Driven test by Data Driver Wizard or by modifying the script manually. The procedure for converting a test to a data-driven test is composed of the following main steps:

Assigning a variable name to the data table (mandatory when using the Data Driver wizard and otherwise optional)
Add statements to the script that open and close the data table.
Adding statements and functions to the test so that it will read the data from the data table and run in a loop, while it reads each iteration of data.
Replace fixed values in checkpoint statements and in recorded statements with parameters.
Create a data table containing values for the parameters. This is known as parameterize the test.

To create data-driven tests select lines in the test script:
Go to Choose Table >Data Driver Wizard.

The Data Driver Wizard pop up opens with the "Use a new or existing Excel table" box which displays the name of the Excel file that WinRunner creates, which stores the data for the data-driven test.

In the “Assign a name to the variable” box, enter a variable name with which to refer to the data table.

Check the “Add statements to create a data-driven test" check box which automatically adds statements to run the test in a loop. If the user do not choose to select this option user will receive a warning that data-driven test must contain a loop and statements to open and close the data table. User should not select this option if the user has chosen it previously while running the Data Driver wizard on the same portion of the test script.

If the user wants to Imports data from a database check the "Import data from a database" check box. In order to import data from a database, either Microsoft Query or Data Junction must be installed on the machine.

Check the "Parameterize the test" check box which replaces fixed values in selected checkpoints and in recorded statements with parameters and in the data table, adds columns with variable values for the parameters.

Select the "Line by line" option if the user decide to parameterize a particular line, and if so, whether to add a new column to the data table or use an existing column when parameterize data.

Select the "Automatically" option if the user decides to replaces all data and adds new columns to the data table.

In the Next screen "Test script line to parameterize" box displays the line of the test script to parameterize. The highlighted value can be replaced by a parameter. “Argument to be replaced” box displays the argument (value) that user can replace with a parameter. User can use the arrows to select a different argument to replace. User has to Choose whether and how to replace the selected data. After finishing the parameterization the final screen of the wizard opens where the user if needed can see the data table created.

Assigning the Main Data Table for a Test

The main data table is the table that is selected by default when user choose Tools >Data Table or open the Data Driver wizard. To assign the main data table for a test:
Go to File >Test Properties and click the General tab.

Choose the data table user want to assign from the Main data table list. All data tables that are stored in the test folder are displayed in the list.

Using Data-Driven Checkpoints and Bitmap Synchronization Points

When checking the properties of GUI objects in a data-driven test, it is better to create a single property check than to create a GUI checkpoint which contains references to a checklist stored in the test’s chklist folder and expected results stored in the test’s exp folder. A single property check does not contain checklist, so it can be easily parameterized. In order to parameterize GUI and bitmap checkpoints and bitmap synchronization points statements. First create separate columns for each checkpoint or bitmap synchronization point. Then enter dummy values in the columns to represent captured expected results. While running the test in Update mode, WinRunner recaptures expected values for GUI and bitmap checkpoints automatically. WinRunner prompts user before recapturing expected values for bitmap synchronization points. And save all the results in the test’s exp folder.

Using TSL Functions with Data-Driven Tests
Opening a Data Table
ddt_open (data_table_name [, mode]);

data_table_name The name of the data table. The name may be the table variable name, the Microsoft Excel file or a tabbed text file name, or the full path and file name of the table. The first row in the file contains the names of the parameters. This row is labeled row 0.

mode The mode for opening the data table: DDT_MODE_READ (read-only) or DDT_MODE_READWRITE (read or write). When the mode is not specified, the default mode is DDT_MODE_READ.

The ddt_open function opens the data table file with the specified data_table_name. The active row becomes row number 1. User must use a ddt_open statement to open the data table before using any other ddt_functions.

Saving a Data Table
ddt_save (data_table_name);

The ddt_save function saves the information in a data table in its existing format. ddt_save does not close the data table. Use the ddt_close to close the data table.

Closing a Data Table
ddt_close (data_table_name);

The ddt_close function closes the specified data table. ddt_close does NOT save changes to the data table. If user makes any changes to the data table, user must use the ddt_save function to save the changes before using ddt_close to close the table. The ddt_close function will not close the table if it is currently open in the table editor, regardless of whether it was opened from the WinRunner menu or using the ddt_show function. The ddt_close function checks if the table editor is displaying the table, and if so, leaves it open.

Displaying the Data Table Editor
dt_show (data_table_name [, show_flag]);
show_flag The value indicating whether the editor should be shown (default=1) or hidden (0).

The ddt_show function allows the table editor to be shown or hidden. The show_flag value is 1 if the table editor is to be shown and is 0 if the table editor is to be hidden.

Exporting a Data Table
ddt_export (data_table_name1, data_table_name2);
data_table_name1 The source data table filename.
data_table_name2 The destination data table filename.
The ddt_export function sends the contents of data_table_name1 to data_table_name2

Returning the Number of Rows in a Data Table
dt_get_row_count (data_table_name, out_rows_count);
out_rows_count The output variable that stores the total number of rows in the data table.
The ddt_get_row_count function retrieves the number of rows in the specified data table.


Changing the Active Row in a Data Table to the Next Row
ddt_next_row (data_table_name);

The ddt_next_row function changes the active row in the specified data table to the next row. If the active row is the last row in a data table, then the E_OUT_OF_RANGE value is returned.

Setting the Active Row in a Data Table
ddt_set_row (data_table_name, row);
row The new active row in the data table.

The ddt_set_row function sets the active row in the specified data table. When the data table is first opened, the active row is the first row.

Setting a Value in the Current Row of the Table
ddt_set_val (data_table_name, parameter, value);
parameter The name of the column into which the value will be inserted.
value The value to be written into the table.

The ddt_set_val function sets a value in a cell of the current row of a database. User can only use this function if the data table was opened in DDT_MODE_READWRITE (read or write mode).

Setting a Value in a Row of the Table
ddt_set_val_by_row (data_table_name, row, parameter, value);
row The row number in the table. It can be any existing row or the current row number plus 1, which will add a new row to the data table.
parameter The name of the column into which the value will be inserted.
value The value to be written into the table.

The ddt_set_val_by_row function sets a value in a specified cell in the table. User can only use this function if the data table was opened in DDT_MODE_READWRITE (read or write mode).

Retrieving the Active Row of a Data Table
ddt_get_current_row ( data_table_name, out_row );
out_row The output variable that stores the active row in the data table.

The ddt_get_current_row function retrieves the active row in the specified data table and returns this value as out_row.

Determining Whether a Parameter in a Data Table is Valid
ddt_is_parameter (data_table_name, parameter);
parameter The parameter name to check in the data table.

The ddt_is_parameter function returns whether a parameter in the specified data table is valid.

Returning a List of Parameters in a Data Table
ddt_get_parameters (data_table_name, params_list, params_num);
params_list This out parameter returns the list of all parameters in the data table, separated by tabs.
params_num This out parameter returns the number of parameters in params_list.
The ddt_get_parameters function returns a list of all parameters in a data table.

Returning the Value of a Parameter in the Active Row in a Data Table
ddt_val (data_table_name, parameter);

The ddt_val function returns the value of a parameter in the active row in the specified data table.
Returning the Value of a Parameter in a Row in a Data Table
ddt_val_by_row (data_table_name, row_number, p

(Continued on next question...)

Other Interview Questions