|
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.
Create a new script and record the actions in a Web page.
Insert a test case using the Insert Testcase option in the Script Editor toolbar. This will display the Test Case Configuration screen.
From this screen, click the Add button in the CheckPoint List and specify the test case details such as Test case id, severity and description.
Click the radio option HTML Check. This will display the options Element, Text and Table. Please note that you can add test variables only for element and table checkpoints in a test case.
Click on the Element radio option and select an element from the Web page whose attributes need to be validated.
The Test Case Configurator screen will display all the attributes of the selected object. You will be able to view two columns Property and Value. Each Value field will have a Browse button next to it. Click the Browse button from the appropriate field which will display the Select Test Variables screen.
In the above screen, you can either select the test variables (if available) or add new test variables by clicking the Create New Variable link. This will display the Configure Test Variables screen. In this screen, you can add test variables using the steps given below in Adding Test Variables.
After selecting a test variable from the Available Test Variables combo, click the Apply button to add the test variable to the attribute value. For e.g., this will add the variable as TEST_VAR('Emp_Name').
Click Commit To List and click Apply. This will add the test case to the test script. Now, this has generated the test case with one set of data. Now to convert this base test script to include the test case with multiple set of data, follow the steps given below in Converting the Base Script to include Data-Driven Test Case.
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") |
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:
Click the '+' symbol next to the Variable column. This will add a new row.
Enter the variable name in the Variable Name column.
Enter the variable value in the Value column. Add as many test variables and values as required by clicking the '+' symbol.
After adding test variables and values, click the Save button to apply the changes.
To delete test variables,
Click the delete symbol to delete a particular test variable.
Click the Save button to apply the changes.
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:
Insert data configuration to fetch values from an external database, from CSV file or using variable substitution option. Please refer to the details in the topic Creating Data-Driven Test Scripts.
Insert Jython for loop construct to iterate through the multiple set of data.
Insert the setTestVariable() using the Function Generator tool to set the required variables to be used in the test case at runtime.
Choose the Function Generator tool using the Insert Built-in Function option from the Script Editor toolbar. This will display the Function Generator tool.
From this screen, choose the "Category" as General and "Function" as setTestVariable().
Enter the variable name and variable value.
Click the Paste button to paste the function in the script.
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) |
|