Web Functional Testing > Function Reference > Adding AJAX Functions

Adding AJAX Functions

Tags:  


Description : Ajax Functions can be used to handle dynamic nature of the application. With the use of AJAX functions, QEngine can be made to wait until specific HTML element to appear / disappear in webpage and then proceed to do further intended actions recorded in the webscript. The timeout value configure can control the maximum time to wait for the element.

Where the AJAX Functions can be used ?

Following is the scenario which will be automatically QEngine can handle,
  • In a traditional web application, the webpage will be reloaded to send a request to the server.
  • In these scenario QEngine will automatically insert a "setWindow" into the script if the page is reloaded. Hence during playback play engine will wait for the page to load completely and then proceed for further actions recorded in the webscript.

Following is the scenario where AJAX functions will be useful,
  • In a modern web application, the request to the server can be sent through AJAX technology.
  • The request to the web server can be sent without reloading the webpage. If the page is not reloaded QEngine may not record "setWindow" function in the script. Hence play engine will assume all the needed elements are already present in the webpage, and proceed to do the recorded actions in the webscript.
  • In such scenario, the playback over certain elements may fail, if that element is not loaded at the time of playback. The particular element may be added to the webpage based on the response to the AJAX request sent to the server.
  • To handle such scenario you have to use AJAX functions.
  • Using AJAX functions you can make QEngine to wait until the particular element to appear in the webpage, and then proceed to do further functions recorded in the script.

How to enable AJAX element handling ?
  • AJAX element handling can be enabled in the Suite Settings globally for a suite. Under Settings->Replay Settings-> enable the checkbox for "Enable AJAX element handling" and configure the timeout value for maximum time to wait.
  • AJAX element handling can be enabled using the runtime function call enableWaitForElement. The features of this function is described below. Using this function you can enable / disable the AJAX element handling in the runtime of script execution, which will enable you to turn on / off this at the needed times.

Following are the various functions available in the AJAX Functions category,
  1. enableWaitForElement
  2. setWaitTimeForElement
  3. waitForDynamicElement
  4. waitForDynamicElementById
  5. waitForDynamicElementRemoval
  6. waitForDynamicElementRemovalById
  7. waitForElementPropertyChange
  8. waitForDynamicElementPropertyChange
  9. waitForDynamicElementPropertyChangeById
  10. waitForElement
  11. waitForElementRemoval
  12. waitForText
  13. waitForWindowStatus
  14. waitForTitle


enableWaitForElement

Function Description:

Using this function you can enable / disable AJAX element handling in the runtime.  During playback, the test waits until the element is loaded or identified for each of the user actions placed after the enableWaitForElement(). You can use the first parameter of this function to enable/disable the wait time action for specific user actions.

The parameters include:

1st argument - Accepts true or false to enable or disable the wait time action for specific user actions.

2nd argument - The maximum time to wait in seconds.

How to Define:

enableWaitForElement(enable/disable,wait_time_in_secs)

Example:

enableWaitForElement("true",15)

In the above example the AJAX element handling is enabled and the timeout for maximum wait is set as 15 secs.

Return Values:

0 for Success

1 for Failure

Top


setWaitTimeForElement

Function Description:

This function is used in relation to the enableWaitForElement(). Use this function to set the timeout value (increase/decrease the value) to maximum wait time until the specified HTML element is loaded or identified. This function should be inserted just before the user actions for which you need to wait until the HTML elements are loaded/identified.

 How to Define:

setWaitTimeForElement(wait_time_in_secs)

 Example:

enableWaitForElement("true",10)

clickButton("Button1",2)

clickLink("Link1",2)

setWaitTimeForElement(20)

clickButton("Button2",2)

          In the above example, initially the maximum wait time to identify the button element Button1 is 10 seconds. The setWaitTimeForElement() is used to increase the maximum wait time for the next clickButton() which is 20 seconds wherein the test will wait for a maximum of 20 seconds to identify the button element Button2.

 Return Values:

0 for Success

1 for Failure

Top


waitForDynamicElement

 Function Description:

During playback, the test waits until the HTML Element with the given tag name and matching property name and value is identified.

The parameters include:

tagname = Tag name of the HTML element to be identified.

propertyname = Property name of the HTML element to be matched.

propertyvalue = Property value of the HTML element to be matched. The property value can also be given as a dynamic property using regular expressions. i.e., when the properties in your HTML page changes each time the script is replayed.

index = Occurrence of the element in the HTML page.

useRegExp =  Accepts true or false which determines whether to use regular expression or not.
    If false, property value will be matched for equal condition. To know the details of using the regular expressions, refer to the following link.

wait_time in secs = The maximum time to wait in seconds.

 How to Define:

 waitForDynamicElement("tagName", "propertyName", "propertyValue", index, "useRegExp", "wait_time")

 Example:

 waitForDynamicElement("input", "type", "button", 2, "false", 15)

 Return Values:

0 for Success

1 for Failure

Top


waitForDynamicElementById

 Function Description:

During playback, the test waits until the HTML Element with the given element id is identified.

The parameters include:

element_id = Element Id of the HTML element to be identified.

wait_time in secs = The maximum time to wait in seconds.

index = Occurrence of the element in the HTML page.

useRegExp =  Accepts true or false which determines whether to use regular expression or not.
    If false, property value will be matched for equal condition. To know the details of using the regular expressions, refer to the following link.

 How to Define:

 waitForDynamicElementById("element_id", wait_time[, index, "useRegExp"])

 Example:

 waitForDynamicElement("linkid", 15)

 Return Values:

0 for Success

1 for Failure

Top


waitForDynamicElementRemoval

 Function Description:

During playback, the test waits until the specified HTML Element with the given tag name and matching property name and value, is removed from the HTML page.

The parameters include:

tagname = Tag name of the HTML element to be identified.

propertyname = Property name of the HTML element to be matched.

propertyvalue = Property value of the HTML element to be matched. The property value can also be given as a dynamic property using regular expressions. i.e., when the properties in your HTML page changes each time the script is replayed.

index = Occurrence of the element in the HTML page.

useRegExp =  Accepts true or false which determines whether to use regular expression or not.

    If false, property value will be matched for equal condition. To know the details of using the regular expressions, refer to the following link.

wait_time in secs = The number of seconds to wait to identify the specified HTML element.

 How to Define:

 waitForDynamicElementRemoval("tagName", "propertyName", "propertyValue", index, "useRegExp", "wait_time")

 Example:

waitForDynamicElementRemoval("INPUT", "type", "button", 2, "false", 15)

 Return Values:

0 for Success

1 for Failure

Top


waitForDynamicElementRemovalById

 Function Description:

During playback, the test waits until the specified HTML Element with the given element id is removed from the HTML page.

The parameters include:

element_id = Element Id of the HTML element to be identified.

wait_time in secs = The number of seconds to wait to identify the specified HTML element.

index = Occurrence of the element in the HTML page.

useRegExp =  Accepts true or false which determines whether to use regular expression or not.

    If false, property value will be matched for equal condition. To know the details of using the regular expressions, refer to the following link.

 How to Define:

 waitForDynamicElementRemovalById("element_id", wait_time[, index, "useRegExp"])

 Example:

waitForDynamicElementRemovalById("spanid", 15,)

 Return Values:

0 for Success

1 for Failure

Top


waitForElement

 Function Description: 

During playback, the test waits until the specified HTML Element with the given Element ID is identified.

The parameters include:

 Element ID = The HTML element ID which has to be identified.

 wait_time = The maximum time to wait in seconds.

 How to Define:

 waitForElement("Element_ID", "wait_time")

 Example:

 waitForElement("department_1",15)

Return Values:

0 for Success

1 for Failure

Top


waitForElementRemoval

 Function Description: 

 During playback, the test waits until the HTML Element with the given Element ID is removed.

The parameters include:

 Element ID = The HTML element ID which has to be removed.

 wait_time = The maximum time to wait in seconds.

 How to Define:

 waitForElementRemoval("Element_ID", "wait_time")

 Example:

 waitForElementRemoval("department_1",15)

 Return Values:

 0 for Success

1 for Failure

Top


waitForElementPropertyChange

 Function Description: 

During playback, the test waits until the specified HTML Element property changes to the configured value.

The parameters include:

 Object ID = The object id used to retrieve the HTML Element properties from the Map File.

Required Property Name = HTML Property name which is being checked.

Required Property Value = Property Value to be matched to proceed to next action.

 wait_time = The maximum time to wait in seconds.

 How to Define:

 waitForElementPropertyChange("Object_ID", "Req_Property_Name", "Req_Property_Value" , "wait_time")

 Example:

 waitForElementPropertyChange("department_1", "display", "block",15)

Return Values:

0 for Success

1 for Failure

Top


waitForDynamicElementPropertyChange

 Function Description: 

During playback, the test waits until the specified property of the HTML Element with the given tag name and matching property name and value, is changed to the configured value in the HTML page.

The parameters include:

tagname = Tag name of the HTML element to be identified.

propertyname = Property name of the HTML element to be matched.

propertyvalue = Property value of the HTML element to be matched. The property value can also be given as a dynamic property using regular expressions. i.e., when the properties in your HTML page changes each time the script is replayed.

index = Occurrence of the element in the HTML page.

Required Property Name = HTML Property name which is being checked.

Required Property Value = Property Value to be matched to proceed to next action.

wait_time = The maximum time to wait in seconds.

useRegExp =  Accepts true or false which determines whether to use regular expression or not.

    If false, property value will be matched for equal condition. To know the details of using the regular expressions, refer to the following link.

 

 How to Define:

 waitForDynamicElementPropertyChange("tagName", "PropertyName", "PropertyValue", Index, "Req_Property_Name", "Req_Property_Value", wait_time,"useRegExp")

 Example:

 waitForDynamicElementPropertyChange("div", "id", "loading", 1, "display", "block",15)

Return Values:

0 for Success

1 for Failure

Top


waitForDynamicElementPropertyChangeById

 Function Description: 

During playback, the test waits until the specified property of the HTML Element with the given element id, is changed to the configured value in the HTML page.

The parameters include:

element_id = Element Id of the HTML element to be identified.

Required Property Name = HTML Property name which is being checked.

Required Property Value = Property Value to be matched to proceed to next action.

wait_time = The maximum time to wait in seconds.

index = Occurrence of the element in the HTML page.

useRegExp =  Accepts true or false which determines whether to use regular expression or not.

    If false, property value will be matched for equal condition. To know the details of using the regular expressions, refer to the following link.

 

 How to Define:

waitForDynamicElementPropertyChangeById("Element_ID", "Req_Property_Name", "Req_Property_Value", wait_time, Index, "useRegExp")

 Example:

 waitForDynamicElementPropertyChangeById("loading","display", "block",15)

Return Values:

0 for Success

1 for Failure

Top


waitForText

 Function Description: 

During playback, the test waits until the specified search text (with the given prefix and suffix text) appears in the HTML page that is identified in the last user action.

The parameters include:

 Search_String = The text to be searched in the HTML page.

 Prefix_String = The prefix string using which the search string has to be searched for.

 Suffix_String = The suffix string using which the search string has to be searched for.

 How to Define:

 waitForText("Search_String", "Prefix_String", "Suffix_String", "Time_Out")

 Example:

 waitForText("Configure","Device","Parameters")

 Return Values:

          0 for Success

1 for Failure

Top


waitForWindowStatus

 Function Description: 

During playback, the test waits until the specified window status appears in the currently active window.

The parameters include:

Status_Text (Optional. Default Value: Done) =  The Status text which is verified to be shown in the window status bar

wait_time = The maximum time to wait in seconds.

 How to Define:

 waitForWindowStatus("Status_Text", "Time_Out")

 Example:

waitForText("Done","10")

 Return Values:

          0 for Success

1 for Failure

Top


waitForTitle

 Function Description: 

 During playback, the test waits until the specified window with specified title appears.

The parameters include:

 Window_Title = The window title to be searched.

 Window_Index = The occurrence of the window, if there are one or more windows with the specified title exist.

 Time_Out = The maximum time to wait in seconds until the specified window title is identified.

 How to Define:

 waitForTitle("Window_Title", Index, Timeout_Value)

 Example:

 waitForElementRemoval("AdventNet_Payroll", 1, 15)

 Return Values:

0 for Success

1 for Failure


0 Comments  Show recent to old
Post a comment


 RSS of this page

Copyright © 2009, Zoho Corporation. All Rights Reserved.