Skip to end of metadata
Go to start of metadata

This page is intended for sharing ideas and resources related to using Selenium and Selenium IDE

Unknown macro: {composition-setup}
Unknown macro: {deck}
Unknown macro: {card}

Selenium: For Regression testing, Acceptance testing and setting up Test Environments with Sites, Users and Seed Data.

Selenium IDE is an integrated development environment for Selenium tests. It is implemented as a Firefox extension, and allows you to record, edit, and debug tests. You can choose to use its recording capability, or you may edit your scripts by hand.

Setting up Selenium IDE

AdBlock Plus is no longer needed to run the Selenium scripts referenced here.

  1. You can download the extension here. You will then be able to run any of the scripts attached to this page right in your browser.
  2. Some of the scripts (including the environment setup scripts) require that you upload certain files. These files can be found in the TestingData.zip file. If you are using any of these scripts and you are not on the network you will need to download this file and unzip. Additionally, anywhere in the scripts where a file needs to be uploaded you will need to change the default path to that of downloaded TestingData file. There are comments in the scripts where this action will be necessary.
  3. Finally, you will need to add this file user-extensions.js to Selenium. To do so, open up Selenium IDE and select Options from the Options menu. Use the Browse button to select the file and then select OK. You will now need to close and reopen open Selenium IDE for the changes to take affect.

You are now ready to begin recording and running the tests.

Recording Tests

This is a very (I repeat, very) general idea on how to record tests with Selenium IDE. Just remember that once you have it open it is already in record mode and will be recording any actions you make in the browser.
  • To open Selenium IDE in the Sidebar
    • Select View, Toolbars and then Selenium IDE
  • To open Selenium IDE in a Detached window
    • Select Tools and then Selenium IDE
  • Once you have Selenium open it is automatically in Record mode.
  • Selecting any element on the screen will record an action. Right clicking an element on the screen will give you a list of options for that element.
  • Stop recording the test by clicking the Record button.

Once you have finished recording your tests there are a couple of basic things you want to do to it right away. First of all, remove 'selectWindow' and 'selectFrame' commands from your test. If you are testing a JSF tool (eg. Samigo, Melete) you will most likely want to use XPath instead of what was recorded in the Target field. JSF tools use randomly generated element id's which will change from session to session, instance to instance. For help with XPath select teh next tab.

To playback the test you just recorded (and edited) all you need to do is push the Play button. Of course, depending on where you started recording from, you may need to log out or go to a different worksite.

Test Suite Automation

Selenium IDE

To automate your tests there are a few things you need to do. First of all you need to make sure all the tests you made in Selenium IDE are saved as .html or .htm files. You can save your test as an html or htm file when you create it.

Now, in the directory of all your tests, you need to make an html file called TestSuite.htm (a sample can be found in SVN). This file should contain a simple array of links to each of your test html's. Remember TestSuite.htm should be kept in the same directory as all your tests.

Next, open Firefox and Selenium IDE. From the Selenium IDE File menu select Open Test Suite... and then select the TestSuite.htm. You will now have the Test Suite loaded into the sidebar of Selenium IDE. If you select the the first Play button you will run through the entire suite, while selecting the second Play button will run through only the test you have selected.

Using the TestNG testing framework with Selenium

Running your test suites in Selenium IDE is ok, but it doesn't provide the hands off automation and reporting features of a full testing framework. No worries, Selenium works great with TestNG. Go here for more detail.

Unknown macro: {card}
Unknown macro: {card}
Unknown macro: {composition-setup}

Practical XPath Examples

To see code examples select the XPath notation

Any element that has an attribute (The first matching element will be selected):

Unknown macro: {toggle-cloak}
//input[@value='submit']

Unknown macro: {cloak}
Unknown macro: {cloak}
  • An input with a value of submit.

Any element that 'contains' an attribute with specific text:

Unknown macro: {toggle-cloak}
//a[contains(@href,'resources.doc&')]

Unknown macro: {cloak}
Unknown macro: {cloak}
  • An a element that contains an href attribute with the text resources.doc& anywhere in it.
    • In this case the title attribute could not be used because there was more than one element on the page with the title value of Attach a copy.

Any element that 'contains' specific text but has no attribute:

Unknown macro: {toggle-cloak}
//label[contains(text(),'Correct Answer (optional)')]

Unknown macro: {cloak}
Unknown macro: {cloak}
  • A label element that contains the text Correct Answer (optional) anywhere in it.

Any element that has specific text that is surrounded by white space and has no usable attribute:

Unknown macro: {toggle-cloak}
//a[normalize-space(.)='Assignment 1']

Unknown macro: {cloak}
Unknown macro: {cloak}
  • An a element with the text Assignment 1 in it.

Any element that has specific text that is preceded by another element that 'contains' specific text:

Unknown macro: {toggle-cloak}
//td[contains(text(),'Rose, Emma(erose)')]/div/a[text()='Grade']

Unknown macro: {cloak}
Unknown macro: {cloak}
  • An a element in a that contains the text Grade that is preceded by a td element that contains the text Rose, Emma(erose).

Some more examples using sample code

Axes break xpaths into "steps". /descendant:: and /following-sibling:: will probably both come in handy someday.

Predicates refine an xpath, without being included in the results. and and or can be used to combine multiple conditions in a single predicate.

Functions that are useful in predicates: contains(), starts-with(), position(), normalize-space()

Each step typically evaluates to a "nodeset", basically a list of results. The results from the previous step are the input into the next step.

Unknown macro: {card}
Unknown macro: {deck}

1 Comment

  1. All hints (except the third) are, in fact, necessary.
    The third hint is sometimes necessary when Selenium can't find some form item.

    Example:
    When creating a new account, there are two forms elements with id 'eid' and 'pw' (elements on 'New Account' frame and on top login frame). The workaround here is to install 'XPather' and find the full DOM of the 'eid' and 'pw' fields for the 'New account' frame. This will end up like:
    //descendant::form@id='user-create_edit'/p1/input@id='eid'

    I am encountering one problem in navigation: when using '*AndWait' commands (like 'ClickAndWait'), Selenium do wait for page load but not for frame load which sometimes will cause the script to stop running...