Friday, December 16, 2005

Selenium 'AndWait' timeouts

We are using Selenium at work for our UATs. Our continuous integration server is running our UATs after each commit to verify the app still works as expected.

A reoccuring problem has been button on pages that only sometimes cause postbacks. The issue is that when a postback is caused you have to use the command 'clickAndWait' when no postback occured you just use 'click'. So.. if you use 'clickAndWait' and there is no postback Selenium sits there waiting for a page refresh that will never come. In effect the test runner hangs.

Our build process has a timeout set, so eventually the nant task running the UAT times out.. This has to be set pretty long as currently the UATs are taking 20+ mins. As a result we are not getting fast enough feedback.

My Solution...

I hacked away at the selenium code a bit to introduce a timeout for all 'AndWait' commands.

Here is the code changes:

In selenium-executionloop.js I replaced

/**
* Busy wait for waitForCondition() to become true, and then continue
* command execution.
*/
this.pollUntilConditionIsTrue = function () {
if (this.waitForCondition()) {
this.waitForCondition = null;
this.continueCommandExecutionWithDelay();
} else {
window.setTimeout("testLoop.pollUntilConditionIsTrue()", 10);

}
};

with

/**
* Busy wait for waitForCondition() to become true, and then continue
* command execution.
*/
this.pollUntilConditionIsTrue = function () {
LOG.info("Polling:");
this.pollUntilConditionIsTrueWithTimeout(2000);
};

this.pollUntilConditionIsTrueWithTimeout = function (timeoutChances) {
if (this.waitForCondition()) {
this.waitForCondition = null;
this.continueCommandExecutionWithDelay();
} else {
if (timeoutChances <= 0)
{
var message = "'AndWait' command timed out.";
LOG.error(message);
this.commandError(message);
this.testComplete();
}
else window.setTimeout("testLoop.pollUntilConditionIsTrueWithTimeout("+ (timeoutChances -1) +")", 10);
}
};



It is not tested on anything other than IE, and no unit tests... but it seems to work for us.

No comments:

GitHub Projects