What is it?
This extension adds assertions similar to waitFor* called reloadAndWaitFor*. If an assertions is called with that name, the current page is reloaded every 20 seconds. Additionally the whole assertion times out after 70 seconds.
This is a useful extension in the context of insertions done by the tests. In big environments a change may only be visible after a few seconds and the page has to be reloaded again for the change to be visible.
The extension is used to test the local.ch market, a Swiss classifieds platform.
Licence
Apache License, V2. This code was developed by Patrice Neff for local.ch.
How to add it to selenium:
1. Add the following code into the 'user-extensions.js' file:
/* * Extend Selenium core with reloadAndWaitFor* asserts (reload as often as necessary for up to 60 seconds) * Copyright 2007 - local.ch ag * Version 0.2 * 0.1: Initial release * 0.2: Remove redundancies * 0.3: Fix reloading */ CommandHandlerFactory.prototype._oldRegisterWaitForCommandsForPredicate = CommandHandlerFactory.prototype._registerWaitForCommandsForPredicate; CommandHandlerFactory.prototype._registerWaitForCommandsForPredicate = function(commandTarget, baseName, predicateBlock) { this._oldRegisterWaitForCommandsForPredicate(commandTarget, baseName, predicateBlock); // Register a reloadAndWaitForBlah and reloadAndWaitForNotBlah based on the specified accessor. var cmdBlock = this._reloadAndWaitForActionForPredicate(predicateBlock); this.registerAction("reloadAndWaitFor" + baseName, cmdBlock, false, true); var invertedCmdBlock = this._invertPredicate(cmdBlock); var invertedNotCmdBlock = this._reloadAndWaitForActionForPredicate(invertedCmdBlock); this.registerAction("reloadAndWaitFor" + this._invertPredicateName(baseName), invertedNotCmdBlock, false, true); this.registerAction("reloadAndWaitForNot" + baseName, invertedNotCmdBlock, false, true); } CommandHandlerFactory.prototype._reloadAndWaitForActionForPredicate = function(predicateBlock) { // Convert an isBlahBlah(target, value) function into a reloadAndWaitForBlahBlah(target, value) function. return function(target, value) { var retval = Selenium.decorateFunctionWithTimeout(function() { var status = false; if (this.lastReload == undefined) this.lastReload = new Date().getTime(); try { status = predicateBlock(target, value).isTrue; } catch (e) { // Treat exceptions as meaning the condition is not yet met. } if (status == false) { if (new Date().getTime() > this.lastReload+1000) { // Reload every 20 seconds selenium.doRefresh(); this.lastReload = new Date().getTime(); } } return status; }, 70000); return retval; }; };
Example:
Sample Selenium code:
| open | /test-page | |
| reloadAndWaitForTextPresent | New username |

Comments (2)
Jun 26, 2007
walley75 says:
I followed the directions and added the program text into the user-extensions.js...I followed the directions and added the program text into the user-extensions.js file and restarted Selenium IDE. I now get the error "Failed to load user-extensions.js!" and "error=ReferenceError: CommandHandlerFactory is not defined"
What is missing? I am new to java script. I can edit as needed.
Oct 22, 2009
Sean says:
CommandHandlerFactory is not defined can be resolved by adding the following li...CommandHandlerFactory is not defined
can be resolved by adding the following line:
var CommandHandlerFactory = classCreate();