Question

I have a site which has alot of ajax, and requires automation. However, I cant record ajax parts of the site properly. I tried the waitfor keyword and failed. I also went through the following website http://www.ibm.com/developerworks/opensource/library/os-webautoselenium/index.html, but could not make out a on how to apply the code to MyEclipse.

Does anyone have some good tutorials on how to test ajax applications ?

Thanks in advance

Was it helpful?

Solution

Ajax is a bit of mess and working with Selenium. There is no easy answer to your question but I have a few tips..

You will need to use a lot of these loops to wait for actions/updates etc:

        for (int second = 0;; second++) {
        if (second >= 60) log.error("Timeout (60 seconds) while submitting request");
        try { if (selenium.isElementPresent("elementID")) break; } catch (Exception e) {}
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

Also Ajax enabled pages have many times events trigged on characters being entered into TextBox for example and then selenium.type("elementID", "12345"); wont to it for you. The typeKeys("elementID", "12345"); will fire events.

With FireFox and firebug, use the javascript debugger to analyse what is happening in the background. I do prefer to use Chromes Inspect debugger. Talk to your developers to find out whats triggered for certain elements etc.

Secondly you can have a look on the newest version of Selenium 2.0. The web driver is supposed to handle Ajax requests much better but I have not yet got time to work with.

So in short, you will have to write a lot of the code by your self and modify recorded parts.. If does not work out there some of the commercial ones that handle some type of Ajax better.

OTHER TIPS

If you're using XPath, then it won't work. Try CSS locators. I'm using Sizzle.js locators in RC and it works well in all ajax elements.

For IDE, you can go for available plugins or write your own and plug it using user-extensions.js option.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top