Usage

Step 1 - Annotate your test class

Tell JUnit to run execute the your integration tests using the Selenium JUnit 4 Class Runner using the following annotation on your test class:

@RunWith(SeleniumJUnit4ClassRunner.class)

Note: @RunWith annotation is inherited.

Step 2 - Pick the Selenium API

Decide whether you are going to use the Selenium 1.0 or 2.0 API by applying the appropriate annotation from the table below to your test class:

Annotation API Version Implementation When to use
@ServerConfiguration 1.0 Selenium Server This should be consider the legacy API and is not recommended for creating new test suites
@WebDriverConfiguration 2.0 Web Driver Recommended
@WrappedDriverConfiguration 1.0 Web Driver Suitable for use when migrating existing test suites

Step 3 - Configure the API

Selenium Server

The table below lists the fields that you can use to configure the Selenium 1.0 API using a Selenium Server:

Field Type Default Description
browserURL String None The starting URL for integration tests
browserStartCommands String[] { "*firefox" } The command strings used to launch each browser for which the tests are to be run
serverHost String "localhost" The host name on which the Selenium server resides
serverPort int 4444 The port number on which the Selenium server is listening

Web Driver

The table below lists the fields that you can use to configure the Selenium 2.0 API using a web driver:

Field Type Default Description
baseDrivers Class<? extends WebDriver>[] { HtmlUnitDriver.class } The web driver classes used to launch each browser for which the tests are to be run

Wrapped Driver

The table below lists the fields that you can use to configure the Selenium 1.0 API when using a wrapped web driver:

Field Type Default Description
baseDrivers Class<? extends WebDriver>[] { HtmlUnitDriver.class } The web driver classes used to launch each browser for which the tests are to be run
browserURL String None The starting URL for integration tests

Step 4. Annotate your API object

The table below lists the annotations that you can used to inject the Selenium or WebDriver instance as a test fixture:

Annotation Use with Field type
@SeleniumServer @SeleniumServerConfiguration or @WrappedDriverConfiguration Selenium
@WebDriver @WebDriverConfiguration WebDriver

Step 5. Annotate a browser name field (Optional)

You can use the @SeleniumBrowser annotation to annotate a member variable of type string into which SeleniumJUnit4ClassRunner will inject a string to identify the browser name.