Using TSL Functions with Data-Driven Tests - WinRunner

WinRunner provides several TSL functions that enable you to work with data-driven tests.

You can use the Function Generator to insert the following functions in your test script, or you can manually program statements that use these functions.

Opening a Data Table

The ddt_open function creates or opens the specified data table. The data table is a Microsoft Excel file or a tabbed text file. The first row in the Excel/tabbed text file contains the names of the parameters. This function has the following syntax:

ddt_open ( data_table_name [ , mode ] );

The data_table_name is the name of the data table. The mode is the mode for opening the data table: DDT_MODE_READ (read-only) or DDT_MODE_READWRITE (read or write).

Saving a Data Table

The ddt_save function saves the information in the specified data table. This function has the following syntax:

ddt_save ( data_table_name );

The data_table_name is the name of the data table.

Note that ddt_save does not close the data table. Use the ddt_close function, described below, to close the data table.

Closing a Data Table

The ddt_close function closes the specified data table. This function has the following syntax:

ddt_close ( data_table_name );

The data_table_name is the name of the data table.
Note that ddt_close does not save changes made to the data table. Use the ddt_save function, described above, to save changes before closing the data table.

Exporting a Data Table

The ddt_export function exports the information of one table file into a different table file. This function has the following syntax:

ddt_export ( data_table_filename1, data_table_filename2 );

The data_table_filename1 is the name of the source data table file. The data_table_filename2 is the name of the destination data table file.

Displaying the Data Table Editor

The ddt_show function shows or hides the editor of a given data table. This function has the following syntax:

ddt_show ( data_table_name [ , show_flag ] );

The data_table_name is the name of the table. The show_flag is the value indicating whether the editor should be displayed (default=1) or hidden (0).

Returning the Number of Rows in a Data Table

The ddt_get_row_count function returns the number of rows in the specified data table. This function has the following syntax:

ddt_get_row_count ( data_table_name, out_rows_count );

The data_table_name is the name of the data table. The out_rows_count is the output variable that stores the total number of rows in the data table.

Changing the Active Row in a Data Table to the Next Row

The ddt_next_row function changes the active row in the specified data table to the next row. This function has the following syntax:

ddt_next_row ( data_table_name );

The data_table_name is the name of the data table.

Setting the Active Row in a Data Table

The ddt_set_row function sets the active row in the specified data table. This function has the following syntax:

ddt_set_row ( data_table_name, row );

The data_table_name is the name of the data table. The row is the new active row in the data table.

Setting a Value in the Current Row of the Table

The ddt_set_val function writes a value into the current row of the table. This function has the following syntax:

ddt_set_val ( data_table_name, parameter, value );

The data_table_name is the name of the data table. The parameter is the nameof the column into which the value will be inserted. The value is the value to be written into the table.

Setting a Value in a Row of the Table

The ddt_set_val_by_row function sets a value in a specified row of the table. This function has the following syntax:

ddt_set_val_by_row ( data_table_name, row, parameter, value );

The data_table_name is the name of the data table. The row is 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. The parameter is the name of the column into which the value will be inserted. The value is the value to be written into the table.

Retrieving the Active Row of a Data Table

The ddt_get_current_row function retrieves the active row in the specified data table. This function has the following syntax:

ddt_get_current_row ( data_table_name, out_row );

The data_table_name is the name of the data table. The out_row is the output variable that stores the specified row in the data table.

Determining Whether a Parameter in a Data Table is Valid

The ddt_is_parameter function determines whether a parameter in the specified data table is valid. This function has the following syntax:

ddt_is_parameter ( data_table_name, parameter );

The data_table_name is the name of the data table. The parameter is the name of the parameter in the data table.

Returning a List of Parameters in a Data Table

The ddt_get_parameters function returns a list of all parameters in the specified data table. This function has the following syntax:

ddt_get_parameters ( data_table_name, params_list params_num );

The data_table_name is the name of the data table. The params_list is the out parameter that returns the list of all parameters in the data table, separated by tabs. The params_name is the out parameter that returns the number of parameters in params_list.

Returning the Value of a Parameter in the Active Row in a Data Table

The ddt_val function returns the value of a parameter in the active row in the specified data table. This function has the following syntax:

ddt_val ( data_table_name, parameter );

The data_table_name is the name of the data table. The parameter is the name of the parameter in the data table.

Returning the Value of a Parameter in a Row in a Data Table

The ddt_val_by_row function returns the value of a parameter in the specified row of the specified data table. This function has the following syntax:

ddt_val_by_row ( data_table_name, row_number, parameter );

The data_table_name is the name of the data table. The parameter is the name of the parameter in the data table. The row_number is the number of the row in the data table.

Reporting the Active Row in a Data Table to the Test Results

The ddt_report_row function reports the active row in the specified data table to the test results. This function has the following syntax:

ddt_report_row ( data_table_name );

The data_table_name is the name of the data table.

Importing Data from a Database into a Data Table

The ddt_update_from_db function imports data from a database into a data table. It is inserted into your test script when you select the Import data from a database option in the DataDriver wizard. When you run your test, this function updates the data table with data from the database. This function has the following syntax:

ddt_update_from_db ( data_table_name, file,out_row_count[ , max_rows ] );

The data_table_name is the name of the data table.

The file is an *.sql file containing a query defined by the user in Microsoft Query or *.djs file containing a conversion defined by Data Junction. The aemout_row_count is an out parameter containing the number of rows retrieved from the data table. The max_rows is an in parameter specifying the maximum number of rows to be retrieved from a database. If no maximum is specified, then by default the number of rows is not limited.


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

WinRunner Topics