|
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:

You can fetch and substitute values dynamically from a
Database, such as Oracle, Mysql, Sybase, etc
CSV file or
Using Variable Substitution
Inserting Data Configuration in Test Scripts
To insert data configuration in test scripts, perform the following steps:
Choose a script from the tree-view.
Place the cursor in the required location in the script where you need to insert data configuration.
Choose Data Configuration option from the script editor toolbar as shown above. The View Data Configuration screen is displayed.
To insert the already configured datasource, select the required datasource from the Select DataSource Name combo and click the Paste button to insert the data configuration in the script.
To add a new datasource, click the Add button placed next to the Select DataSource Name combo. This will display the Add/View Data Configuration screen.
In this screen, from the Select DataSource Type combo, select the datasource type such as database, csv, or variable. Enter the new datasource name in the DataSource Name field. This should be unique. If an existing name is given then the values configured are modified for the existing datasource.
Based on the selected datasource type, configure the appropriate values as given in the sub topics Fetching Data From Database, Fetching Data From CSV File or Fetching Data Using Variable Substitution Option.
After configuring the values, choose the Save button to save the configurations and choose the Paste button to paste the newly added datasource in the required location in the test script.
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 |
- |
To fetch data from CSV file:
In the Add/View Data Configuration screen, from the Select DataSource Type combo, select the datasource type as CSV.
Enter the appropriate values for the following field:
Select the csv file from the CSV File Name combo (if already available in <QEngine_Home>/projects/<Suite_Name>/dataset directory ) or create a new csv file name by clicking the Create CSV File link. Please note that the csv files displayed in the combo and the newly created csv files are placed in the server in <QEngine_Home>/projects/<Suite_Name>/dataset directory.
Enter the start column and end column numbers to fetch the multiple column values like username and password. Configure the number of rows to be fetched by providing the start row and end row numbers. Start Row and Start Column number should start from 1.
Fetching Data Using Variable Substitution Option
This option is used to fetch values from the environmental variables or user-defined variables.
In the Add/View Data Configuration screen, from the Select DataSource Type combo, select the datasource type as Variable.
Select the reserved variables from the Variable List combo or add new environmental or user defined variables using the Add/Edit Environmental Variable link placed next to the Edit Date Variable field. The newly added variable will be displayed in the Variable List combo. To know the details of adding a new environmental variable, please refer to the context sensitive help.
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. |
To edit the configured values for data configuration, perform the following steps:
Choose a script from the tree-view.
Choose Data Configuration option from the script editor toolbar as shown above. The View Data Configuration screen is displayed.
To edit a datasource, from the View Data Configuration screen, select the datasource and click the Edit button. This will display the Add/View Data Configuration screen.
In this screen, edit the desired values and click the Save button.
To insert the edited datasource in the script, click the Paste button.
Viewing Existing Data Configuration Details
To view existing data configuration details, perform the following steps:
Choose a script from the tree-view.
Choose Data Configuration option from the script editor toolbar as shown above. The View Data Configuration screen is displayed. In this screen, you can view the list of available data configurations.
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.
|