7. Classes & Object-Oriented Patterns for Page Objects

Classes for Page Object Architecture

export class BasePage {
  constructor(page) {
    this.page = page;
  }

async navigate(path) {
await this.page.goto(path);
}
}

export class LoginPage extends BasePage {
constructor(page) {
super(page);
this.emailInput = page.getByLabel("Email");
this.passwordInput = page.getByLabel("Password");
this.submitBtn = page.getByRole("button", { name: "Sign In" });
}

async login(email, password) {
await this.emailInput.fill(email);
await this.passwordInput.fill(password);
await this.submitBtn.click();
}
}

Task

  • Implement NavigationComponent class:
  • 1. Constructor accepts page.
  • 2. Method getHomeLink() returns page.getByRole("link", { name: "Home" }).
πŸ’‘Common doubts
Did you like the problem?
Lesson 7 of 35
JavaScript
Loading code editor…
Next