Illustrating AJAX Functions

 

The sample script named test-ajax-page is an illustration of how to use some of the AJAX functions which are as follows:

These functions are added in non-recording mode and thus does not use the map file during playback. The detailed description of this sample script is given below:

 

In this script, the employee.html page is recorded which is bundled with QEngine in <QEngine_Home>/examples/payrollsystem/dynamic directory. After navigating to this page, the recording is stopped to insert the waitForElement(). This function is used to wait until the username HTML element is identified. This function will wait for a maximum of 10 seconds to identify the element. If the element is identified before 10 seconds then the function returns true and the test proceeds with the next line in the script. Else, if the element was not identified even at the 10 second then the function returns false and proceeds with the next line in the script.

 

Following are the lines in the sample script which does the above during playback:

 

useLocalMapFile()

launchApplication("about:blank")setWindow( "NONE",2)changeURL("http://$QE_SERVER:$QE_PORT/examples/payrollsystem/dynamic/employee.html",1)

setFastMode() # Dynamicaly change to fast mode playsetWindow( "Employee Details Entry Form",5)clickButton("emp",1)

waitForElement("username",10) # play wait for element username to be displayed until 10 sec timeout

...

...

 

Once the element is identified, the following fields are filled in and the Add button is clicked to add the employee details.

 

Following are the lines in the sample script which does the above during playback:

 

...

...

...

setText("username","John",13)setText("age","20/07/1978",8)

clickButton("gender",1)

setText("dept","QEngine",4)

selectItem("communication","Phone",1)

setText("telephone","888-784-2220",12)

setText("mail","qengine-support@adventnet.com",10)

clickButton("add",1)

 

Once the employee details are added, the waitForText() is used to check whether the text Added is displayed in the HTML page. This function wait for a maximum of 5 seconds to get the specified text and returns true if the text appears and false if the text does not appear within 5 seconds. The executeTest() is a testcase to check for the specified text. Clicking the emp_1 button will create a list element using AJAX call. To handle this, the waitForElement() is used to wait until the list element "salary" is loaded and identified. Once the list element is created, one of the employee is selected from the list element to view the emplyee salary details. Here, the waitForText() is used to dynamically check for the text "Employee Number" that appears using the AJAX call. The last line is a test case which checks for the specified text.

 

Following are the lines in the sample script which does the above during playback:

 

waitForText("Added","EMPTY","EMPTY",5) # play wait for text Added to appear in the HTML window

executeTest("test-info-message-1")

setWindow( "Employee Details Entry Form",22)

clickButton("emp_1",1)

waitForElement("salary",10)

clickButton("salary",9)

waitForText("Employee Number","EMPTY","EMPTY",5)

executeTest("test-salary-001")

 

You can playback this script from the default suite AdventNetPayrollSystem to view the output.



Copyright © 1999, AdventNet Inc. All Rights Reserved.