I’m trying to nail down on some best practices for automation testing with a large test suite.
What I have is a set of page objects (e.g. LoginPage.java
, HomePage.java
), which all inherit from AbstractPage.java
(used for common functionality). These are in the pages
package
All the page objects are initialized in PageInitializer.java
, which calls their constructor. The cucumber step definition files (e.g. LoginSteps.java
, HomePageSteps.java
) inherit from PageInitializer.java
, so that they have access to the methods and fields from the page objects when running the tests. These are in the steps
package.
I’ve added a generic example of the implementation:
AbstractPage.java
package pages; public abstract class AbstractPage { AbstractPage() {} void click(String name, By locator) { /* generic click method */ } }
LoginPage.java
package pages; public class LoginPage extends AbstractPage { private static final By locatorLoginButton = By.id("login); public LoginPage() { super(); } public void clickLogin() { abstractPage.click("login button", locatorLoginButton); } }
PageInitializer.Java
package steps; public class PageInitializer { private LoginPage loginPage; LoginPage loginPage() { if (this.loginPage == null) { loginPage = new LoginPage(); return loginPage; } return this.loginPage; } }
LoginSteps.java
package steps; public class LoginSteps extends PageInitializer { @When("I click login button$ ") public void iClickLoginButton() { loginPage.clickLogin() } }
In reality, there’s over 10 pages inheriting from AbstractPage.java
, all of which are initialized in PageInitializer.java
. There is a similar number of step definition files.
My question is, what best practices can I apply to my test suite to improve the quality of the code, and are there any issues with the way I am currently doing things?