Problem
In this recipe we will see how to use the UI-map and we will discuss some features of creating an UI-map. In the end we are able to use the UI-map in both Selenium IDE and Selenium WebDriver. This will save a lot of time and the use of the UI-map makes the tests better maintainable. We can even put this file under version control in case you like to keep track of the changes.
Prerequisites
We have to create the UI-map before we can use it in our tests. In the locator section is explained how to access the elements and how to create an UI-map.
Solution
We have to make the locators available in Selenium IDE by loading the file into the IDE.
- Open Selenium IDE by selecting Selenium IDE from the Tools menu in Firefox.
- Open the Options window by clicking Options → Options…
- Set the location of the UI-map, using the Browse… button.
- Click on OK to confirm the modifications and reopen Selenium IDE to make changes effect.
- The target textfield has been changed to a selectbox with the locators from the UI-map.
What has been done
We made the locators known in Selenium IDE following the previous steps. We are now able to select locators by their meaningful name.
There is more
The mapping is defined using JSONJavaScript Object Notation (JavaScript Object Notation) and can be shared between Selenium IDE and Selenium WebDriver.
Use UI-map with Selenium Server
We can use the UI-map once we run the Selense testscript with the Selenium Server. We have to use the following batch command:
java -jar "<path/to/selenium_server>.jar" -htmlSuite "*firefox" "<base url>" "<path/to/testsuite>.html" "<path/to/results>.html" -userExtensions "<path/to/user-extensions.js>"
Tip 1: We need to use a testsuite file, because the script will not work with a testcase file.
Tip 2: The name of the UI-map file should be user-extensions.js. We can put all the user-extensions into onefile.