All skills
jeffallan avatar

/playwright-expert

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

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.

referencesapi-mocking.md

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

API Mocking

Basic Route Mocking

test('displays mocked user data', async ({ page }) => {
  await page.route('**/api/users', route =>
    route.fulfill({
      status: 200,
      contentType: 'application/json',
      body: JSON.stringify([
        { id: 1, name: 'Alice' },
        { id: 2, name: 'Bob' },
      ]),
    })
  );

  await page.goto('/users');
  await expect(page.getByText('Alice')).toBeVisible();
  await expect(page.getByText('Bob')).toBeVisible();
});

Mock Error Responses

test('handles API error gracefully', async ({ page }) => {
  await page.route('**/api/users', route =>
    route.fulfill({
      status: 500,
      body: JSON.stringify({ error: 'Server error' }),
    })
  );

  await page.goto('/users');
  await expect(page.getByText('Failed to load users')).toBeVisible();
});

Conditional Mocking

test('mock specific requests', async ({ page }) => {
  await page.route('**/api/**', route => {
    const url = route.request().url();

    if (url.includes('/api/users')) {
      return route.fulfill({
        status: 200,
        json: [{ id: 1, name: 'Mocked User' }],
      });
    }

    // Let other requests through
    return route.continue();
  });
});

Modify Responses

test('modify API response', async ({ page }) => {
  await page.route('**/api/products', async route => {
    // Get real response
    const response = await route.fetch();
    const json = await response.json();

    // Modify it
    json.products = json.products.map(p => ({
      ...p,
      price: p.price * 0.9, // 10% discount
    }));

    // Return modified response
    await route.fulfill({ json });
  });
});

Wait for Response

test('waits for API response', async ({ page }) => {
  const responsePromise = page.waitForResponse('**/api/users');

  await page.getByRole('button', { name: 'Load Users' }).click();

  const response = await responsePromise;
  expect(response.status()).toBe(200);
});

Mock Network Conditions

test('slow network', async ({ page }) => {
  await page.route('**/api/**', async route => {
    await new Promise(resolve => setTimeout(resolve, 3000));
    await route.continue();
  });

  await page.goto('/dashboard');
  await expect(page.getByText('Loading...')).toBeVisible();
});

HAR File Mocking

// Record responses
await page.routeFromHAR('mocks/api.har', {
  url: '**/api/**',
  update: true, // Record new responses
});

// Playback recorded responses
await page.routeFromHAR('mocks/api.har', {
  url: '**/api/**',
  update: false,
});

Quick Reference

Method Purpose
route.fulfill() Return mock response
route.continue() Pass to real server
route.fetch() Get real response
route.abort() Block request
waitForResponse() Wait for API call
routeFromHAR() Use recorded responses
Pattern Use Case
Mock all Isolated testing
Mock errors Error handling
Modify response Test edge cases
Network delay Loading states

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.