Friday, September 11, 2009

Selenium - Testing AJAX Web Applications

In AJAX applications, we do not reload the whole page, instead we update part of the page based on the response. To test these applications we cannot use wait_for_page_to_load() or wait_for_frame_to_load() or alert_is().

In these cases, we have to use the wait_for_condition() selenium API.
Key thing to observe here is that the code that you write in the condition is in javascript.
In the following example, I am waiting for the alert for 60000 milliseconds. This alert is poped up after updating the page based on the AJAX response.

my $cond = "try{ if(selenium.getAlert().indexOf('Package successfully deployed') > -1){true;} } catch(ex) {}";
$Common::sel->wait_for_condition($cond, 60000);

No comments: