Selenium: Ajax Testing

谁说胖子不能爱 提交于 2019-11-30 05:25:11
smriti

I got help on this from one article and with help of @Hannibal

http://agilesoftwaretesting.com/?p=111

JQuery: “jQuery.active”

Prototype: “Ajax.activeRequestCount”

Dojo: “dojo.io.XMLHTTPTransport.inFlight.length”

So if there is Ajax call we can use second option.

selenium.waitForCondition(
        "selenium.browserbot.getCurrentWindow().jQuery.active == 0",
        timeout);

To answer your first point, yes waitForCondition(javascript,timeout) will run the javascript till it returns a true value OR when timeout happens. You should take a look at the api documentation for this as you need to use browserbot to run the script in your application window. Link to API documentation is here

In Selenium 1, one way by which you can handle the Ajax conditions are by creating custom functions which will wait till the condition is met or till a timeout happens. While a normal Selenium.isElementPresent will fail immediately if the element is not present, your custom function will wait for some more time (the time for Ajax to load) before it fails. As an example you can refer the following custom method for isElementPresent. This is written in JAVA, you should be able to use the same logic in the programming language that you use.

public boolean AjaxIsElementPresent(String elementToLookFor, int timeOutValueInSeconds){

int timer=1;
while(timer<=timeOutValue){
 if(selenium.isElementPresent(locator))
   return true;
 else
   Thread.sleep(1000);
     }
return false;

}

This method will return a boolean false if the element is not present even after the specified timeoutValue. If it finds the element within the timeoutvalue then it returns a true.

I have seen some in built functions for AjaxCondition handling in Selenium 2. But I have not used it. You can refer to Selenium 2 code base

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!