AJAX + Selenium: solution for race conditions

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.

But what happens if your website is full of AJAX and all the source code is generated dynamically? I mean, for instance, the JavaScript events.

I’m not an expert in HTML or JavaScript but i’m talking about the onclick, onmouseover, onload, etc. attributes of the HTML tags. Usually, these attributes have JavaScript events that perform a change in the site.

BUT, if these JavaScript events are loaded dynamically and asynchronously using an AJAX request, is Selenium able to perform proper assertions? NO.

Continue reading

Advertisements