15. Scalable Page Object Model in Java

Enterprise Page Object in Java

public class LoginPage {
    private final Page page;
    private final Locator emailInput;
    private final Locator passwordInput;
    private final Locator submitBtn;

public LoginPage(Page page) {
this.page = page;
this.emailInput = page.getByLabel("Email");
this.passwordInput = page.getByLabel("Password");
this.submitBtn = page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName("Sign In"));
}

public void navigate() {
page.navigate("/login");
}

public void login(String email, String password) {
emailInput.fill(email);
passwordInput.fill(password);
submitBtn.click();
}
}

Task

  • Implement CounterComponent in Java:
  • 1. Private int count initialized to 0.
  • 2. Public method increment() increases count.
  • 3. Public method getCount() returns count.
πŸ’‘Common doubts
Did you like the problem?
Lesson 15 of 18
Java
Loading code editor…
Next