This chapter provides information on how to set up Selenium for visual testing the Servoy solutions in Web Client. Selenium IDE record and playback the user clicks on the UI.
In This Chapter
Create a folder wicketPathLocatorBuilder
in the local drive with the file user-extension.js.wicketPathLocatorBuilder
inside. To add the wicketpath locator into the Selenium IDE Locator Builder options paste the following snippet into this file.
LocatorBuilders.add('wicketpath', function(e) { var path = ''; var current = e; while (current != null) { if (current.parentNode != null) { path = this.relativeXPathFromParent(current) + path; if (1 == current.parentNode.nodeType && // ELEMENT_NODE current.parentNode.getAttribute("wicketpath")) { return this.preciseXPath("//" + this.xpathHtmlElement(current.parentNode.nodeName.toLowerCase()) + "[@wicketpath=" + this.attributeValue(current.parentNode.getAttribute('wicketpath')) + "]" + path, e); } } else { return null; } current = current.parentNode; } return null; });
Add the following code inside the user-extension.js.wicketPathLocatorBuilder
to include the command waitForWicketAjax as a Selenium IDE extension. The waitForWicketAjax command checks if there is a pending wicket Ajax request from the current Browser window and will wait until the wicket Ajax request is completed.
/* * Some usefull links: * http://www.packtpub.com/article/user-extensions-add-ons-selenium-testing-tools * http://selenium.polteq.com/en/ */ Selenium.prototype.isWicketAjaxReady = function(locator, text) { //TODO extend with checking JQuery.ajax as well. See http://hedleyproctor.com/2012/07/effective-selenium-testing/ if (!selenium.browserbot.getCurrentWindow().wicketAjaxBusy) { var doc = selenium.browserbot.getCurrentWindow().document; var scriptTag = doc.createElement("script"); scriptTag.type = "text/javascript" var script = 'wicketAjaxBusy = function() {for (var c in Wicket.channelManager.channels) {if (Wicket.channelManager.channels[c].busy) { Wicket.Log.info("Channel " + c + " is busy");return true;}}Wicket.Log.info("No channels are busy");return false;}'; try { scriptTag.appendChild(document.createTextNode(script)); } catch (e) { scriptTag.text = script; } doc.body.appendChild(scriptTag); } return !selenium.browserbot.getCurrentWindow().wicketAjaxBusy() };
wicketPathLocatorBuilder
.servoy.webclient.debug.wicketpath
to true.sendKeys
, also add a fireEvent
with value blur
on the target for the sendKeys
, otherwise the sendKeys
is not appliedselectWindow
commands. Most of these can be removed. They are only needed when the test needs to switch to another tab or to a different dialog (or back to the main form from a dialog)click
events, but those clicks usually result in an Ajax call to the server. Use the waitForWicketAjax
command to wait the result from the server before executing the next command. Note that waitForWicketAjax
fails if there are multiple Ajax call to the server or if the call results in closing the JSWindow ( The command would not find the current window and generate an error ).waitForWicketAjax
cannot be used wait for a specific element to be loaded instead.waitForSelectOptions
to wait for the value to be loaded on the list.Tip: for more detailed documentation and video tutorials user this link: http://jroller.com/selenium/