We have an application that uses quite a bit of Ajax and this caused problems in recording tests using the Selenium IDE. Each test step was recorded successfully, but because there are web services calls firing in the background on the client (the Ajax stuff), a playback would fail immediately. The fix in general is to use Javascript to check for a completion flag of some sort, but the IDE did not have a provision for inserting code automatically or to delay each test step. This limited the ability to rerun a recorded test when mistakes are made during the recording process. I’ve been working (with other engineers) on modifying the Selenium IDE code to allow the automatic insertion of Ajax rendering complete Javascript code. However, the latest version of the IDE in SVN has a slow-down control now and that seems to work like a champ on our app. It allows you to slow the playback down to something that approximates human speed and our app now seems to be happy as we record and then play back. Thanks to the Selenium IDE developer Shinya Kasatani for this great addition.
I still plan to add a switch to allow specified Javascript to be executed automatically when the Selense plays back – to allow a check for a "render complete" flag that we have in our Javascript.
192.168.18.125
3.145.95.233
Recently a part of our site incorporated more AJAX calls like autocomplete feature. The record and playback fail each time. There was a nice tutorial online which demonstrated how to overcome this.
Here is a sample of how we over came this, using xpath, typekeys, mouseover and a for loop that sleeps for a second.
selenium.open(“/unlock/”);
selenium.waitForPageToLoad(“30000”);
selenium.typeKeys(“tags”, searchTerm); // search term is parameterised replace this with something you want to search for like Iphone 4
for (int second = 0; second = 60)
{
result = false;
System.out.println(“limit reached”);
}
//phone is parametrised too so again change this to the expected results.
try { if (selenium.isTextPresent(phone)) break; } catch (Exception e) {}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
if(result == false)
{
result = false;
}
else
{
selenium.mouseOver(“xpath=/x:html/x:body/x:ul/x:li/x:a”);
selenium.click(“xpath=/x:html/x:body/x:ul/x:li/x:a”);
selenium.waitForPageToLoad(“30000”);
result = selenium.isTextPresent(“exact:Learn everything you need to know about how to unlock your ” +phone+”. In the table below we list all available options to help you compare between different unlocking solutions, including how to do it, long it takes and how much it costs.The giffgaff unlockapedia also includes reviews and ratings by our members for the different unlocking options. Have you unlocked this handset before? Make sure you add a comment and rating.\n\nThis is an impartial and independent service provided by giffgaff, the mobile network run by you.”);
}