/playwright-e2e:page-object-generationfrom playwright-e2e
Generate Page Object Model (POM) classes with typed locators as getters, actions as async methods, and a shared base page class. One POM per page or major section.
Ships in playwright-e2e. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Behaviour is controlled by the testPattern key in .playwright-agent.json:
testPattern value | Pattern applied |
|---|---|
"page-object" (default) | Generate dedicated *.page.ts files under tests/e2e/pages/ |
"co-located" | Inline selectors and actions inside spec files; no separate POM classes |
Only generate POM classes when testPattern is "page-object" or when not set (default).
<page-name>.page.ts in kebab-case (e.g., checkout.page.ts, login.page.ts).<PageName>Page in PascalCase (e.g., CheckoutPage, LoginPage).checkout-summary.page.ts).Every POM class:
Page instance in its constructor and stores it as protected readonly page.void or a data value.BasePage for common helpers.// tests/e2e/pages/login.page.ts
import { Page, Locator } from '@playwright/test';
import { BasePage } from './base.page';
export class LoginPage extends BasePage {
constructor(page: Page) {
super(page);
}
// Locators as getters — evaluated fresh on each access
get emailInput(): Locator {
return this.page.getByLabel('Email');
}
get passwordInput(): Locator {
return this.page.getByLabel('Password');
}
get submitButton(): Locator {
return this.page.getByRole('button', { name: 'Sign in' });
}
get errorMessage(): Locator {
return this.page.getByRole('alert');
}
// Actions as async methods — return void or a value, never a POM
async goto(): Promise<void> {
await this.page.goto('/login');
}
async login(email: string, password: string): Promise<void> {
await this.emailInput.fill(email);
await this.passwordInput.fill(password);
await this.submitButton.click();
}
async getErrorText(): Promise<string | null> {
return this.errorMessage.textContent();
}
}
Always generate (or reuse) a base.page.ts that all POMs extend. The base provides shared navigation helpers and a common wait utility.
// tests/e2e/pages/base.page.ts
import { Page } from '@playwright/test';
export class BasePage {
protected readonly page: Page;
constructor(page: Page) {
this.page = page;
}
async waitForPageLoad(): Promise<void> {
await this.page.waitForLoadState('domcontentloaded');
}
async getPageTitle(): Promise<string> {
return this.page.title();
}
async getCurrentURL(): Promise<string> {
return this.page.url();
}
}
Instantiate POMs inside test blocks, not at module scope, to ensure each test gets a fresh page context:
import { test, expect } from '../fixtures/test';
import { LoginPage } from '../pages/login.page';
test.describe('Login', () => {
test('should navigate to dashboard after login', async ({ page }) => {
const loginPage = new LoginPage(page);
await loginPage.goto();
await loginPage.login('[email protected]', 'secret');
await expect(page).toHaveURL('/dashboard');
});
test('should display error for wrong password', async ({ page }) => {
const loginPage = new LoginPage(page);
await loginPage.goto();
await loginPage.login('[email protected]', 'wrong');
await expect(loginPage.errorMessage).toBeVisible();
});
});
| Do | Don't |
|---|---|
| Locators as getter properties | Cache locators in constructor |
Actions return void or a scalar value | Return another POM from an action method |
| One POM per page or major section | One giant POM for the whole app |
Extend BasePage for shared helpers | Duplicate navigation helpers in each POM |
Instantiate POMs inside test blocks | Share a single POM instance across tests |
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub gagandeepp/software-agent-teams --plugin playwright-e2e7 skills in this plugin
/e2e-assertionsWeb-first Playwright assertions with built-in auto-waiting. Covers the full assertion API, soft assertions for non-critical checks, negation, custom failure messages, and anti-patterns to avoid./e2e-project-structureScaffold the E2E directory layout, establish file naming conventions, adapt to monorepo directoryMapping, and support both the page-object and co-located test patterns./e2e-selectorsFramework-aware locator strategy for Playwright. Defines locator priority, per-framework selector tables for React, Angular, Vue, and plain HTML, anti-patterns to avoid, and DO/DON'T examples.