用途:指导在 TypeScript 中编写生产级 Playwright 测试,覆盖定位器策略、自动等待、测试隔离、fixtures、并行与 CI、调试与反模式。
主要能力:以面向用户的定位器优先(getByRole > getByLabel > getByTestId > CSS);禁止 waitForTimeout,依赖自动等待与 web-first 断言;每个测试使用独立 BrowserContext;默认 fullyParallel,仅在无法隔离时用 test.describe.serial;用 fixtures 而非 beforeEach/afterEach 做 setup,并按团队成熟度(startup/growing/established)选浏览器矩阵、分片与可视化基线。
必要用法:先检查 .agents/qa-project-context.md,缺失信息再提问(语言、浏览器、已有套件、单/多站点)。配置示例使用 defineConfig,设置 testDir、fullyParallel、forbidOnly、retries、workers、reporter、trace、截图与项目矩阵(chromium/firefox/webkit),并可用 setup 项目写入 storageState。命令:npx playwright test --shard=${{ matrix.shard }}/4、npx playwright merge-reports --reporter=html ./all-blob-reports、npx playwright show-trace、npx playwright test --ui、npx playwright test my-test.spec.ts --debug、npx playwright migrate、npx playwright init-agents --loop=claude|vscode|opencode。POM 方法只返回状态,断言写在测试中。
适用场景:从 Cypress/Selenium 迁移、多浏览器/多站点回归、表单与 API 模拟、可访问性与可视化回归、CI 分片与 trace 排查。
限制:需 Node 与 Playwright 环境,需配置 BASE_URL 等环境变量与凭据;版本行为随发布变化(如 v1.57 Chrome for Testing 默认、v1.59 Screencast、v1.60 locator.drop 与 tracing.startHar);反模式包括 God Page Object、POM 内断言、断言实现细节、fixtures 依赖顺序、滥用 data-testid。其他细节暂未提供。