We are now writing a new test suite using Selenium 2 (Webdriver) and TestNG. Our tests use the Page Object pattern and we are very happy with the the way things are looking so far. However, we ran into a design issue with our tests and we don't seem to be able to find a good solution for it. Let me give you an example. Here is our LoginTestCase:
public class LoginTestCase extends MyTestCase {
@BeforeTest
public void login() {
HomePage homepage = PageFactory.initElements(getDriver(), HomePage.class);
LoginPage loginPage = homepage.login();
DashboardPage dashboardPage = loginPage.loginUser("username", "password");
}
}
We would like to extend our tests that require a user to be logged in from this test. Ideally we would be able to write something like this:
public class DashboardTestCase extends LoginTestCase {
@Test
public void testDashboard(DashboardPage dashboardPage) {
...
}
}
At this point the user is at the DashboardPage and the only thing needed is the object of that page which was created in the LoginTestCase.
I know the obvious solution is to store that object in a variable (in the LoginTestCase) that will then be access by the child test cases. However this looks very ugly and can lead to a misuse of that variable.
Is there a better solution for this or some pattern that addresses this design issue?