Token导航 LogoToken导航

Agent Skill · 研究检索

playwright-automation(Playwright 自动化)

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

playwright-automation 是研究检索类 Agent Skill,可用宿主为 Codex、Claude、Cursor、Gemini CLI,通过GitHub 仓库获取,权限为操作浏览器;许可证信息还不明确,第三方扫描已通过,按安装量在研究检索类的 73,675 个 Skill 里排第 52,399。

总安装 561周安装 17GitHub Stars 4下载 140核验 2026-05-01

安装说明

本站只整理中文说明,不托管安装包,也不代用户安装。
GitHub
许可证
unknown

安装方式

通过对话安装

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

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

命令行安装

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

skills.shnpx skills
npx skills add https://github.com/petrkindlmann/qa-skills --skill playwright-automation

这个 Skill 是做什么的

研究检索类 Skill 主要解决「找资料、核对事实、把来源整理清楚」的问题,通常会让助手先检索再总结。

用于辅助测试设计与自动化用例整理,适合浏览器端回归验证场景。可帮助编写单元测试、端到端测试或根据失败日志定位问题。通过 GitHub 安装,支持 Codex、Claude、Cursor、Gemini CLI 等宿主环境。需确认项目测试框架与运行命令,避免为通过测试而破坏真实逻辑;涉及浏览器时应区分模拟与生产环境。

playwright-automation 属于研究检索类 Skill,可作为该场景下的辅助能力补充。

来源仓库内路径:skills/playwright-automation

上手步骤

4 步
  1. 1

    确认自己的宿主工具

    公开资料标注支持 Codex、Claude、Cursor、Gemini CLI;先确认自己用的是其中之一,再按对应工具的 Skills 目录放置。

  2. 2

    拿到安装命令

    可以直接复制的命令是 npx skills add https://github.com/petrkindlmann/qa-skills --skill playwright-aut…;命令里的占位符换成自己的路径或密钥再执行。

  3. 3

    安装后重启宿主

    命令执行完要完全退出宿主工具再打开,让新装的 Skill 被重新扫描到,否则列表里可能看不到。

  4. 4

    按最小权限试用

    它需要操作浏览器,先在测试目录或测试账号里跑,确认没问题再放到正式项目。

常见问题

6 条

playwright-automation 怎么安装?

在终端执行 npx skills add https://github.com/petrkindlmann/qa-skills --skill playwright-automation。装完完全退出宿主工具再打开,让它重新扫描本地 Skill。

playwright-automation 支持哪些 AI 工具?

公开资料标注支持 Codex、Claude、Cursor、Gemini CLI。其他工具只要能读取本地 Skill 目录,一般也能手动放进去,但要自己确认触发方式是否一致。

playwright-automation 需要什么权限?

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

playwright-automation 是免费的吗?

公开资料没有标注明确许可证,收费和商用限制都无法确认。正式使用前请到来源仓库核对授权说明。

playwright-automation 用的人多吗?

公开数据是累计安装 561 次,近一周安装 17 次,下载 140 次,GitHub 4 星。这些数字来自第三方目录统计,只能当作热度参考,不代表质量或安全性。

playwright-automation 安全吗?

第三方扫描结果为通过,但这只覆盖已知的静态检查项,不能替代自己读一遍源码和安装命令。

值得选的地方和要先想清楚的地方

值得选的地方

  • 同时适配 4 种工具,换客户端不用重新找替代品。
  • 第三方扫描已通过,常见的高风险行为没有命中。

先想清楚的地方

  • 许可证没有明确标注,能不能商用、能不能再分发都不确定。
  • 第三方目录整理,版本更新和行为细节以来源仓库为准。

适不适合你

更适合

  • 已经在用 Codex,想直接扩展它能力的人。
  • 需要处理研究检索类任务、又不想每次都手写提示词的人。

不太适合

  • 需要明确授权才能用到公司项目里的场景。
  • 需要厂商级技术支持和 SLA 的生产系统。

研究检索类 Skill 对比

6 个同类
Skill总安装GitHub 星权限许可证扫描
find-skills

寻找技能 · Codex、Claude

31,199,81316,486操作浏览器MIT有提醒
self-improving-agent

自我改进 Agent · OpenClaw

16,464,0023,396接触敏感数据MIT-0通过
soultrace

灵魂追踪 · Codex、Claude

7,588,94412需要联网未明确有提醒
self-improving

自我完善 · OpenClaw

6,829,2841,046需要联网MIT-0通过
microsoft-foundry

微软代工厂 · Codex、Claude

6,614,144764调用外部服务未明确有提醒
playwright-automation

Playwright 自动化 · 本页

5614操作浏览器未明确通过

按安装量取同分类前几名;数字来自第三方目录统计,只作热度参考,不代表质量结论。

SKILL.md 原文

Discovery Questions

Before generating any code, ask:

  1. TypeScript or JavaScript? TypeScript is strongly recommended. It catches locator and assertion mistakes at compile time, and every example in this skill assumes TypeScript.
  2. Which browsers? Chromium for local dev. Add Firefox and WebKit in CI. Mobile viewports are separate Playwright projects, not separate test files.
  3. Existing suite or fresh start? If migrating from Cypress or Selenium, start by rewriting the flakiest tests first. Do not attempt a big-bang rewrite.
  4. Single site or multi-site? Multi-site architectures need shared fixtures and per-site config objects. See references/multi-site-architecture.md.

Core Principles

  1. User-facing locators first. getByRole > getByLabel > getByTestId > CSS (last resort). Locators must reflect what the user sees, not how the DOM is structured. See references/selector-strategies.md.
  2. Auto-waiting -- NEVER use waitForTimeout. Every Playwright action and web-first assertion auto-waits. If you think you need a timeout, you need a better locator or assertion.
  3. Test isolation. Each test gets a fresh BrowserContext. Tests must never depend on other tests' state or execution order.
  4. Parallel by default, serial only when necessary. Use fullyParallel: true in config. Reserve test.describe.serial for flows that genuinely cannot be isolated (rare).
  5. Fixtures for setup, not hooks. Fixtures compose, provide type safety, and automatically tear down. Prefer them over beforeEach/afterEach for anything non-trivial. See references/fixtures-and-projects.md.
Calibrate to your team maturity (set team_maturity in .agents/qa-project-context.md): - startup — Chromium only, 5–10 critical path tests, basic CI run on PR. Skip sharding and visual testing until the suite is stable. - growing — Multi-browser (Chromium + Firefox), POM structure, parallel execution, CI with sharding, HTML report artifacts. - established — Full browser matrix, auth fixtures, API mocking layer, visual regression baseline, trace-on-failure, flakiness tracking.

Common AI Agent Mistakes

Do not generate code that matches any of these patterns.

1. Never use waitForTimeout() as synchronization

Why it is wrong: Arbitrary waits are slow on fast machines and flaky on slow ones. They hide the real condition you are waiting for.

// BAD
await page.waitForTimeout(2000);
await page.click('#submit');

// GOOD
await page.getByRole('button', { name: 'Submit' }).click(); // auto-waits

2. Never default to CSS/XPath when getByRole/getByLabel/getByTestId work

Why it is wrong: CSS selectors encode DOM structure, break on refactors, and do not communicate test intent.

// BAD
await page.locator('.btn-primary.submit-form').click();

// GOOD
await page.getByRole('button', { name: 'Submit' }).click();

See the full decision tree in references/selector-strategies.md.

3. Never use discouraged page.* APIs when locator APIs exist

Why it is wrong: page.click(), page.fill(), page.type() are legacy convenience methods that bypass the locator auto-waiting pipeline and cannot be chained or filtered.

// BAD
await page.click('#email');
await page.fill('#email', 'user@example.com');

// GOOD
await page.getByLabel('Email').fill('user@example.com');

4. Never use force: true without documented justification

Why it is wrong: force: true skips actionability checks (visible, enabled, stable, receives events). Either the wrong element is targeted, or there is an accessibility bug.

// BAD
await page.getByRole('button', { name: 'Save' }).click({ force: true });

// GOOD -- dismiss any overlay first
await page.getByRole('button', { name: 'Dismiss' }).click();
await page.getByRole('button', { name: 'Save' }).click();

5. Never share mutable state between tests

Why it is wrong: Tests run in parallel. Shared module-level variables create race conditions and order-dependent failures. Use fixtures instead. See references/anti-patterns.md.

6. Never put login boilerplate in every test -- use storageState

Why it is wrong: UI login for every test is slow and fragile. storageState logs in once and replays cookies/localStorage for all tests. See references/auth-patterns.md.

7. Never use locator.all() on dynamic collections without a stability check

Why it is wrong: locator.all() returns a snapshot. If the DOM is still updating, you get a partial or empty array. It does not auto-retry.

// BAD
const items = await page.getByRole('listitem').all();
expect(items.length).toBe(5); // may be 0 if DOM is still rendering

// GOOD
await expect(page.getByRole('listitem')).toHaveCount(5);
const items = await page.getByRole('listitem').all(); // then iterate if needed

8. Never assert with allTextContents() when toHaveText() gives retryability

Why it is wrong: allTextContents() is a snapshot that does not retry. toHaveText() retries until the condition is met or timeout expires.

// BAD
const texts = await page.getByRole('listitem').allTextContents();
expect(texts).toEqual(['Apple', 'Banana', 'Cherry']);

// GOOD
await expect(page.getByRole('listitem')).toHaveText(['Apple', 'Banana', 'Cherry']);

9. Never test external dependencies you do not control

Why it is wrong: Third-party services have their own uptime, rate limits, and UI changes. Tests that hit real external services are flaky by definition.

// BAD -- hitting real Stripe checkout
await page.goto('https://checkout.stripe.com/...');

// GOOD -- mock the external integration
await page.route('**/api/create-checkout-session', async (route) => {
  await route.fulfill({ json: { sessionId: 'mock_session', url: '/success' } });
});

10. Never leave test.only in committed code

Why it is wrong: A single test.only silently skips every other test in the suite. In CI, you run one test and think everything passes.

export default defineConfig({ forbidOnly: !!process.env.CI });

Project Structure

project-root/
├── playwright.config.ts
├── e2e/
│   ├── fixtures/              # base.fixture.ts, auth.fixture.ts, data.fixture.ts
│   ├── pages/                 # Page objects organized by feature
│   │   ├── base.page.ts
│   │   ├── dashboard.page.ts
│   │   └── components/        # Reusable component objects
│   │       ├── data-table.component.ts
│   │       └── modal.component.ts
│   ├── tests/                 # Test files organized by feature
│   │   ├── auth/
│   │   ├── dashboard/
│   │   └── settings/
│   ├── helpers/               # test-data.ts, api-client.ts
│   └── global-setup.ts
├── .auth/                     # Git-ignored storageState files
└── test-results/              # Git-ignored artifacts

playwright.config.ts

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

const isCI = !!process.env.CI;
const baseURL = process.env.BASE_URL ?? 'http://localhost:3000';

export default defineConfig({
  testDir: './e2e/tests',
  fullyParallel: true,
  forbidOnly: isCI,
  retries: isCI ? 2 : 0,
  workers: isCI ? '50%' : undefined,
  reporter: isCI
    ? [['html', { open: 'never' }], ['github'], ['json', { outputFile: 'test-results/results.json' }]]
    : [['html', { open: 'on-failure' }]],
  use: {
    baseURL,
    trace: isCI ? 'on-first-retry' : 'retain-on-failure',
    screenshot: 'only-on-failure',
    video: isCI ? 'on-first-retry' : 'off',
    actionTimeout: 15_000,
    navigationTimeout: 30_000,
  },
  projects: [
    { name: 'setup', testMatch: /global-setup\.ts/, teardown: 'teardown' },
    { name: 'teardown', testMatch: /global-teardown\.ts/ },
    { name: 'chromium', use: { ...devices['Desktop Chrome'], storageState: '.auth/user.json' }, dependencies: ['setup'] },
    { name: 'firefox', use: { ...devices['Desktop Firefox'], storageState: '.auth/user.json' }, dependencies: ['setup'] },
    { name: 'webkit', use: { ...devices['Desktop Safari'], storageState: '.auth/user.json' }, dependencies: ['setup'] },
  ],
  webServer: isCI ? undefined : {
    command: 'npm run dev', url: baseURL, reuseExistingServer: true, timeout: 120_000,
  },
});

Global Setup

import { test as setup, expect } from '@playwright/test';

setup('authenticate as default user', async ({ page }) => {
  await page.goto('/login');
  await page.getByLabel('Email').fill(process.env.TEST_USER_EMAIL!);
  await page.getByLabel('Password').fill(process.env.TEST_USER_PASSWORD!);
  await page.getByRole('button', { name: 'Sign in' }).click();
  await expect(page).toHaveURL(/.*dashboard/);
  await page.context().storageState({ path: '.auth/user.json' });
});

Page Object Model

Base Page

import { type Page, type Locator, expect } from '@playwright/test';

export abstract class BasePage {
  constructor(protected readonly page: Page) {}
  abstract readonly path: string;

  async goto(): Promise<void> {
    await this.page.goto(this.path);
    await this.waitForReady();
  }

  async waitForReady(): Promise<void> {
    await this.page.waitForLoadState('domcontentloaded');
  }
}

Component Objects

Component objects represent reusable UI fragments (modals, data tables, nav bars). They take a root Locator, not a Page.

export class DataTable {
  readonly rows: Locator;
  constructor(private readonly root: Locator) {
    this.rows = root.getByRole('row');
  }
  getRowByText(text: string | RegExp): Locator {
    return this.rows.filter({ hasText: text });
  }
}

Fixture-Based Injection

Inject page objects via fixtures, not constructors in test files.

export const test = base.extend<{ dashboardPage: DashboardPage }>({
  dashboardPage: async ({ page }, use) => { await use(new DashboardPage(page)); },
});
export { expect } from '@playwright/test';

Composition Over Inheritance

Compose component objects rather than inherit from deep class hierarchies.

export class UsersPage extends BasePage {
  readonly path = '/admin/users';
  readonly table: DataTable;
  constructor(page: Page) {
    super(page);
    this.table = new DataTable(page.getByRole('table', { name: 'Users' }));
  }
}

Test Patterns

Authentication (storageState reuse)

Global setup logs in once and saves storageState. All test projects load it via config. For multi-role auth (admin/user/guest), see references/auth-patterns.md.

Form Interactions with test.step

Wrap logical action groups in test.step() for better trace viewer output.

test('submits a multi-step form', async ({ page }) => {
  await page.goto('/onboarding');
  await test.step('fill personal info', async () => {
    await page.getByLabel('First name').fill('Jane');
    await page.getByRole('button', { name: 'Next' }).click();
  });
  await test.step('submit', async () => {
    await page.getByRole('button', { name: 'Complete setup' }).click();
  });
  await expect(page).toHaveURL('/dashboard');
});

API Mocking

// Mock a response
await page.route('**/api/products*', async (route) => {
  await route.fulfill({ json: { items: [{ id: '1', name: 'Widget', price: 29.99 }] } });
});

// Modify a real response
await page.route('**/api/feature-flags', async (route) => {
  const response = await route.fetch();
  const body = await response.json();
  body.flags['new-checkout'] = true;
  await route.fulfill({ response, json: body });
});

// Simulate errors
await page.route('**/api/products*', (route) => route.fulfill({ status: 500 }));

// WebSocket (v1.49+)
await page.routeWebSocket('**/ws/notifications', (ws) => {
  ws.onMessage((msg) => { ws.send(JSON.stringify({ type: 'alert', title: 'Deployed' })); });
});

See references/network-and-mocking.md for HAR replay, conditional routing, and full patterns.

Tags and Annotations

test('checkout @smoke', async ({ page }) => { /* npx playwright test --grep @smoke */ });
test.slow();                                    // Triples timeout
test.skip(({ browserName }) => browserName === 'webkit', 'WebKit bug');
test.fixme('known issue tracked in JIRA-1234', async ({ page }) => { /* ... */ });

Assertions

Web-First Assertions (auto-retry — always prefer these)

await expect(page.getByRole('alert')).toBeVisible();
await expect(page.getByRole('heading')).toHaveText('Dashboard');
await expect(page).toHaveURL('/dashboard');
await expect(page.getByRole('button', { name: 'Save' })).toBeEnabled();
await expect(page.getByRole('listitem')).toHaveCount(5);
await expect(page.getByRole('listitem')).toHaveText(['Apple', 'Banana', 'Cherry']);

Soft Assertions

Collect all failures instead of stopping at the first; all are reported at the end.

await expect.soft(page.getByLabel('Name')).toHaveValue('Jane Doe');
await expect.soft(page.getByLabel('Email')).toHaveValue('jane@example.com');

ARIA Snapshots

Verify accessibility tree structure; catches semantic regressions.

await expect(page.getByRole('navigation', { name: 'Main' })).toMatchAriaSnapshot(`
  - navigation "Main":
    - link "Home"
    - link "Products"
`);

New Features (2025-2026)

Agents should be aware of these recent Playwright additions:

VersionFeatureWhat it does
v1.45Clock APIpage.clock.install() / page.clock.fastForward() -- control time without monkey-patching Date
v1.45--fail-on-flaky-testsCI flag that fails the run if any test required a retry to pass
v1.46--only-changedRun only tests affected by changed files (git-diff-aware)
v1.46Component testing router fixtureMock Next.js/SvelteKit/etc. router in component tests
v1.46ARIA snapshotstoMatchAriaSnapshot() for accessibility tree assertions
v1.49routeWebSocketFirst-class WebSocket interception (replaces CDP hacks)
v1.51expect.configurePer-block timeout/soft configuration
v1.57Speedboard in HTML reporterPerformance timeline visualization in the built-in report
v1.57webServer.wait regexWait for a specific stdout pattern instead of just a URL

Parallel Execution & CI

Worker Configuration

export default defineConfig({
  fullyParallel: true,
  workers: process.env.CI ? '50%' : undefined,
});

Sharding Across CI Nodes

strategy:
  fail-fast: false
  matrix:
    shard: [1, 2, 3, 4]
steps:
  - run: npx playwright test --shard=${{ matrix.shard }}/4

Multiple Reporters

reporter: [
  ['html', { open: 'never' }],
  ['json', { outputFile: 'results.json' }],
  ['github'],
  ['junit', { outputFile: 'junit.xml' }],
],

See references/ci-recipes.md for complete GitHub Actions workflows, artifact upload patterns, and sharding with merge.


Debugging

  • Trace viewer: npx playwright show-trace test-results/my-test/trace.zip -- timeline of actions, network, DOM snapshots, console logs.
  • UI mode: npx playwright test --ui -- live browser, step-by-step, time-travel debugging.
  • Debug flag: npx playwright test my-test.spec.ts --debug -- headed browser, pauses at each action.
  • VS Code extension: ms-playwright.playwright -- run/debug from gutter icons, pick locators, watch mode.
  • page.pause(): Opens the Playwright Inspector mid-test. For local debugging only. Never commit to CI code paths.

See references/debugging-and-triage.md for flaky test triage workflows and artifact analysis.


Done When

  • playwright.config.ts exists with projects defined for at least one target browser (Chromium minimum; Firefox and WebKit added for CI)
  • Page Object Model files live in the designated directory (e2e/pages/ or equivalent) with component objects composed via root Locator
  • All locators in test code use getByRole, getByLabel, or getByTestId — no raw CSS selectors or XPath
  • CI workflow runs Playwright with --shard across matrix jobs and uploads the HTML report as an artifact on failure
  • No waitForTimeout calls exist anywhere in test code (grep or forbidOnly-style lint catches any regressions)

Related Skills and References

Reference Files (in references/)

FilePurpose
anti-patterns.mdBAD vs GOOD code pairs for every common mistake
fixtures-and-projects.mdAuth fixtures, data fixtures, multi-env projects, composition
selector-strategies.mdLocator decision tree, getByRole examples, stability scoring
auth-patterns.mdstorageState, multi-role, token seeding, session expiry
multi-site-architecture.mdShared fixtures, per-site config, monorepo patterns
network-and-mocking.mdpage.route, route.fetch, HAR, WebSocket, conditional routing
debugging-and-triage.mdTrace viewer, flaky test triage, retries, artifacts
ci-recipes.mdReporters, sharding, --only-changed, browser caching, artifacts

Related Skills

  • visual-testing -- Screenshot comparison, threshold management, baseline workflows.
  • ci-cd-integration -- Pipeline configuration, parallelization, reporting beyond Playwright.
  • api-testing -- Backend API validation, contract testing, request/response schemas.
  • test-reliability -- Flaky test patterns, retry strategies, test stability metrics.
  • accessibility-testing -- WCAG compliance, axe-core integration, ARIA assertions.

平台分布

Codex

37.96%
按下载量换算53

Claude

30.25%
按下载量换算42

Cursor

17.16%
按下载量换算24

Gemini CLI

9.02%
按下载量换算13

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

操作浏览器

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

安装前确认

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

继续浏览同类 Skills