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.
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.
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") );
}
}
The test is simplified but it will return a page object of a successful login.
thanks
Your best option might be to use the LoginPageTest class as a parent class and extend each of your test classes from LoginPageTest.
That way, each test can login to the system using the parent’s setup and tear down methods and do its own additional testing as well.