Child pages
  • Setting Up Selenium for Web Client UI Testing

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Setup Log extension: Open the Selenium IDE, go to menu  Options -> Options -> File Logging.
Select the log file and log level. Default Info

Selenium Best Practice

 

 

Use the following best practices to make the automated test easily maintainable.

Select the proper locator

  • The selection of a stable locator is the most important step to have a maintainable test script. Element's locator can change frequentely in the DOM resulting in an unmaintenaible test. When recording the Test Case the developer should choose the locator that most likely will not change when modifying the form.

...

  • Is a good practice to store the locator of often used element into Selenium variables. If the locator is then affected by any change would be easier to set the new locator in the test script. In such a way the Test Case becomes also more readable.

ID locator 

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.

Wicketpath 

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.

Example: //div[@wicketpath='servoy__page_servoy__dataform_forms_0_webform_servoywebform_View_sv____BC22D853__A837__4D0B__8937__8ED2D086451E_sv____F48C87B8__E69A__46D1__93C2__33F59B96538E__wrapper']/input

...

XPath: position

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)

Example: //div[13]/div/div/div[3]/div

...

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.

Examples

//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

FormName-ElementName

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. 

 

Keep the test maintainable

  • Store frequently used values in variables.
  • Avoid duplicates in the test scripts. Modulate the Test Cases and Test Suites and reuse same Test Cases in multiple Test Suites. Create new extentions or Rollup for frequently used sequence of commands.
  • Keep the Test Case and the Test Suites small. Each Test Suite should test a single Use Case. Separate the Test Suite in multiple Test Cases, each Test Case is a single Unit of test.
    Example: create new customer. Create a Test Suite and the following Test Cases: Login, Open form customers, create customer, logout.
  • Refactor the test when refactoring the code or changing the form.
  • Document the tests. Use proper naming conventions and save the Test Suite and Test cases in a organized folder structure.
  • Use setUp and tearDown functions to make the test repeatable. Avoid using other Test Cases as setUp or tearDown, if the test case of the setUp fails then the setup will not be correct. Use Servoy functions as setUp or tearDown. Is possible to inject wicket callback to the Servoy functions into the client libraries. Once the wicket callback is correctly injected execute from Selenium with the command runScript