Now we are writing a new test suite using Selenium 2 (Webdriver) and TestNG . Our tests use an Object Object , and we are very pleased with how everything looks like this. However, we ran into a design problem with our tests, and we seem to be unable to find a good solution for this. 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 expand our tests that require user login from this test. Ideally, we could write something like this:
public class DashboardTestCase extends LoginTestCase { @Test public void testDashboard(DashboardPage dashboardPage) { ... } }
At this point, the user is in DashboardPage
, and the only thing needed is the object of this page that was created in LoginTestCase
.
I know that the obvious solution is to save this object in a variable (in LoginTestCase
), after which there will be access to children's test cases. However, this looks very ugly and can lead to misuse of this variable.
Is there a better solution for this or some kind of template that solves this problem?
source share