Selenium: Ajax Testing

后端 未结 2 1266
南方客
南方客 2020-12-29 15:42

Please brief me about the Ajax testing with selenium RC. As in Ajax element not reflect on the view-source, but using firebug we can see the changes in HTML source code.

相关标签:
2条回答
  • 2020-12-29 16:14

    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

    0 讨论(0)
  • 2020-12-29 16:16

    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);
    
    0 讨论(0)
提交回复
热议问题