title: Re-using login functionality in Selenium page object model tests
body: <p>I am exploring the use of Selenium 2 on a web application which requires authentication before a user can use any of the application. I am planning on either JUnit 4 or TestNG (Still investigating which one to use with Grid 2). I may plan to use jbehave as well.</p>
  
  <p>Does anyone have any suggestions on how I can improve the following test so I can use  successful login functionality across all my tests? I want to avoid duplicating login in the tests itself.</p>
  
  <pre><code>public class LoginPageTest {
  
      private LoginPage page;
  
      @Before
      public void openTheBrowser() {
          page = PageFactory.initElements(new FirefoxDriver(), LoginPage.class);
          page.open("http://www.site.com/Login");
      }
  
      @After
      public void closeTheBrowser() {
          page.close();
      }
  
      @Test
      public void whenTheUserEntersValidCredentialsTheUserIsLoggedIn() {
          assertThat(page.getTitle(), containsString("Login") );
      }   
  }
  </code></pre>
  
  <p>The test is simplified but it will return a page object of a successful login. </p>
  
  <p>thanks</p>