playwright
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePlaywright
Playwright
When to Use This Skill
何时使用此Skill
Use this skill when the user:
当用户出现以下情况时使用本Skill:
Mentions / keywords
提及的关键词
- Mentions “Playwright”, “@playwright/test”, “playwright.config.ts”, “trace viewer”, or “PWDEBUG”
- References /
*.spec.tsfiles that import*.test.ts@playwright/test
- 提及“Playwright”、“@playwright/test”、“playwright.config.ts”、“trace viewer”或“PWDEBUG”
- 引用了导入的
@playwright/test/*.spec.ts文件*.test.ts
Context
场景
- Is trying to add or maintain E2E/smoke coverage for a web app
- Is trying to debug flaky UI tests (selectors, timing, waits)
- Needs one-off automation (screenshots, console logs, quick flow checks)
- 尝试为Web应用添加或维护E2E/冒烟测试覆盖
- 尝试调试不稳定的UI测试(选择器、时序、等待)
- 需要临时自动化操作(截图、控制台日志、快速流程检查)
Purpose
目的
- Route Playwright work into the right workflow (suite vs. one-off script vs. debugging)
- Standardize patterns that prevent flaky tests (locators, assertions, waits)
- Keep artifacts in for predictable cleanup
./tmp/
- 将Playwright相关工作引导至正确的工作流(测试套件 vs 临时脚本 vs 调试)
- 标准化避免测试不稳定的模式(定位器、断言、等待)
- 将工件存储在目录下,以便可预测地清理
./tmp/
Quick routing
快速导航
- Writing/maintaining suites → See
@playwright/testreferences/e2e-with-playwright-test.md - Auth once, reuse state () → See
storageStatereferences/auth-and-storage-state.md - CI hardening + config knobs → See
references/ci-and-config.md - Locators, assertions, POM, fixtures → See
references/patterns.md - Fixtures (worker-scoped, auto fixtures) → See
references/fixtures.md - Mocking APIs / controlling network → See
references/api-mocking.md - Visual testing () → See
toHaveScreenshotreferences/visual-testing.md - Link checking / dead link detection → See
references/link-checking.md - Flaky tests / trace viewer / retries → See
references/debugging.md - One-off automation (screenshots/logs/check flows) → See
references/ad-hoc-automation.md
- 编写/维护测试套件 → 查看
@playwright/testreferences/e2e-with-playwright-test.md - 一次性认证,复用状态() → 查看
storageStatereferences/auth-and-storage-state.md - CI加固 + 配置项 → 查看
references/ci-and-config.md - 定位器、断言、POM、fixtures → 查看
references/patterns.md - Fixtures(工作进程级、自动fixtures) → 查看
references/fixtures.md - Mock API / 控制网络 → 查看
references/api-mocking.md - 视觉测试() → 查看
toHaveScreenshotreferences/visual-testing.md - 链接检查 / 死链检测 → 查看
references/link-checking.md - 不稳定测试 / trace viewer / 重试 → 查看
references/debugging.md - 临时自动化操作(截图/日志/流程检查) → 查看
references/ad-hoc-automation.md
Non-negotiables
硬性要求
- Prefer /
getByRoleover CSS/XPath; addgetByLabelonly when needed.data-testid - Use web-first assertions () instead of boolean checks.
await expect(locator).toBeVisible() - Never add to “fix” flake; if you use it temporarily while debugging, remove it before calling the work “done”.
waitForTimeout() - Don’t default to everywhere; use it intentionally (SPAs / known background activity can make it misleading).
networkidle - For CLI agent runs, use minimal reporters to avoid log spam; store artifacts under .
./tmp/playwright/ - Keep tests independent; avoid cross-test shared state.
- 优先使用/
getByRole而非CSS/XPath;仅在必要时添加getByLabel。data-testid - 使用Web优先断言()替代布尔值检查。
await expect(locator).toBeVisible() - 切勿添加来“修复”测试不稳定问题;如果在调试时临时使用,需在完成工作前移除。
waitForTimeout() - 不要在所有场景下默认使用;仅在必要时使用(单页应用/已知的后台活动可能导致其结果不准确)。
networkidle - 对于CLI agent运行,使用极简报告器以避免日志冗余;将工件存储在目录下。
./tmp/playwright/ - 保持测试独立性;避免测试间共享状态。
Verification
验证方式
- E2E suite changes: run (or
npx playwright test --reporter=line) and confirm failures reproduce.--reporter=dot - Flake fixes: run the previously failing test at least 5 times (ex: ) before calling it fixed.
--repeat-each 5 - CI-sensitive changes: run the suite in “CI-like” settings (ex: ) and confirm it still behaves.
CI=1 npx playwright test --reporter=line
- E2E测试套件变更:运行(或
npx playwright test --reporter=line)并确认失败场景可复现。--reporter=dot - 不稳定测试修复:至少运行之前失败的测试5次(例如:)后,再确认问题已修复。
--repeat-each 5 - 对CI敏感的变更:在“类CI”环境下运行测试套件(例如:)并确认行为符合预期。
CI=1 npx playwright test --reporter=line
Provenance
来源
- Consolidated from upstream installed skills: ,
playwright-best-practices,playwright-testing,playwright-expert,playwright-skillwebapp-testing
- 整合自上游已安装的Skill:,
playwright-best-practices,playwright-testing,playwright-expert,playwright-skillwebapp-testing