Navigation



For news about this project, please visit the blog.


SelAid: Helper Classes for Selenium WebDriver Tests

SelAid consists of open source helper classes for testing the more complex HTML constructs via Selenium WebDriver.

WebDriver is easy enough to use for testing individual HTML elements, but certain HTML elements only make sense in combination with others. For example:

  • TABLE, TR, TH and TD form a table
  • SELECT and OPTION form a select list (or listbox)
  • Within one form, INPUT elements sharing a NAME attribute form a radio button group

The objective of SelAid is to provide a higher level abstraction for these more complex constructs to make testing them easier.

License

SelAid is distributed under an Apache 2.0 License.

System requirements

  • JRE 1.6 or later
  • Selenium 2.0 Alpha 4 or later

Example

Here's an example of an HTML listbox with option groups and multiple select.
  <select id="colors" size="3" multiple="true">
    <optgroup label="primary">
      <option value="r" id="red">Red</option>
      <option selected value="y" id="yellow">Yellow</option>
      <option value="b" id="blue">Blue</option>
    </optgroup">
    <optgroup label="secondary">
      <option selected value="g" id="green">Green</option>
      <option value="o" id="orange">Orange</option>
      <option value="v" id="violet">Violet</option>
    </optgroup">
  </select>
You can test it as follows using SelAid, WebDriver and JUnit:
  WebElement element = _driver.findElement(By.id("colors"));
  SelectHelper helper = new SelectHelper(element);
  assertTrue(helper.isMultiSelect());
  assertTrue(helper.isSelected("yellow"));
  assertFalse(helper.isSelected("red"));
  assertFalse(helper.isSelected("fuchsia")); // doesn't exist
  // concisely check which entries are selected
  assertArrayEquals(
      new String[] {"Yellow", "Green"},
      helper.getSelectedText()
      );
You can also change the selections in a one-liner:
  helper.selectValues(new String[] {"r", "o"} );
If you wish, you can interact with the option groups individually and again very concisely:
  OptionGroupHelper primaryColors = 
      helper.getGroup("primary");
  assertArrayEquals(
      new String[] {"Red", "Yellow", "Blue"},
      primaryColors.getOptionText()
      );

Release 1.0.1 (May 22, 2010)

Added a getElement() method to most helpers in order to get back the underlying Selenium WebDriver object.

Added support for option groups within a select list.

Release 1.0.0 (May 15, 2010)

Basic functionality for tables, select lists and radio button groups.

Installation

Simply unzip the distribution, put the JAR and the Seleium JARs (which you need to download separately) in your classpath, and start writing tests. See the included Javadoc for examples.
Download links are to the right.