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.

referencesdebugging-flaky.md

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

Debugging & Flaky Tests

Debugging Tools

// Pause execution and open inspector
await page.pause();

// Enable step-by-step mode
PWDEBUG=1 npx playwright test

// Slow motion
test.use({ launchOptions: { slowMo: 500 } });

// Headed mode
npx playwright test --headed

Trace Viewer

# View trace from failed test
npx playwright show-trace trace.zip

# Generate trace always
test.use({ trace: 'on' });

# View in UI mode
npx playwright test --ui

Common Flaky Test Causes

1. Race Conditions

// ❌ Bad: Element may not exist yet
await page.click('.submit-btn');

// ✅ Good: Auto-waiting built in
await page.getByRole('button', { name: 'Submit' }).click();

2. Animation/Transitions

// ❌ Bad: Click during animation
await page.click('.menu-item');

// ✅ Good: Wait for stable state
await page.getByRole('menuitem').click();
await expect(page.getByRole('menu')).toBeVisible();

3. Network Timing

// ❌ Bad: Assumes data loaded
await page.goto('/dashboard');
expect(await page.textContent('.user-name')).toBe('John');

// ✅ Good: Wait for network
await page.goto('/dashboard');
await page.waitForResponse('**/api/user');
await expect(page.getByTestId('user-name')).toHaveText('John');

4. Test Isolation

// ❌ Bad: Tests share state
test('test 1', async () => { /* creates user */ });
test('test 2', async () => { /* assumes user exists */ });

// ✅ Good: Each test is independent
test.beforeEach(async ({ page }) => {
  await page.request.post('/api/test/reset');
});

Proper Waiting

// Wait for element state
await expect(page.getByText('Success')).toBeVisible();
await expect(page.getByRole('button')).toBeEnabled();
await expect(page.getByRole('dialog')).toBeHidden();

// Wait for navigation
await page.waitForURL(/dashboard/);

// Wait for response
await page.waitForResponse(r => r.url().includes('/api/data'));

// Wait for load state
await page.waitForLoadState('networkidle');

// AVOID arbitrary waits
await page.waitForTimeout(3000); // ❌ BAD

Retry Strategies

// playwright.config.ts
export default defineConfig({
  retries: process.env.CI ? 2 : 0,

  // Retry only specific tests
  expect: {
    timeout: 10000, // Increase assertion timeout
  },
});

// Per-test retry
test('flaky test', async ({ page }) => {
  test.info().annotations.push({ type: 'issue', description: 'Known flaky' });
  // ...
});

Debugging Output

// Console output
test('debug test', async ({ page }) => {
  page.on('console', msg => console.log(msg.text()));
  page.on('pageerror', err => console.log(err.message));
});

// Screenshot on step
await page.screenshot({ path: 'debug.png' });

Quick Reference

Command Purpose
PWDEBUG=1 Enable inspector
--headed Show browser
--ui UI mode
page.pause() Pause execution
show-trace View trace file
Fix Flaky Cause
Auto-wait locators Race conditions
waitForResponse Network timing
Test isolation Shared state
Increase timeout Slow operations

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.