Extending Selenium from the client driver

Selenium is a web page testing tool that we use a lot at my work. It can be extended by supplying it with a user-extensions.js file.

We’re extending our test application to include support for Selenium Grid. In this setup we can’t supply that user-extensions.js file directly, it has to be injected via the client driver. However, this happens too late; Selenium doesn’t notice our custom locator functions any more. This is a known issue, also noted by Ross Patterson. I’ve found a way to work around this limitation. Add the following to your user-extensions.js file such that it’s executed after your additions have loaded:

objectExtend(selenium.browserbot, PageBot.prototype);
selenium.browserbot._registerAllLocatorFunctions();

It seems to work just fine without any unwanted side-effects. If you tried this, please leave a comment to let us know how it worked out for you!

dr. Sybren A. Stüvel
dr. Sybren A. Stüvel
Open Source software developer, photographer, drummer, and electronics tinkerer

Related