Wednesday, March 23, 2011

Selenium IDE and Wicket

When testing a Wicket application, Selenium IDE often records element id's that are dynamic and change every time the application is opened. To resolve this problem, I followed this tip from https://issues.apache.org/jira/browse/WICKET-1830 by Frank van Lankvelt.

Create a folder "wicketPathLocatorBuilder" with the file "user-extension.js.wicketPathLocatorBuilder". Paste the following snippet in this file.
 
LocatorBuilders.add('wicketpath', function(e) {
this.log.debug("wicketpath: e=" + e);
if (e.attributes && e.hasAttribute("wicketpath")) {
this.log.info("found attribute " + e.getAttribute("wicketpath"));
return "//" + this.xpathHtmlElement(e.nodeName.toLowerCase()) +
"[@wicketpath=" + this.attributeValue(e.getAttribute("wicketpath")) + "]";
}
return null;
});

LocatorBuilders.order.unshift(LocatorBuilders.order.pop());

Open Selenium IDE, go to menu Options -> Options. In the Selenium Core extensions input field, paste the path to the earlier created folder "wicketPathLocatorBuilder". Restart firefox.

Now when you record tests, the wicketpath attribute is used to generate an element locator.