Web Driver

The simple test case below illustrates the usage of the Selenium 2.0 API.

package com.btmatthews.selenium.junit4.runner.test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.openqa.selenium.WebDriver;

import com.btmatthews.selenium.junit4.runner.SeleniumJUnit4ClassRunner;
import com.btmatthews.selenium.junit4.runner.SeleniumWebDriver;
import com.btmatthews.selenium.junit4.runner.WebDriverConfiguration;

/**
 * Unit tests for the {@link WebDriverConfiguration} configuration style.
 * 
 * @author <a href="mailto:brian@btmatthews.com">Brian Thomas Matthews</a>
 * @since 1.0.0
 */
@RunWith(SeleniumJUnit4ClassRunner.class)
@WebDriverConfiguration()
public final class TestWebDriver {

        /**
         * The object used to start/stop the web browser used for testing.
         */
        @SeleniumWebDriver
        private WebDriver webDriver;

    /**
     * The name of the browser being used for the test.
     */ 
        @SeleniumBrowser
        private String browserName;

        /**
         * Verify that the test runner injected the web driver.
         */
        @Test
        public void testInjection() {
                assertNotNull(webDriver);
                assertNotNull(browserName);
                assertEquals("HtmlUnitDriver", browserName);
        }

        /**
         * Verify that we can navigate to the Google home page.
         */
        @Test
        public void testHomePage() {
                webDriver.navigate().to("http://www.google.com");
                assertEquals("Google", webDriver.getTitle());
        }
}