All skills
jeffallan avatar

/playwright-expert

@efebc44
by jeffallanjeffallan/claude-skills12k stars
1,124

Use when writing E2E tests with Playwright, setting up test infrastructure, or debugging flaky browser tests. Invoke to write test scripts, create page objects, configure test fixtures, set up reporters, add CI integration, implement API mocking, or perform visual regression testing. Trigger terms: Playwright, E2E test, end-to-end, browser testing, automation, UI testing, visual testing, Page Object Model, test flakiness.

Use this Skill: https://skilld.dev/gh/jeffallan/claude-skills/playwright-expert

This session only. Nothing lands on disk.

referencespage-object-model.md

≈921 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Page Object Model

Basic Page Object

// pages/LoginPage.ts
import { Page, Locator } from '@playwright/test';

export class LoginPage {
  readonly page: Page;
  readonly emailInput: Locator;
  readonly passwordInput: Locator;
  readonly submitButton: Locator;
  readonly errorMessage: Locator;

  constructor(page: Page) {
    this.page = page;
    this.emailInput = page.getByLabel('Email');
    this.passwordInput = page.getByLabel('Password');
    this.submitButton = page.getByRole('button', { name: 'Log in' });
    this.errorMessage = page.getByRole('alert');
  }

  async goto() {
    await this.page.goto('/login');
  }

  async login(email: string, password: string) {
    await this.emailInput.fill(email);
    await this.passwordInput.fill(password);
    await this.submitButton.click();
  }

  async getErrorMessage() {
    return this.errorMessage.textContent();
  }
}

Using Page Objects in Tests

// tests/login.spec.ts
import { test, expect } from '@playwright/test';
import { LoginPage } from '../pages/LoginPage';

test('successful login redirects to dashboard', async ({ page }) => {
  const loginPage = new LoginPage(page);

  await loginPage.goto();
  await loginPage.login('user@test.com', 'password123');

  await expect(page).toHaveURL(/dashboard/);
});

test('invalid credentials show error', async ({ page }) => {
  const loginPage = new LoginPage(page);

  await loginPage.goto();
  await loginPage.login('user@test.com', 'wrongpassword');

  await expect(loginPage.errorMessage).toBeVisible();
});

Custom Fixtures

// fixtures.ts
import { test as base } from '@playwright/test';
import { LoginPage } from './pages/LoginPage';
import { DashboardPage } from './pages/DashboardPage';

type Fixtures = {
  loginPage: LoginPage;
  dashboardPage: DashboardPage;
  authenticatedPage: Page;
};

export const test = base.extend<Fixtures>({
  loginPage: async ({ page }, use) => {
    await use(new LoginPage(page));
  },

  dashboardPage: async ({ page }, use) => {
    await use(new DashboardPage(page));
  },

  authenticatedPage: async ({ page }, use) => {
    const loginPage = new LoginPage(page);
    await loginPage.goto();
    await loginPage.login('user@test.com', 'password123');
    await page.waitForURL(/dashboard/);
    await use(page);
  },
});

export { expect } from '@playwright/test';

Using Fixtures

// tests/dashboard.spec.ts
import { test, expect } from '../fixtures';

test('shows user profile', async ({ authenticatedPage, dashboardPage }) => {
  await expect(dashboardPage.userProfile).toBeVisible();
});

Component Page Objects

// components/NavBar.ts
export class NavBar {
  constructor(private page: Page) {}

  readonly homeLink = () => this.page.getByRole('link', { name: 'Home' });
  readonly profileLink = () => this.page.getByRole('link', { name: 'Profile' });
  readonly logoutButton = () => this.page.getByRole('button', { name: 'Logout' });

  async logout() {
    await this.logoutButton().click();
  }
}

// pages/DashboardPage.ts
export class DashboardPage {
  readonly navBar: NavBar;

  constructor(private page: Page) {
    this.navBar = new NavBar(page);
  }
}

Quick Reference

Pattern Purpose
Page Object Encapsulate page interactions
Fixture Share setup across tests
Component PO Reusable UI components
Locator methods Lazy evaluation
Best Practice Reason
Methods for actions Readable tests
Locators as getters Lazy evaluation
No assertions in PO Flexibility
Fixtures for setup DRY, maintainable

Source: SKILL.md on GitHub

1 alert16d5 checks · Risk CRITICAL
  • Gen Agent Trust Hub16d

    Error: AI Analysis failed - API error after retries

  • Socket16d

    No alerts

  • Snyk16d

    Risk: LOW · No issues

  • Runlayer6mo

    6 files scanned · No issues

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at efebc44. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 months ago.

Steadyupdated 5 months ago
Other metadata
metadata
{
  "author": "https://github.com/Jeffallan",
  "version": "1.1.0",
  "domain": "quality",
  "triggers": "Playwright, E2E test, end-to-end, browser testing, automation, UI testing, visual testing",
  "role": "specialist",
  "scope": "testing",
  "output-format": "code",
  "related-skills": "test-master, react-expert, devops-engineer"
}
  • Testing
  • TypeScript
  • playwright
  • e2e-testing
  • browser-automation
  • page-object-model
  • ui-testing
  • visual-testing
  • ci-cd

README badge

README badge for jeffallan/claude-skills/playwright-expert

Writes Playwright E2E tests using the Page Object Model pattern, handles test fixtures and configuration, debugs flaky tests via trace viewer, and integrates into CI/CD pipelines. Targets browser automation workflows with role-based selectors, auto-waiting, and parallel test execution.

Generated from the current SKILL.md.

Does this skill help with visual regression testing?
Yes. The skill covers visual regression testing and includes reference guides for setting up visual comparisons as part of your test suite.
What selector strategy does this skill recommend?
Role-based selectors (getByRole, getByLabel) are preferred for resilience to styling changes. CSS class selectors are discouraged as brittle.
Does this skill cover CI/CD integration?
Yes. The skill includes guidance on adding Playwright tests to CI/CD pipelines and configuring parallel execution.
How does this skill approach flaky tests?
It provides a debugging workflow using trace viewer and screenshots, emphasizes auto-waiting over arbitrary timeouts, and recommends running tests multiple times to verify stability.
Does this skill use Page Object Model?
Yes. POM is a core pattern recommended for maintainability, with included reference guide and code examples.

Generated from the current SKILL.md. These answers refresh after source changes.