Skip to content

Instantly share code, notes, and snippets.

@mxschmitt
Created December 8, 2021 20:47
Show Gist options
  • Save mxschmitt/adedb44167da986a79d782e2fc265bf3 to your computer and use it in GitHub Desktop.
Save mxschmitt/adedb44167da986a79d782e2fc265bf3 to your computer and use it in GitHub Desktop.
Playwright POM
import { Page } from '@playwright/test';
/**
* This is a Page Object Model (POM) class for the application's Todo page. It
* provides locators and common operations that make writing tests easier.
* @see https://playwright.dev/docs/test-pom
*/
export class TodoPage {
/**
* Locators are used to reflect a element on the page with a selector.
* @see https://playwright.dev/docs/api/class-locator
*/
listItems = this.page.locator('.todo-list li');
inputBox = this.page.locator('input.new-todo');
filterByActiveItemsButton = this.page.locator('.filters >> text=Active');
filterByCompletedItemsButton = this.page.locator('.filters >> text=Completed');
constructor(public readonly page: Page) { }
async addItem(text: string) {
await this.inputBox.fill(text);
await this.inputBox.press('Enter');
}
async goto() {
await this.page.goto('https://todomvc.com/examples/vanilla-es6/');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment