There exists a problem with the race conditions testing websites full of AJAX, here is a solution using Selenium.
I’ve been looking for the perfect solution of the pair “AJAX + Web testing tool” and i’ve reached the conclusion that, so far, there isn’t a perfect solution.
Selenium is ready (at least almost ready) to test AJAX websites and apparently, Selenium is the most used tool and has the biggest support community, and therefore, is the better one to deal with AJAX applications.
As probably many of you know, Selenium has methods like “waitForXXX” that can assert most of the AJAX request and if your website renders the code statically or dynamically just some pieces of the site, you won’t have any problems.
Using the method “waitForCondition”. I know is not the best solution because you will need to use it in many places of your code, so the best idea will be a more general approach that is explained in the next point.
$js = "var target = selenium.browserbot.getCurrentWindow().document.getElementById('idOfTheElement').onclick;"; $js .= "(typeof target = 'function') || (typeof target == 'object')"; $selenium->waitForCondition($js, 5000);
The best solution?
I suggest this idea to whoever really wants to solve this problem:
Keep a container of all the XMLHttpRequest that your site has and improve Selenium with the ability of wait for AJAX request finished asking the state of all these objects. If the state of all this objects is 4 (completed) you will be totally sure that you can perform the next action, you’ll be sure the request that can cause the race condition is fully loaded.
Any voluntary? i can help!