Token导航 LogoToken导航TokenDH.com
开发操作浏览器github未标认证来源可访问许可证需确认审计通过

playwright-proPlaywright 专业版

Agent Skill

用于辅助测试设计、自动化测试、用例整理和回归验证。它适合让 Agent 编写单元测试、端到端测试、测试计划或根据失败日志定位问题。使用时需要确认项目测试框架、运行命令和夹具数据,避免为了通过测试而改坏真实逻辑;涉及浏览器或外部服务时,应区分本地模拟、测试环境和生产环境。

总安装

1,958

周安装

80

GitHub Stars

103

下载量

627
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:playwright-pro(Playwright 专业版)
来源仓库:https://github.com/borghei/claude-skills
仓库路径:skills/playwright-pro
安装命令:
npx skills add https://github.com/borghei/claude-skills --skill playwright-pro
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/borghei/claude-skills --skill playwright-pro

简介

playwright-pro 提供生产级端到端测试解决方案,支持从用户故事自动生成测试用例。

  • 采用 Page Object 模式与稳健定位策略,集成 CI/CD 与视觉回归测试。
  • 输出可维护的测试套件与 flaky test 修复指南,提升回归验证效率。
  • 执行测试时需区分模拟环境与真实浏览器行为,避免误判逻辑缺陷。
  • 适用宿主包括 Codex、Claude、Cursor、Gemini CLI,接入前应确认版本、权限和运行环境要求。

SKILL.md

Playwright Pro

Tier: POWERFUL Category: Engineering / Testing Maintainer: Claude Skills Team

Overview

Production-grade end-to-end testing with Playwright. Generate tests from user stories, implement the Page Object pattern for maintainability, apply the correct locator strategy for resilient tests, diagnose and fix flaky tests, migrate from Cypress or Selenium, integrate with CI/CD, run visual regression tests, and perform accessibility audits. Enforces the 10 golden rules that eliminate 90% of E2E test failures.

Sub-Skills

This skill uses compound sub-skill architecture. Each sub-skill in skills/ handles a specific workflow:

Sub-SkillFilePurpose
Initskills/init.mdBootstrap Playwright in a project -- install, configure, create first test
Generateskills/generate.mdGenerate test files from user stories or page descriptions
Fixskills/fix.mdDiagnose and fix failing or flaky tests using trace analysis
Migrateskills/migrate.mdMigrate from Cypress or Selenium to Playwright
Reviewskills/review.mdAudit test quality, coverage gaps, and flaky test indicators
Reportskills/report.mdGenerate execution reports from Playwright JSON output
Coverageskills/coverage.mdMap tests to user stories, identify coverage gaps
BrowserStackskills/browserstack.mdBrowserStack cloud integration for cross-browser testing
TestRailskills/testrail.mdTestRail integration for test case management

Sub-Skill Flow

Init ──> Generate ──> Review ──> Fix (if needed)
                         │
                    Coverage ──> Generate (fill gaps)
                         │
                    Report ──> BrowserStack / TestRail

Typical lifecycle: Init sets up the project, Generate creates tests from stories, Review audits quality, Fix resolves failures, Coverage identifies gaps that feed back into Generate, and Report/BrowserStack/TestRail handle reporting and integration.

Scripts

ScriptPurpose
scripts/test_generator.pyGenerate Playwright test code from user story descriptions
scripts/flaky_detector.pyAnalyze multiple CI runs to detect flaky test patterns
scripts/coverage_mapper.pyMap tests to user flows and identify coverage gaps
scripts/page_object_generator.pyGenerate Page Object classes from HTML or selector lists
scripts/test_analyzer.pyScan test files for anti-patterns and quality issues
scripts/test_report_parser.pyParse Playwright JSON reports into summaries

Keywords

Playwright, E2E testing, end-to-end testing, page objects, flaky tests, test generation, Cypress migration, Selenium migration, visual regression, accessibility testing, CI integration

10 Golden Rules

These rules are non-negotiable. Following them eliminates 90% of E2E test failures.

  1. getByRole() over CSS/XPath — resilient to markup changes
  2. Never page.waitForTimeout() — use web-first assertions instead
  3. expect(locator) auto-retries; expect(await locator.textContent()) does NOT
  4. Isolate every test — no shared state between tests
  5. baseURL in config — zero hardcoded URLs in tests
  6. Retries: 2 in CI, 0 locally — retries mask flakiness in dev
  7. Traces: 'on-first-retry' — rich debugging without slowdown
  8. Fixtures over globalstest.extend() for shared setup
  9. One behavior per test — multiple related assertions are fine
  10. Mock external services only — never mock your own app

Locator Priority (Most to Least Preferred)

1. getByRole('button', { name: 'Submit' })     — semantic, accessible
2. getByLabel('Email address')                   — form fields with labels
3. getByText('Welcome back')                     — visible text content
4. getByPlaceholder('Enter your email')          — inputs with placeholder
5. getByTestId('submit-button')                  — when no semantic option exists
6. page.locator('.submit-btn')                   — CSS as last resort
7. page.locator('//button[@type="submit"]')      — XPath: avoid entirely

Why This Order Matters

// FRAGILE: breaks when CSS class changes
await page.locator('.btn-primary-lg').click();

// FRAGILE: breaks when DOM structure changes
await page.locator('div > form > button:nth-child(2)').click();

// RESILIENT: survives refactors, tests what users see
await page.getByRole('button', { name: 'Create account' }).click();

Configuration

playwright.config.ts

import { defineConfig, devices } from '@playwright/test';

export default defineConfig({
  testDir: './tests/e2e',
  fullyParallel: true,
  forbidOnly: !!process.env.CI,
  retries: process.env.CI ? 2 : 0,
  workers: process.env.CI ? 4 : undefined,
  reporter: process.env.CI
    ? [['html'], ['github'], ['json', { outputFile: 'test-results.json' }]]
    : [['html']],

  use: {
    baseURL: process.env.BASE_URL || 'http://localhost:3000',
    trace: 'on-first-retry',
    screenshot: 'only-on-failure',
    video: 'retain-on-failure',
  },

  projects: [
    // Auth setup: runs once, shares state with all tests
    { name: 'setup', testMatch: /.*\.setup\.ts/ },

    {
      name: 'chromium',
      use: { ...devices['Desktop Chrome'] },
      dependencies: ['setup'],
    },
    {
      name: 'firefox',
      use: { ...devices['Desktop Firefox'] },
      dependencies: ['setup'],
    },
    {
      name: 'mobile-chrome',
      use: { ...devices['Pixel 5'] },
      dependencies: ['setup'],
    },
  ],

  webServer: {
    command: 'pnpm dev',
    url: 'http://localhost:3000',
    reuseExistingServer: !process.env.CI,
    timeout: 30000,
  },
});

Page Object Pattern

// pages/login.page.ts
import { type Page, type Locator, expect } from '@playwright/test';

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

  constructor(page: Page) {
    this.page = page;
    this.emailInput = page.getByLabel('Email address');
    this.passwordInput = page.getByLabel('Password');
    this.submitButton = page.getByRole('button', { name: 'Sign in' });
    this.errorMessage = page.getByRole('alert');
    this.forgotPasswordLink = page.getByRole('link', { name: 'Forgot password?' });
  }

  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 expectError(message: string) {
    await expect(this.errorMessage).toContainText(message);
  }

  async expectRedirectToDashboard() {
    await expect(this.page).toHaveURL(/\/dashboard/);
  }
}
// pages/dashboard.page.ts
import { type Page, type Locator, expect } from '@playwright/test';

export class DashboardPage {
  readonly page: Page;
  readonly heading: Locator;
  readonly projectList: Locator;
  readonly createProjectButton: Locator;

  constructor(page: Page) {
    this.page = page;
    this.heading = page.getByRole('heading', { name: 'Dashboard' });
    this.projectList = page.getByRole('list', { name: 'Projects' });
    this.createProjectButton = page.getByRole('button', { name: 'New project' });
  }

  async expectLoaded() {
    await expect(this.heading).toBeVisible();
  }

  async getProjectCount() {
    return this.projectList.getByRole('listitem').count();
  }

  async createProject(name: string) {
    await this.createProjectButton.click();
    await this.page.getByLabel('Project name').fill(name);
    await this.page.getByRole('button', { name: 'Create' }).click();
  }
}

Test Generation from User Stories

Given a user story, generate tests following this pattern:

// tests/e2e/auth/login.spec.ts
import { test, expect } from '@playwright/test';
import { LoginPage } from '../../pages/login.page';
import { DashboardPage } from '../../pages/dashboard.page';

test.describe('User Login', () => {
  let loginPage: LoginPage;

  test.beforeEach(async ({ page }) => {
    loginPage = new LoginPage(page);
    await loginPage.goto();
  });

  test('successful login redirects to dashboard', async ({ page }) => {
    await loginPage.login('user@example.com', 'password123');
    const dashboard = new DashboardPage(page);
    await dashboard.expectLoaded();
  });

  test('shows error for invalid credentials', async () => {
    await loginPage.login('user@example.com', 'wrongpassword');
    await loginPage.expectError('Invalid email or password');
  });

  test('shows validation error for empty email', async () => {
    await loginPage.login('', 'password123');
    await loginPage.expectError('Email is required');
  });

  test('shows validation error for invalid email format', async () => {
    await loginPage.login('not-an-email', 'password123');
    await loginPage.expectError('Enter a valid email');
  });

  test('forgot password link navigates to reset page', async ({ page }) => {
    await loginPage.forgotPasswordLink.click();
    await expect(page).toHaveURL(/\/forgot-password/);
  });
});

Authentication Setup (Shared State)

// tests/e2e/auth.setup.ts
import { test as setup, expect } from '@playwright/test';

const authFile = 'playwright/.auth/user.json';

setup('authenticate as test user', async ({ page }) => {
  await page.goto('/login');
  await page.getByLabel('Email address').fill('test@example.com');
  await page.getByLabel('Password').fill('password123');
  await page.getByRole('button', { name: 'Sign in' }).click();

  // Wait for redirect to confirm login succeeded
  await expect(page).toHaveURL(/\/dashboard/);

  // Save authentication state for reuse
  await page.context().storageState({ path: authFile });
});

Flaky Test Diagnosis

Common Causes and Fixes

SymptomCauseFix
waitForTimeout(2000) in testTiming-dependentReplace with await expect(locator).toBeVisible()
Test passes locally, fails in CIRace conditionAdd web-first assertion before interaction
Element not found after navigationPage not loadedawait page.waitForURL('/expected-path')
Stale element referenceDOM re-renderedUse Playwright locators (auto-retry)
Different data between runsShared test stateIsolate with test.beforeEach setup
Flaky on slow CI runnersInsufficient timeoutIncrease expect timeout, not waitForTimeout

Diagnosis Commands

# Run with trace on every test (not just retries)
npx playwright test --trace on

# Run a specific flaky test 10 times
for i in $(seq 1 10); do npx playwright test tests/e2e/checkout.spec.ts; done

# Show test timeline
npx playwright test --trace on
npx playwright show-trace test-results/*/trace.zip

# Run in headed mode for visual debugging
npx playwright test --headed --retries 0

# Debug a specific test interactively
npx playwright test --debug tests/e2e/checkout.spec.ts

Cypress to Playwright Migration

CypressPlaywright
cy.visit('/path')await page.goto('/path')
cy.get('.selector')page.locator('.selector')
cy.contains('text')page.getByText('text')
cy.get('[data-testid="x"]')page.getByTestId('x')
cy.intercept('GET', '/api/*')await page.route('/api/*',...)
cy.wait('@alias')await page.waitForResponse('/api/*')
cy.should('be.visible')await expect(locator).toBeVisible()
cy.should('have.text', 'x')await expect(locator).toHaveText('x')
cy.fixture('data.json')JSON.parse(fs.readFileSync(...))
beforeEach(() => {cy.login()})Auth setup project + storageState

CI Integration

GitHub Actions

name: E2E Tests
on: [push, pull_request]

jobs:
  e2e:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: pnpm/action-setup@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 20
          cache: 'pnpm'
      - run: pnpm install --frozen-lockfile
      - run: pnpm exec playwright install --with-deps chromium

      - run: pnpm build  # build the app first
      - run: pnpm exec playwright test
        env:
          BASE_URL: http://localhost:3000

      - uses: actions/upload-artifact@v4
        if: failure()
        with:
          name: playwright-report
          path: playwright-report/
          retention-days: 7

Visual Regression Testing

// tests/e2e/visual/dashboard.spec.ts
import { test, expect } from '@playwright/test';

test('dashboard matches visual snapshot', async ({ page }) => {
  await page.goto('/dashboard');
  await page.waitForLoadState('networkidle');

  // Full page screenshot comparison
  await expect(page).toHaveScreenshot('dashboard.png', {
    maxDiffPixels: 50,  // allow small rendering differences
  });
});

test('project card component snapshot', async ({ page }) => {
  await page.goto('/dashboard');
  const card = page.getByTestId('project-card').first();

  await expect(card).toHaveScreenshot('project-card.png', {
    maxDiffPixelRatio: 0.01,
  });
});
# Generate/update baseline screenshots
npx playwright test --update-snapshots

# Run visual comparison
npx playwright test tests/e2e/visual/

Accessibility Testing

import { test, expect } from '@playwright/test';
import AxeBuilder from '@axe-core/playwright';

test('login page has no accessibility violations', async ({ page }) => {
  await page.goto('/login');

  const results = await new AxeBuilder({ page })
    .withTags(['wcag2a', 'wcag2aa', 'wcag21a', 'wcag21aa'])
    .analyze();

  expect(results.violations).toEqual([]);
});

test('dashboard meets WCAG AA standards', async ({ page }) => {
  await page.goto('/dashboard');

  const results = await new AxeBuilder({ page })
    .exclude('.third-party-widget')  // exclude elements you don't control
    .analyze();

  // Log violations for debugging
  for (const violation of results.violations) {
    console.log(`${violation.impact}: ${violation.description}`);
    for (const node of violation.nodes) {
      console.log(`  - ${node.html}`);
    }
  }

  expect(results.violations.filter(v => v.impact === 'critical')).toEqual([]);
});

Common Pitfalls

  • page.waitForTimeout(N) — the single most common cause of flaky tests; use web-first assertions
  • CSS selectors as primary strategy — breaks on every refactor; use role/label/text locators
  • Shared state between tests — one test's data pollutes another; isolate with proper setup/teardown
  • No trace configuration — debugging CI failures without traces wastes hours; enable on-first-retry
  • Testing third-party services — mock external APIs; only test your own application
  • Running all browsers in development — test Chromium locally, full matrix in CI only
  • No page objects — duplicate locators across tests create maintenance nightmares

Best Practices

  1. Page Object per page/component — centralize locators, expose user-intent methods
  2. Web-first assertions everywhereexpect(locator).toBeVisible() auto-retries, waitForTimeout does not
  3. Auth as a setup project — authenticate once, reuse storageState across all tests
  4. One behavior per test — keeps failures isolated and test names meaningful
  5. Run in CI with --retries 2 — but investigate any test that needs retries locally
  6. Trace + screenshot on failure — upload as CI artifacts for post-mortem debugging
  7. Visual regression for critical UI — catch unintended visual changes automatically
  8. Accessibility tests in the suite — WCAG compliance as a regression gate, not an afterthought

Troubleshooting

ProblemCauseSolution
locator.click() times outElement hidden behind overlay/modal or not yet renderedAdd await expect(locator).toBeVisible() before clicking; check for z-index overlays blocking the target
Visual snapshots fail on every CI runDifferent OS font rendering between local and CIGenerate baseline screenshots inside CI (Linux), not locally (macOS); use maxDiffPixelRatio: 0.02 for tolerance
Auth setup project runs but tests get 401storageState path mismatch or expired tokenVerify storageState path in playwright.config.ts matches the setup script; confirm tokens don't expire mid-suite
page.route() intercept never triggersRoute pattern doesn't match the actual request URL or glob syntax errorLog requests with page.on('request', r => console.log(r.url())) to verify the exact URL; use ** glob for subpaths
Tests pass individually but fail when run togetherShared mutable state or port collision between parallel workersEnsure test isolation via test.beforeEach setup; use unique test data per worker with test.info().parallelIndex
toHaveScreenshot() throws "missing baseline"Snapshot file not committed to version controlRun npx playwright test --update-snapshots and commit the generated files under the __screenshots__ directory
Accessibility audit returns false positivesAxe scanning third-party embedded widgets or iframesUse .exclude('.third-party-widget') or .include('#app-root') to scope the audit to your own markup

Success Criteria

  • Flaky test rate below 2% — measured over a rolling 7-day window across all CI runs; any test exceeding 5% flake rate is quarantined and fixed within 48 hours
  • E2E suite completes within 10 minutes — full cross-browser matrix (Chromium, Firefox, mobile) on CI with 4 parallel workers; alert if wall-clock time exceeds threshold
  • 100% of critical user journeys covered — login, checkout, onboarding, and core CRUD workflows each have dedicated spec files with happy-path and primary error-path tests
  • Zero waitForTimeout() calls in the codebase — enforced via ESLint rule or grep-based CI check; all waits use web-first assertions
  • Page Object coverage for every tested page — no raw locators in spec files; all element access goes through page object classes with user-intent method names
  • WCAG AA compliance gate passing — accessibility tests run on every PR; zero critical or serious violations allowed to merge
  • Visual regression baselines reviewed on every UI PR — screenshot diffs attached to PR as artifacts; baseline updates require explicit reviewer approval

Scope & Limitations

This skill covers:

  • End-to-end test authoring, organization, and maintenance with Playwright
  • Page Object Model architecture and locator strategy best practices
  • Flaky test diagnosis, CI integration, and trace-based debugging
  • Visual regression testing and WCAG accessibility auditing

This skill does NOT cover:

  • Unit testing or component testing in isolation (see engineering/testing-strategy for test pyramid guidance)
  • API contract testing or load/performance testing (see api-test-suite-builder for API-focused testing)
  • Test data management, database seeding, or factory patterns for test fixtures
  • Mobile native app testing (Appium, Detox); this skill targets web browsers only

Integration Points

SkillIntegrationData Flow
ci-cd-pipeline-builderE2E tests run as a pipeline stage after build and unit testsPipeline config triggers playwright test; artifacts (traces, screenshots) upload on failure
api-test-suite-builderAPI tests validate backend contracts; Playwright tests validate UI flows end-to-endAPI test results confirm endpoint stability before E2E suite runs against the same environment
pr-review-expertPR reviews check for test coverage on UI changes and flag missing E2E specsReview checklist references Playwright Pro golden rules; flags waitForTimeout or raw CSS selectors
performance-profilerPerformance budgets complement E2E tests to catch regressionsProfiler identifies slow pages; Playwright tests add networkidle waits or performance assertions for flagged routes
observability-designerTest failures feed into observability dashboards for flake trackingCI test results export JSON reports; observability pipelines ingest pass/fail/flake metrics over time
release-managerE2E suite is a release gate; green suite required before deployment proceedsRelease workflow calls Playwright CI job; blocks release tag creation on any test failure

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

35.34%
按下载量换算222

Claude

28.92%
按下载量换算181

Cursor

18.91%
按下载量换算119

Gemini CLI

8.93%
按下载量换算56

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

操作浏览器

该 Skill 可能涉及浏览器控制能力,使用时可能读取或操作网页内容,需要在受控环境中确认权限边界。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills