AGENT SKILL

playwright

Robust E2E browser testing with Playwright. Use when writing browser-driven tests — leverage auto-waiting (no `waitForTimeout`), prefer user-visible locators (`getByRole`, `getByText`, `getByLabel`) over CSS/XPath, reuse `storageState` for auth, and enable trace-on-first-retry for CI debugging. Also carries the `data-testid` contract a UI change states in its acceptance criteria.

适用职业律师与法务
使用场景测试与质量
License 许可
MIT
所属仓库
dsj1984/mandrel
最近更新
2026-11-13
Stars
★ 7
Forks
1

01 前言 Front Matter

name
playwright
vendor
playwright
description
Robust E2E browser testing with Playwright. Use when writing browser-driven tests — leverage auto-waiting (no `waitForTimeout`), prefer user-visible locators (`getByRole`, `getByText`, `getByLabel`) over CSS/XPath, reuse `storageState` for auth, and enable trace-on-first-retry for CI debugging. Also carries the `data-testid` contract a UI change states in its acceptance criteria.

03 SKILL.md 正文

Skill: Playwright

Policy Capsule

  • Rely on Playwright's auto-waiting; never use waitForTimeout or hardcoded sleeps to paper over flakes.
  • Prefer user-visible locators (getByRole, getByText, getByLabel) over CSS selectors or XPath.
  • Reuse storageState to seed authenticated scenarios; do not repeat login flows in every test.
  • Use toHaveScreenshot() for critical visual surfaces; treat snapshot diffs as intentional reviews, not auto-refreshes.
  • Write tests independent of one another so they run in parallel; clean up shared state in fixtures, not afterwards.
  • Enable trace: 'on-first-retry' (or 'retain-on-failure') so CI failures are debuggable in the Trace Viewer.
  • Use a unique data set per test run, or tear down state explicitly, to prevent cross-test contamination.
  • Never let Playwright own the lifetime of a dev server it did not start: boot the server out-of-band, point the suite at the running origin, and set reuseExistingServer so webServer only probes readiness.

The testid contract

A data-testid is a selector two artifacts share: the component that renders it and the spec that queries it. Renaming one without the other is a silent break — the suite still compiles, and the failure arrives as a missing element at run time, in CI, attributed to whichever change happened to land next.

So a change touching UI (*.tsx, *.astro, *.svelte, *.vue, a components folder) states which side of that contract it is on, in its own acceptance criteria, as one of:

  • data-testid invariance: <the testids that MUST be preserved> — the change reshapes markup and renames nothing, and the list says what the reshape may not touch.
  • data-testid changes: <old> -> <new>, with the matching tests/e2e/*.spec.ts selector updated — the rename is deliberate, and the spec file that queries it is edited in the same change (or in one ordered ahead of it, when the work is split).

Renaming a testid without the matching spec edit is forbidden either way. When a change deliberately renames nothing, say so in its negative-scope prose too: a preserved set stated only once reads as an omission the next author is free to revise.

Running a webServer-backed suite outside CI

Playwright's webServer block watches the process it spawned. That assumption holds for a dev server that stays in the foreground, and breaks for any manager that daemonizes one — the foreground process exits 0 while the server keeps serving, Playwright reads the exit as a crash, and the run aborts before a single test executes:

Process from config.webServer exited early

Read that line as a lifetime-ownership mismatch, not a flake. It reproduces on every invocation, clean tree or not, and no amount of retrying, tree-cleaning or timeout-raising changes it. Agent sandboxes and IDE harnesses commonly manage dev servers this way (Dev server already running at … (pid N)), so an agent meets this far more often than a developer does.

Attach, don't boot

Invert the ownership instead of fighting it — the manager owns the process, Playwright owns only the probe:

  1. Boot the server out-of-band through whatever manages it, and confirm it is serving. Its lifetime is now the manager's concern, not the runner's.
  2. Point the suite at the already-running origin — set the config's baseURL (or the webServer.url the block probes) to that origin, via the project's own environment seam rather than an edit to committed config.
  3. Set reuseExistingServer: true so Playwright probes the URL, finds it live, and never spawns or supervises a process of its own.

This is the same convention the QA harness already encodes as qa.environments[].baseUrl: attach to a running origin, never boot one. A suite run this way exercises identical browser behavior — only the process supervision differs.

When no attachable origin exists

Some apps genuinely cannot be reached this way — the server is unreachable from the sandbox, or the suite depends on a build step the sandbox cannot run. Do not burn a timebox rediscovering that. Record the observed signature, state which of the three steps above failed, and escalate on the first encounter: that evidence is exactly what the unreproducible-tier verdict in ci-remediation.md requires, and it is the only verdict that lets an unrunnable tier route somewhere other than a dead end.

04 同仓库更多 Skills

dsj1984
dsj1984/mandrel

no-capsule-skill

Fixture without a Policy Capsule section.

Skill与智能体开发
★ 7
dsj1984
dsj1984/mandrel

qa-harness

Conventions for agent-driven QA driving — the one driving-conventions reference behind both `/qa-run` (the known-scenario sweep through a real browser) and `/qa-explore` (agent-led exploratory driving). Use when instrumenting a live surface — covers navigation-first execution, per-surface console and network capture, design-token visual checks, the `F#` finding shape, per-environment resolution, and static driving as the documented interim. The run procedures live in `.agents/workflows/qa-run.md` and `.agents/workflows/qa-explore.md`; this skill is the conventions reference they lean on.

视觉设计Skill与智能体开发
★ 7
dsj1984
dsj1984/mandrel

playwright-bdd

Wires Gherkin `.feature` files to Playwright via the `playwright-bdd` library. Use when running BDD scenarios on a Playwright runtime — pairs with the `gherkin-authoring` skill (scenario prose) and the `playwright` skill (browser conventions). Drives execution by tag expression with trace-first debugging and Playwright-native sharding.

测试与质量
★ 7
dsj1984
dsj1984/mandrel

gherkin-authoring

Authors `.feature` files that stay business-readable, translate cleanly from PRD acceptance criteria, and reuse a shared step-definition library. Use when writing or editing scenarios — the SSOT enforcement rules live in `.agents/rules/gherkin-standards.md`; this skill shows authors how to apply them.

★ 7
dsj1984
dsj1984/mandrel

security-and-hardening

Hardens code against vulnerabilities. Use when handling user input, authentication, data storage, or external integrations. The non-negotiable security MUSTs live in `.agents/rules/security-baseline.md`; this skill shows how to apply them, with the project's surfacing and validation-response process.

★ 7
dsj1984
dsj1984/mandrel

idea-refinement

Refines ideas iteratively. Refine ideas through structured divergent and convergent thinking. Use "idea-refine" or "ideate" to trigger.

★ 7