sotaaaaa / playwright-boilerplate

A NodeJS Playwright project utilizing the Page Object Model

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Playwright Tests View site - GH Pages

Playwright Page Object Model Boilerplate

This is an example of a Playwright project that uses the page object model design pattern. In general, Playwright best practices are followed where possible and the configuration is largely the default configuration generated when you install Playwright.

The site under test is Automation Exercise and tests were derived from the Automation Exercise test cases.

The pageObjects Directory

pageObjects
    ├── base.page.ts
    ├── base.pageComponent.ts
    ├── pageFixture.ts
    ├── components
        └── *.pageComponent.ts
    └── pages
        └── *.page.ts

This directory contains our base page class, base page component class, and all page object classes that extend those base classes.

  • base.page.ts
    • The base page class is intended to include Locators and functionality that is shared across all pages. It takes a Page instance as a constructor parameter.
  • base.pageComponent.ts
    • I like to use page components to logically separate page elements that are common across multiple pages from pages themselves. This class takes a Locator parameter in addition to a Page instance. Typically, page components are instantiated within other page classes, and not within the spec file itself.
    • Here's an example where a page component is being instantiated within a page object. Specifically, this the navigation bar component being instantiated within the home page class, as the home page contains the navigation bar. The navigation bar component can then be used in our tests. See here and here.
  • pageFixture.ts

Accessibility Testing

I'm using the @axe-core/playwright for accessibility testing in axe.spec.ts. These are failing miserably on the test site I'm using.

Github Actions

I've made some changes to the Github Actions workflow that Playwright provides.

About

A NodeJS Playwright project utilizing the Page Object Model


Languages

Language:TypeScript 100.0%