Creating Data-Driven Test Cases

Overview

 

You can add test variables to parameterize attribute values in Element Checkpoint or Table Checkpoint. The values for the variables can be fetched either from a test script or using the data configuration option to fetch values from an external database or CSV file using environmental variables. This will enable you to execute a single test case with multiple set of data.

 

The test variables are configured using the Configure Test Variables screen. This screen is invoked using the Configure Test Variables option in the Script Editor toolbar or from the Test Case Configurator screen for element and table checkpoints.

 

Creating a Base Test Script with Test Case

 

Create a base test script with a test case using the following steps.

Example of a Base Test Script which includes Test Case with Single Set of Data

 

useLocalMapFile()

launchApplication("http://localhost:4444/examples/payrollsystem/index.html")

setWindow( "AdventNet Payroll System",5)

clickList("View",1)

setWindow( "AdventNet Payroll System Package - Form to View Employee Details",1)

setText("yourname","Mary",3)

setText("dept","Sales",3)

#Test case which includes element checkpoint to validate the property value #of employee name field.

executeTest("mytest1")

 

Adding Test Variables

 

You add test variables using the Configure Test Variables screen. This is invoked using the Configure Test Variables option in the Script Editor toolbar or from the Insert TestCase Configuration screen. The steps to add test variables are as follows:

To delete test variables,

Converting the Base Script to include Data-Driven Test Case

 

To convert the base test script to include a data-driven test case with multiple set of data, follow the steps given below:

For example, consider the sample script test-for-construct.wcs bundled in the default Suite AdventNetPayrollSystem which has been modified to include data-driven test case as follows. Here an element checkpoint is added in the test case to validate the property value of the employee name field for each employee.  

 

Example of a Data-Driven Test Case with Mutliple Set of Data

 

useLocalMapFile()

launchApplication("http://localhost:4444/examples/payrollsystem/index.html")

setWindow( "AdventNet Payroll System",5)

clickList("View",1)

setWindow( "AdventNet Payroll System Package - Form to View Employee Details",1)

initDataSet("test_datasource")

result = getValuesFrom("test_datasource")

#********************************************************************************

#result is a 2D array which stores the values fetched from the specified dataset.

#You can fetch values from the 2D array using a for loop. A sample is shown below.

#In this sample, based on the number of columns in the csv, name and dept values are fetched:

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

displayMessage(len(result))

name=str(result[i][0])

displayMessage(name)

dept=str(result[i][1])

displayMessage(name)

setText("yourname",name,3)

setText("dept",dept,3)

#setTestVariable function added to dynamically fetch the value from 2D array #and store in the test variable.

setTestVariable("varname",name)

#executeTest statement added after inserting a test case that includes an #element checkpoint with test variable substitution. Here, the value field

#for the employee name field is dynamically validated for each employee.

executeTest("mytest1")

#********************************************************************************

closeWindow( "QEngine - Redefining Software Quality",79)

 



Copyright © 1999, AdventNet Inc. All Rights Reserved.