← Back to Hub

Playwright E2E Testing

Skill for writing end-to-end tests with Playwright. Covers page object patterns, assertions, and handling async UI.

Skilltestingplaywrighte2etestingbrowser

by Build Ship Grow

playwright-e2e-testing.yml
yaml + markdown
---
name: e2e
description: Write Playwright end-to-end tests for web applications
triggers:
  - /e2e
  - "write e2e test"
  - "playwright test"
---

# Playwright E2E Testing Skill

## Setup Check
Before writing tests, verify `playwright.config.ts` exists.
If not, suggest: `pnpm create playwright`

## Test Structure
```ts
import { test, expect } from "@playwright/test";

test.describe("Feature Name", () => {
  test("user can complete action", async ({ page }) => {
    await page.goto("/path");
    await page.getByRole("button", { name: "Submit" }).click();
    await expect(page.getByText("Success")).toBeVisible();
  });
});
```

## Best Practices
- Use role-based selectors: `getByRole`, `getByLabel`, `getByText`
- Never use CSS selectors or test IDs unless absolutely necessary
- Wait for network idle after navigation: `waitForLoadState("networkidle")`
- Use `test.beforeEach` for common setup (login, seed data)
- Group related tests in `test.describe` blocks
- Take screenshots on failure: configured in playwright.config.ts
- Run in CI with `npx playwright test --reporter=html`

## Page Object Pattern
For complex pages, extract a page object:
```ts
class LoginPage {
  constructor(private page: Page) {}
  async login(email: string, password: string) {
    await this.page.getByLabel("Email").fill(email);
    await this.page.getByLabel("Password").fill(password);
    await this.page.getByRole("button", { name: "Sign in" }).click();
  }
}
```