User-extensions & Plugins – Introduction

Selenium IDE (Integrated Development Environment) can be enriched with user-extensions, such as: logical statements and data driven testing. This also allows us to create our own actions, assertions and even your own locator strategies. Those user-extensions are written in JavaScript and will be loaded on the IDE’s start up.

As of Selenium IDE version 1.0.4 Selenium can also be extended through it’s own plugin system. They will mainly add new functionality to Selenium IDE, such as: extra buttons in the toolbar.

This is an introduction to the other posts related to this topic. Related posts are listed below.

Using the UI-map user-extension

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.

  1. Open Selenium IDE by selecting Selenium IDE from the Tools menu in Firefox.
  2. Open the Options window by clicking Options → Options…
  3. Set the location of the UI-map, using the Browse… button.
  4. Click on OK to confirm the modifications and reopen Selenium IDE to make changes effect.
  5. 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 JSON (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.

Using the flow control user-extension

Problem

It is by default not possible to add flow-control or conditional statements to our Selenium IDE tests. They came up with an excellent flow-control user-extension for Selenium IDE, that makes it possible to add conditional statements to the tests. This recipe shows us how to integrate flow-control in our tests.

Prerequisites

We have to make the flow-control user-extention available in Selenium IDE by loading the file into the IDE. The flow-control user-extension can be downloaded from the following location: http://wiki.openqa.org/display/SEL/flowControl

Solution

This user-extension provides a couple of logical functions, like: label, goto, gotoIf and while loops. We can define points in our tests to navigate to. We can place the label command in front of a selection of code.

Command Target Value
label name_of_label  

There are two ways to navigate to the labeled selection of code. We can make a conditional statement or we can just jump to that selection. The first table shows the goto command and the second table shows a conditional statement.

Command Target Value
gotolabel name_of_label  

 

Command Target Value
gotoIf Conditional statement name_of_label

 

We have also the ability to make a conditional loop, a while-loop.

Command Target Value
while Conditional statement  
//Script within the while-loop
endWhile    

Using the datadriven user-extension

Problem

There are several reasons for implementing datadriven testing. Imagine we have to test a telecom application, where we need unique phone numbers for every test. Or we have to test an insurance application, where we need unique policy numbers for every test. Or we have to test a banking application, where we need unique account numbers for every test cycle. For those reasons it could be extremely useful to populate the test with testdata from an external file. This can be done with the datadriven user-extension.

Prerequisites

We have to make the flow-control, include and datadriven user-extention available in Selenium IDE by loading the file into the IDE. The user-extensions can be downloaded from the following location: http://wiki.openqa.org/display/SEL/datadriven

Solution

The first thing we need to do is creating an XML file with testdata, which can be used in the tests. The testdata in the XML file is written as a key/value structure and will look like this: 


<testdata>
    <test key1="value1" key2="value2"/>
</testdata>
1
2
3
<testdata>
    <test key1="value1" key2="value2"/>
</testdata>

Once we have the XML with testdata, we can build or modify our tests. We have to load the XML file and walk through the testdata rows. For each row we have to execute the test. The script will look like this:

Command Target Value
loadTestData    
While !testdata.EOF()  
NextTestData    
//Script within the while-loop
endWhile    

What has been done

The user-extensions are loaded into the core of Selenium. The script will load an XML file from a preferred location and execute the script for every single line of testdata in the XML. We can call the keys from the test script itself, like this ${key1} and ${key2}

Using the file logging plugin

Problem

The file logging plugin allows users to store the logging information in a separate file. The logging level can be selected and the options menu will be extended.

Prerequisites

The file logging plugin can be downloaded from the Firefox add-on manager, using the following url: https://addons.mozilla.org/.

Solution

There are some extra buttons visible in the log panel after installing the plugin. We can select the level of logging and choose if we want a timestamp.

Using the highlight elements plugin

Problem

Sometimes it’s hard to see what is going on in the browser window. With the highlight elements plugin we can make things visible.

Prerequisites

The highlight elements plugin can be downloaded from the Firefox add-on manager, using the following url: https://addons.mozilla.org/.

Solution

There is an extra button visible in the toolbar of Selenium IDE after installing the plugin. We can see the button in the following screenshot:

We can highlight every element which we use in tests by enabling this button.

Using the power debugger plugin

Problem

This plugin is very powerful in debugging tests. It will pause the execution rather then fail the test. We can simple hit the resume button, once we resolve the issue.

Prerequisites

The power debugger plugin can be downloaded from the Firefox add-on manager, using the following url: https://addons.mozilla.org/.

Solution

There is an extra button visible in the toolbar of Selenium IDE after installing the plugin. We can see the button in the following screenshot:

We can hit the red pause button any time and the test will pause on a failure. We can continue the test by pressing the resume button.

Using the stored variables viewer plugin

Problem

Selenium IDE gives the ability to store values in variables while running the test. The store variables viewer plugin makes it possible to display the values in the logging panel.

Prerequisites

The stored variables plugin can be downloaded from the Firefox add-on manager, using the following url: https://addons.mozilla.org/.

Solution

There will be an extra tab in the logging panel at the bottom of Selenium IDE. The extra tab is displayed in the following screenshot:

Using the test suite batch converter plugin

Problem

Selenium IDE provides a quick start up in test automation. Imagine we decide to build a maintainable framework in a preferred language, with the test suite batch converter we can easily convert our existing tests which are made with Selenium IDE.

Prerequisites

The test suite batch converter plugin can be downloaded from the Firefox add-on manager, using the following url: https://addons.mozilla.org/.

Solution

There are two extra menu options visible in the File menu. We can convert a single testscript or a whole test suite, those options are displayed in the following screenshot:

First we need to select the destination folder and then we can select the source files, in both cases.

Using the favorites plugin

Problem

We may have generated a lot of test suites for a single or multiple projects. It could be helpful to have a quick access to frequently used test suites. In this case the favorites plugin can be of great help.

Prerequisites

The favorites plugin can be downloaded from the Firefox add-on manager, using the following url: https://addons.mozilla.org/.

Solution

This plugin creates one extra button in the toolbar of Selenium IDE. We can compare this function to the favorites function in the browser. We can see the extra button in the screenshot below: