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.
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.
Selenium IDE records the events generated by the user in a Test Case as Selenium commands (clicks/ typing/ keyboard events..).. Each command is targeting a specific element of the DOM (The HTML tree generated by the rendering of the Web Client) using the default Locator Builder; the default is the wicketpath locator if it has been correctly placed on top of the Locator Buillder list.
Just recording is not enough for a correct playback of the Test Case. To validate the test should be added UI verification checks. Is the element present after i have clicked the button ? is the result value equal to the expected value ?
When recording Selenium IDE assumes that all the elements are already present in the DOM but this is not always the case. Selenium IDE is asynchronous therefore is necessary to add an explicit command to put Selenium waiting until the result of the triggered action is received. For example a click on the button 'next record' result in showing the next record of the foundset. The result of the action is not immediate therefore the expected value cannot be immediately target with Selenium. Selenium should wait until the result of the click action is complete before targeting the values of the next record. Use the commands
waitFor to wait a specific element or a specific value to be loaded on the page.
sendKeys, also add a
bluron the target for the
sendKeys, otherwise the
sendKeysis not applied
selectWindowcommands. 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)
clickevents, but those clicks usually result in an Ajax call to the server. Use the
waitForWicketAjaxcommand to wait the result from the server before executing the next command. Note that
waitForWicketAjaxfails 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 ).
waitForWicketAjaxcannot be used wait for a specific element to be loaded instead.
waitForSelectOptionsto 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/
Many plugins are available for Selenium IDE as Firefox add-on. Listed below some nice to have plugins.
Install the Firefox Extension https://addons.mozilla.org/en-US/firefox/addon/selenium-ide-implicit-wait/?src=search. Allows Selenium IDE to automatically wait until the element is found before executing each command using a locator. To use it add the command setImplicitWaitCondition at the beginning of each Test Case.
Install the Firefox Extension FileLogging: https://addons.mozilla.org/en-US/firefox/addon/file-logging-selenium-ide/?src=search Log the test results of the Selenium IDE into a file. Append text to existing log. does never delete the log file. Use Advanced text editor to view results. Is possible to add a timestamp to any log.
Setup Log extension: Open the Selenium IDE, go to menu Options -> Options -> File Logging.
Select the log file and log level. Default Info
Target the element having the specific ID. Is the most fragile type of locator since in the Web Client the markup Id of elements change frequentely.
Target the element using the servoy wicketpath attribute of the element.
Is a stable locator for forms generated with Servoy at Design time; the wicketpath will not change at any edit of the form. The wicketpath is not stable instead when the form or Servoy element is generated at Runtime using the Solution Model. In this case will change at any execution.
Target the element using the exact position of the element in the DOM. This type of locator is unstable for any change happening in the structore of the page but can be use to target element generated with the Solution Model (Note that the Solution Model should always generate the same result otherwise the DOM of the page will look different and most likely the locator will break)
XPath: contains text/property
Target the element containing the specific text or the specific property. Resist to changes made to the form at Design time and even to the solution model. Fails if there are multiple elements containing the same text or the same property or if the text/property is changed.
//div[text()='logout']/../.. find the parent of the parent of the div element having the text equal to 'logout'
//img[contains(@src, "pv_btn_logout.png")] find the element containing the value "pv_btn_logout.png" in the src attribute
Servoy has in it's road map the possibility to provide a Selenium locator based on formName/elementName values which would be more resistant to failure then the mentioned selectors.