title: Using Selenium 2.0 WebDriver in practice
body: <p>I want to write Selenium test cases in JUnit and test my projects in multiple browsers and I would like to take advantage of the fact that all Selenium drivers implement the same interface.</p>
  
  <p>Each test case should look like this:</p>
  
  <pre><code>package fm;
  
  import org.openqa.selenium.WebElement;
  import org.openqa.selenium.By;
  import org.openqa.selenium.WebDriver;
  import static org.junit.Assert.*;
  
  public class HomepageTest {
  
      @Test
      public void testTitle(WebDriver driver) {
          driver.get("http://localhost/");
          assertEquals("Foo", driver.getTitle());
      }
  
      @Test
      public void testSearchForm(WebDriver driver) {
          //...
      }
  
  }
  </code></pre>
  
  <p>The passed WebDriver implementations should be controlled somewhere centrally. I'll probably need to override some of the JUnit behaviour and I hope it's possible.</p>
  
  <p>I want to do it this way in order to avoid two things:</p>
  
  <ul>
  <li>Code repetition: If each test case would initialize all tested browsers in @Before, the test suite would have a lot of repeated code that is hard to maintain.</li>
  <li>Speed of the test suite: If I had centralized control over the order and passed WebDriver implementations, I could easily manage to open for example Firefox, run all test cases in it, close it and open the next browser. If each test case would manage to open and close browsers on its own, it would add a lot of time to each test run.</li>
  </ul>
  
  <p>Anybody have an idea how should I do it? Thanks.</p>