Interview Questions

How to Create a Test Using Winrunner (5)

Introduction To WinRunner Basics


(Continued from previous question...)

How to Create a Test Using Winrunner (5)

Parameterize Standard Database Checkpoints

While creating a standard database checkpoint using ODBC (Microsoft Query), user can add parameters to an SQL statement to parameterize the checkpoint. A parameterized query is a query in which at least one of the fields of the WHERE clause is parameterized, i.e., the value of the field is specified by a question mark symbol (?).

To execute a parameterized query, user must specify the values for the parameters.

To parameterize the SQL statement in the checkpoint, the db_check function has a fourth, optional, argument the parameter_array argument.

Syntax:-
db_check (checklist, expected_results_file [, max_rows [, parameter_array]]);

The parameter_array argument will contain the values to substitute for the parameters in the parameterized checkpoint. WinRunner cannot capture the expected result set while recording the test. Unlike regular database checkpoints, recording a parameterized checkpoint requires additional steps to capture the expected results set. Therefore, user must use array statements to add the values to substitute for the parameters. User must run the test in Update mode once to capture the expected results set before running the test in Verify mode.

TSL Functions for Working with ODBC (Microsoft Query)
When the user works with ODBC (Microsoft Query), user must perform the following steps in the following order:

Connect to the database.
Execute a query and create a result set based on an SQL statement.
Retrieve information from the database.
Disconnect from the database.

Connect to the database.
Syntax:-db_connect (session_name, connection_string [, timeout]);
session_name The logical name or description of the database session.
connection_string The connection parameters to the ODBC database.
timeout The number of seconds before the login attempt times out.


The db_connect function creates the new session_name database session and uses the connection_string to establish a connection to an ODBC database. User can use the Function Generator to open an ODBC dialog box, in which user can create the connection string. If user tries to use a session name that has already been used, WinRunner will delete the old session object and create a new one using the new connection string.

Execute a query and create a result set based on an SQL statement.
Syntax:-db_execute_query ( session_name, SQL, record_number );
SQL The SQL statement to be executed
record_number An out parameter returning the number of records in the result query.


The db_execute_query function executes the query based on the SQL statement and creates a record set. User must use a db connect statement to connect to the database before using this function.

Retrieve information from the database.
Syntax:-db_get_field_value (session_name, row_index, column);
row_index The index of the row written as a string: "# followed by the numeric index. (The first row is always numbered "#0".)
column name of the field in the column


The db_get_field_value function returns the value of a single field in the specified row_index and column in the session_name database session. In case of an error, an empty string will be returned. Before using this function user must use a db connect statement, connect to the database and db execute query statement, execute a query.


Syntax:-db_get_headers (session_name, header_count, header_content);
header_count The number of column headers in the query.
header_content The column headers concatenated and delimited by tabs. If this string exceeds 1024 characters, it is truncated.

The db_get_headers function returns the header_count and the text in the column headers in the session_name database session. Before using this function user must use a db connect statement, connect to the database and db execute query statement, execute a query.

Syntax:-db_get_row (session_name, row_index, row_content);
row_index The numeric index of the row. (The first row is always numbered "0".)
row_content The row content as a concatenation of the fields values, delimited by tabs.

The db_get_row function returns the row_content of the specified row_index, concatenated and delimited by tabs in the session_name database session. Before using this function user must use a db connect statement, connect to the database and db execute query statement, execute a query.

Syntax:-db_write_records (session_name, output_file [, headers [, record_limit]]);
output_file The name of the text file in which the record set is written.
headers An optional Boolean parameter that will include or exclude the column headers from the record set written into the text file. record_limit The maximum number of records in the record set to be written into the text file. A value of NO_LIMIT (the default value) indicates there is no maximum limit to the number of records in the record set.

The db_write_records writes the record set of the session_name into an output_file delimited by tabs. Before using this function user must use a db connect statement, connect to the database and db execute query statement, execute a query.

Syntax:-db_get_last_error ( session_name, error );
error The error message.

The db_get_last_error function returns the last error message of the last ODBC or Data Junction operation in the session_name database session. If there is no error message, an empty string will be returned. User must use a db connect statement to connect to the database before using this function.

Disconnect from the database.
Syntax:-db_disconnect ( session_name );

The db_disconnect function disconnects from the session_name database session. User must use a db connect statement to connect to the database before using this function.

Specifying the Verification Method
User can select the verification method to control how WinRunner identifies columns or rows within a result set. The verification method applies to the entire result set. Specifying the verification method is different for multiple-column and single-column result sets.

Specifying the Verification Method for a Multiple-Column Result Set
Column
Name (default setting)

WinRunner looks for the selection according to the column names. A shift in the position of the columns within the result set does not result in a mismatch.

Index WinRunner looks for the selection according to the index, or position, of the columns. A shift in the position of the columns within the result set results in a mismatch. Select this option if the result set contains multiple columns with the same name.
Row
Key WinRunner looks for the rows in the selection according to the key(s) specified in the Select key columns list box, which lists the names of all columns in the result set. A shift in the position of any of the rows does not result in a mismatch. If the key selection does not identify a unique row, only the first matching row will be checked.

Index (default setting) WinRunner looks for the selection according to the index, or position, of the rows. A shift in the position of any of the rows results in a mismatch.

Specifying the Verification Method for a Single-Column Result Set
By position WinRunner checks the selection according to the location of the items within the column.
By content WinRunner checks the selection according to the content of the items, ignoring their location in the column.


Specifying the Verification Type
WinRunner can verify the contents of a result set in several different ways. User can choose different verification types for different selections of cells.

Case Sensitive (the default)
WinRunner compares the text content of the selection. Any difference in case or text content between the expected and actual data results in a mismatch.

Case Sensitive Ignore Spaces
WinRunner checks the data in the field according to case and content, ignoring differences in spaces. WinRunner reports any differences in case or content as a mismatch.

Case Insensitive WinRunner compares the text content of the selection. Only differences in text content between the expected and actual data result in a mismatch.

Case Insensitive Ignore Spaces
WinRunner checks the content in the cell according to content, ignoring differences in case and spaces. WinRunner reports only differences in content as a mismatch.

Numeric Content WinRunner evaluates the selected data according to numeric values. WinRunner recognizes, for example, that “2” and “2.00” are the same number.

Numeric Range WinRunner compares the selected data against a numeric range. Both the minimum and maximum values are any real number that the user specifies. This comparison differs from text and numeric content verification in that the actual database data is compared against the range that user defined and not against the expected results.

(Continued on next question...)

Other Interview Questions