Skip to content

mate-academy/qa_pw_oop_coffee-cart

Repository files navigation

Create BasePage class for Coffee-Cart testing

Description

In this task, you will practice building the page classes hierarchy and apply the OOP principles.

Preparation

  1. Open the forked repo in VSCode.

  2. Create a new branch by running git checkout -b task_solution.

  3. Run the installation commands:

    • npm ci
    • npx playwright install

Task

  1. Create BasePage.js file under the folder ./src/pages/.
  2. Create a new class BasePage.
  3. Add a constructor to the created BasePage class:
  constructor(page) {
    this.page = page;
  }
  1. Open the CartPage.js file.
  2. Import BasePage class to it.
  3. Inherit the BasePage by the CartPage:
export class CartPage extend BasePage {...}
  1. Update CartPage constructor method to initialize parent class constructor:
  • 7.1 Remove the line this.page = page; - this will now be done in the BasePage class.
  • 7.2 Add as a first line method super(page);. This method will initialize the parent constructor.
  1. Repeat the steps 4-7 for the MenuPage.js class.
  2. Run all the tests to make sure nothing is broken.
  3. Move the open() method to the BasePage:
  • 10.1 Add the _url protected property to the BasePage:
export class BasePage {
  _url;

  constructor(page) {...}
}
  • 10.2 Add the public url() method to the BasePage class:
  url() {
    if (this._url) {
      return this._url;
    } else {
      throw Error(`The property '_url' must be implemented`);
    }
  }
  • 10.3 Add the open() method to the BasePage:
  async open() {
    await this.step(`Open page`, async () => {
      await this.page.goto(this.url());
    });
  }
  • 10.4 Add the protected _pageName() method:
  _pageName() {
    return this.constructor.name.replace('Page', '');
  }
  • 10.5 Update the open() method step to incorporate a page name:
... this.step(`Open ${this._pageName()} page`, ...)
  1. Assign value to this._url = in constructor for the MenuPage and CartPage classes.
  2. Remove the open() methods from MenuPage and CartPage classes.
  3. Run all the tests to make sure nothing is broken.
  4. Move the reload() method from the MenuPage and CartPage classes to the BasePage class.
  5. Move the waitForLoading() method from the CartPage class to the BasePage class.
  6. Run all the tests to make sure nothing is broken.

Task Reporting

  1. Add and commit all your updates.
  2. Push the code to the origin.
  3. Create a PR for your changes.
  4. Keep implementing suggestions from code review until your PR is approved.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published