Skip to end of metadata
Go to start of metadata
Selenium is a free, open source, automated testing suite for web applications across different browsers and platforms.

The Selenium suite consists of a few core components. Several add-ons are also available. The primary components of Selenium are:

  1. Selenium IDE - for recording browser actions driving the web application through a specific scenario
  2. Selenium RC (remote control) - an api for writing tests in various programming languages. Also a server for running tests created with Selenium IDE. Controls the browser with JavaScript by acting as a proxy.
  3. Web Driver - implements a more sophisticated and stable approach to automating browser actions. Controls the browser by communicating directly with it rather than relying on JavaScript.
  4. Selenium Grid - a tool used to run parallel tests across multiple machines and browsers.

Recently, Selenium 2 was released which combines Selenium RC and Web Driver.

SeleniumIDE

Like most record and playback testing tools, SeleniumIDE allows the user to quickly record a browser session and play it back. While many of the Smoke Tests run in CI were initially created using SeleniumIDE they have been heavily modified to be less brittle as well as to be made up of reusable components. SeleniumIDE is useful for recording a test initially. It can then be saved as a unit test and then refined to be more stable and reliable. For writing Smoke Tests from scratch see Deprecated Creating Rice Smoke Tests.

Guidelines to Design/Record a Selenese IDE Test

Documentation guide provided by SeleniumHQ is the best for a beginner/professional to get going with Selenium IDE/Selenium RC/Selenium WebDriver backed Selenese Test.

Selensese is commonly used as a reference for a set of Selenium commands used to run a test.

It’s pretty simple to create a Selenese Test:

  1. Install a Selenium IDE to your Firefox browser (Download here).
  2. Record the script as desired.
  3. Export the recorded script to desired format and save it.
  4. Run an exported JUnit test

Designing (Recording) a Selenium Test is as simple as it looks, but it also involves a bit of tweaking in order to get the best out of it.

Since we already have integrated Selenium Automated testing to the Rice Continuous Integration environment, let's concentrate on how to design/create selenium test and add it to an existing test package.

To have the basic Idea about the usage of SeleniumIDE one must go through the Documentation Guide provided on SeleniumHQ. Try a few tutorials and become well aware about different Selenese commands (and their versions if any) offered by Selenium.

Running a selenium unit test

After you have created a test and successfully played it back using the Selenium IDE, then next step is to save the recorded test as a unit test.

  • From the selenium Firefox add on menu (File > Export Test Case As ...), export the record script as a JUnit 3 or 4 remote control test
  • Attempt to run the test without starting the selenium server, if it fails start the selenium server on the console using
  • OR Download the selenium server
  • Start the selenium server on the console using
  • Add the following system property to the default JUnit test configuration. This can also be done per test in an IDE specific way. The URL points to the rice instance being tested.
  • Add the following system property to prevent Firefox from closing after the test is run.
  • Start the rice instance if not running yet.
  • Initiate the test

IDE Overview

Referring to above mentioned documentations would almost get you well going through recording a simple test case. Below are some simple steps to record your first Test.

  1. Bring IDE to Recording mode by activating the Red button. Once its active IDE starts recording your events on the browser for the window that holds content for Base URL, mentioned at the top bar of IDE.
  2. Get accustomed to all the available commands and know each specifically referring to the documentation available. Command List box on IDE displays list of all the commands supported by IDE. These commands either reflect different browser events or different desirable actions like verifying, asserting element etc. For example:
    1. clickAndWait(locator)
    2. Generated from click(locator)
    3. Arguments : locator - an element locator
    4. Clicks on a link, button, checkbox or radio button. If the click action causes a new page to load (like a link usually does), call waitForPageToLoad.
  3. Target field is the field which takes input to help locate different elements which are under test. IDE supports different locating techniques. CSS, DOM, Xpath are some of the supported methods one can employ to locate element. For example a link with value Documentation can be expressed in target field as:
  4. Value field of IDE takes input for the Test Data that is to be used.
  5. All the selenium Tests are recorded in HTML format by default. You can have HTML view of the Test in the Source Tab.
  6. Another feature IDE comes with is its flexibility to allow the user to export the recorded Test to different formats compatible to various existing popular programming languages and Test framework like JUnit and TestNG. You can directly export or save the Test to desired format. If your project employs JUnit Test framework this will well be a handy feature as the user would want to record Test with IDE, export or save the same to JUnit Test and integrate within your test package as JUnit test.
  7. Lastly your IDE knows to play the same Test. It allows you to load the previously recorded test and play the same. This may help you to quickly verify your Test behavior.
  8. Overriding default configuration would be required in some situations. For example user may want to set desired timeout value for command to timeout throughout Test. One can set default values for default package attribute from the Menu-> Option for JUnit Test format. This and many other such options can be configured as desired.

Things to taken care of while designing/Recording the script.

  1. Test should be such that it should free from the static identifiers for the html elements as much as possible.
  2. There are some components which are automatically generated and have auto generated Ids. Such elements should be located with the help of different feasible locating techniques like xPath, css, html as mentioned in bullet 3 of IDE overview section.
  3. If you are not sure about the later modifications to the page under Test you should avoid using static Identifiers like mentioning ids, name, CSS class Name. This could well prevent breaking of your test sequence.
    for ex. If the input field is
  4. Sometimes it's good to tweak the Test rather than completely accepting the one exported or saved from IDE. Developers more competent with JUnit coding could put in their desired piece of code wherever feasible along with the exported code. You might want to tweak the test for some conditional situations like executions of particular piece of Test Code or Assertions/verification of elements etc.
  5. More and more complex Test you work on, higher the Expertise curve goes.

Configuring Selenium with Maven Applications

This section more or less deal with how to automate and bind your Test's execution with the integration phase of life cycle.
Selenium Maven plug-in along with Maven Surefire Plug-in and web-container plug-ins like tomcat/jetty enables you to run your Test Plans in continuous integrated environment.

Below are some of the plug-in configurations used which may be added to pom.xml to enable binding of Selenium Tests to integration phase.

  1. Selenium Maven Plugin allows binding of Selenium Server’s start and stop goal with integration phase. You may want to add some configurations too along with this.
  2. Tomcat Maven Plugin can be configured to bind the start and stop of container with pre-integration as well as post-integration-test phase. Similar things can be achieved using Jetty Maven Plugin with respective configuration changes.
  3. Maven Surefire Plugin to make sure the execution of Unit Tests during the integration-test phase of lifecycle
    1. Along with this plugin we need to add selenium-java/JUnit dependency
      Setting up all this with your application and running maven goals would ensure execution of Tests during Integration-test phase of application life-cycle.