24. Scalable Page Object Model in ES6

Enterprise Page Object Model in JavaScript

// pages/BasePage.js
export class BasePage {
  constructor(page) {
    this.page = page;
  }
  async goto(path) {
    await this.page.goto(path);
  }
}

// pages/LoginPage.js
import { BasePage } from "./BasePage.js";

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 CartComponent class:
  • 1. Constructor initializes this.itemCount = 0.
  • 2. Method addItem() increments this.itemCount.
  • 3. Method getItemCount() returns this.itemCount.
πŸ’‘Common doubts
Did you like the problem?
Lesson 24 of 35
JavaScript
Loading code editor…
Next