|
Introduction
This sample webscript named test-for-construct is an illustration of writing data driven test cases and usage of programming constructs such as for loop in the scripts.
Assumption is that there exists a CSV (Comma Separated Value) file that stores details of the employees such as employee name, department. This data is going to drive the testing of the page view.html. 4 lines (records) exists in the CSV file. This file named test.csv is available in <QEngine Home>/examples/payrollsystem folder.
On executing the script test-for-construct, you will see that each employee's data is displayed in view.html. This is achieved using a for loop in the script.
Generating scripts with for loops
You need to manually insert the programming constructs such as for, if, while etc after doing the bare minimal recording of the web page. In case of test-for-construct script,
the page view.html was launched in a browser
some dummy values were entered in the text fields
recording was stopped.
This generated the skeletal script where the web page elements were recorded. Then the statements for reading the CSV file, storing the values into variables and replacing them in setText statements were done. Find below a walk through of the script lines.
Launch the browser and load the Payroll system home page.
|
useLocalMapFile()
launchApplication("about:blank") changeURL("$APPHOME/index.html",2)
|
Move to view.html
|
setWindow( "AdventNet Payroll System",2) clickList("View",2) setWindow( "AdventNet Payroll System Package - Form to View Employee Details",2)
|
Specify the CSV file name to be read from
|
initCSV("$APPHOME\test.csv")
|
Using the for loop, read the the lines 0 to 4 from the CSV file. Copy the values from file to local variables name and dept. Set these in the text fields of the web page.
|
for i in range(0,4): name=getCSVValueAt(i,1) dept=getCSVValueAt(i,2) setText("yourname",name,3) setText("dept",dept,3) |
Jython scripting language is used in webscripts and hence you can refer its syntax manual for the syntax of various programming constructs such as if, for, while etc.
On executing the script, you will see that the values are retrieved from the CSV file one by one and displayed in the form fields. To view the results of testing , click on View --> Test Results. The results will appear as shown below:


|