Creating Data-Driven Test Scripts

Overview

 

Data Configuration option enables you to create data-driven test scripts. You can add variables or parameterize lines in your test scripts to dynamically fetch and substitute values either from a database, comma separated values (CSV) file, or using variable substitution option. To create data-driven test scripts you need to insert data configuration at the required location in the test script. To invoke the Data Configuration screen, choose the Data Configuration link placed above the script editor toolbar as shown in the image given below:

 

 

Types of Data Configuration

 

You can fetch and substitute values dynamically from a

Inserting Data Configuration in Test Scripts

 

To insert data configuration in test scripts, perform the following steps:

Fetch Data From Database

 

To fetch data from database, in the Add/View Data Configuration screen, from the Select DataSource Type combo, select the datasource type as Database and enter  the appropriate values for the following fields:

 

Field Name

Value

Example

Database Name

Select the name of the database if available or configure database properties by clicking the Configure Database link.

ORACLE

URL

The database URL is a non-editable field which gets displayed based on the selected database or based on the configured details on choosing the Configure Database link. To know the details of adding/editing database details, refer to the topic Configuring Databases in QEngine.

oracle.jdbc.driver.OracleDriver

Query

Enter the SQL query to fetch the data from the database.

Select name, password from LoginTable.

Row Index and

Enter the row index from where the values has to be fetched.

2

Column Index (Or) Column Name

Enter the column index value or column name from where the values has to be fetched

-

 

Fetching Data From CSV File

 

To fetch data from CSV file:

Fetching Data Using Variable Substitution Option

 

This option is used to fetch values from the environmental variables or user-defined variables.

The values for the reserved variables are automatically substituted by QEngine as shown in the table below. You can make use of these reserved variables as per specific operating needs.

 

QEngine Reserved Variable

Value

$localhost

Substitutes the name of the host machine in which test is being executed.

$localip

Substitutes the IP Address of the host machine in which test is being executed.

$localnet

Substitutes the network address of the host machine in which test is being executed.

$date(dd_mm_yyyy)

Substitutes the system date, in the format specified, of the machine in which test is being executed.

$APPHOME

Substitutes the location of the Application Home directory.

$nexthour

Substitutes the system time of the machine +1 in which test is being executed.

$nextday

Substitutes the system date of the machine +1 in which test is being executed.

 

Editing Data Configuration

 

To edit the configured values for data configuration, perform the following steps:

Viewing Existing Data Configuration Details

 

To view existing data configuration details, perform the following steps:

Displaying Values from the Configured Datasource

 

When you click the Paste button in the Data Configuration screen, the selected datasource will be inserted in the script as given below:

 

Sample datasource inserted in the script after data configuration

 

initDataset("test_datasource");

result_array = getValuesFrom("test_datasource");

 

Here, initDataset() sets the datasource name test_datasource as a unique ID which is used for data source identification. Using this ID, values are dynamically fetched from the configured datasource such as database, csv or using variable substitution option.

 

The getValuesFrom() stores the fetched values in a 2D array based on the data source ID set in the  initDataset(). You can fetch values from the 2D array using a for loop as shown below.

 

for i in range(0,len(result)):

    for j in range(0,len(result[i])):

        displayMessage(str(result[i][j]));

 

You can also parameterize lines in the scripts using the variable str(result[i][j]) in a for loop to replace values dynamically during playback.



Copyright © 1999, AdventNet Inc. All Rights Reserved.