Playwright 端到端测试
webapp-testing
面向 Web 应用的 Playwright 端到端测试指南,包含实用模式和设置步骤。在创建或改进基于浏览器的 E2E 覆盖率、测试稳定性和 CI 执行时使用。不要用于:React 组件测试(使用 ui-testing)、Canvas 游戏交互(使用 browser-canvas-testing)、TDD 工作流(使用 test-driven-development)、失败调试(使用 systematic-debugging)或随机化属性测试(使用 property-based-testing)。
- License 许可
- MIT
- 最近更新
- 2026-08-16
- Stars
- ★ 3
- Forks
- 0
01 前言 Front Matter
- name
- webapp-testing
- description
- Playwright end-to-end testing guidance for web apps, with practical patterns and setup steps. Use when creating or improving browser-based E2E coverage, test stability, and CI execution. DO NOT USE FOR: React component tests (use ui-testing), canvas game interaction (use browser-canvas-testing), TDD workflow (use test-driven-development), debugging failures (use systematic-debugging), or randomized property tests (use property-based-testing).
02 资源文件 2
- 参考文档patterns.md2.5 KB
- 参考文档playwright-setup.md2.5 KB
03 SKILL.md 正文
Web App Testing Skill
Overview
This skill provides practical Playwright E2E guidance for reliable web app testing across local and CI environments.
[CUSTOMIZE] Replace sample URLs, auth flows, selectors, and command snippets with your project-specific values.
<intake>
What do you need help with?
Choose one intent:
- patterns - Test design, selectors, waits, and reliability techniques
- setup - Playwright installation, config, environments, and CI basics
- quickstart - Minimal path to run first E2E test
What do you want to do? (patterns/setup/quickstart)
</intake>
<routing>
Response Routing
| Response | File | Purpose |
|---|---|---|
| patterns | patterns.md |
Test-writing patterns, anti-flake practices, and debugging flow |
| setup | playwright-setup.md |
Setup steps, config model, environment strategy, and CI notes |
| quickstart | playwright-setup.md → patterns.md |
Stand up tooling first, then apply stable test patterns |
</routing>
Quick Principles
- Prefer user-visible assertions over implementation details
- Use robust locators (
getByRole,getByLabel,getByTestId) before CSS/XPath - Keep tests isolated and data-independent
- Minimize fixed sleeps; rely on Playwright auto-wait and explicit expect conditions
- Stabilize E2E by controlling auth, test data, and network behavior
References
patterns.md- Practical E2E patterns and pitfallsplaywright-setup.md- Setup and environment configuration
Gotchas
| Trigger | Gotcha | Fix |
|---|---|---|
Using div > ul > li:nth-child(3) > button as a locator |
Breaks on any DOM restructure, even visually invisible ones | Use getByRole > getByLabel > getByTestId > CSS (last resort) |
await page.waitForTimeout(3000) to wait for readiness |
Adds hard delay to every run; flakes on slow CI | Replace with await expect(locator).toBeVisible() using Playwright auto-wait |
| Asserting immediately after an action without waiting for the result | Race condition; flakes on slow renders | Use Playwright's built-in auto-wait: await expect(locator).toHaveText(...) |
| Test B passes only when test A runs first | Order-dependent suite fails on parallel CI runs | Each test creates and owns its own data; tear down on completion |
| Running full login UI flow for most tests | Login is not re-tested; you're paying time cost repeatedly | Use storageState for authenticated tests; reserve full login UI for a small smoke subset |
| One test scenario covers three different features | A failure in one feature fails the entire test; hard to diagnose | One scenario per test; group by feature or user journey |
| Retrying a flaky test and moving on when it passes | Root cause unknown; intermittent issue will recur | Repro with retries disabled; capture --trace on artifacts; investigate selector stability and async assumptions |
04 同仓库更多 Skills
任务完成前验证
verification-before-completion
在将工作标记为完成前使用的基于证据的验证清单。适用于提交 PR、发布、将工单标记为完成,或任何「我已完成」的声明之前;也适用于为差异测试套件的主张指定基线提交、设计变异测试活动或红灯运行证据、做出「不存在」的主张、普遍性主张,或将一次性演示作为长期保证提供时、归因某项测量结果或声称某次扫描或验证循环已完成时,以及陈述某项检查或 CI 套件将如何处理某个变更时。不要用于:合并后清理或归档(使用 post-pr-review),或处理 GitHub 审查意见(使用 code-review-intake)。
验证与审查方法论
validation-methodology
用于分阶段验证、故障分诊和追查深度设置的可复用验证与审查方法论。在运行验证阶梯、对失败进行分诊或执行对抗性审查时使用。不要用于:CE Gate 编排、专家派发的职责归属或步骤执行流程(这些保留在 Code-Conductor 中)。
上游智能体接手协议
upstream-onboarding
供上游智能体(Experience-Owner、Solution-Designer、Issue-Planner)与 Code-Conductor 在针对现有 GitHub issue 被调用时使用的共享开场阶段协议。它会生成适配规模的上下文简报,并在每个阶段边界对承接的工作执行标准检查。当用户可调用的智能体收到引用现有 GitHub issue 的请求、且必须在开场阶段加载 solution-authoring 与 upstream-onboarding 时使用。不要用于:子智能体派发(其已在经评估的会话上下文中运行)、合并后审查(使用 post-pr-review)、研究类或非树形子智能体。
React 组件测试策略
ui-testing
以用户行为为核心的弹性 React 组件测试策略。适用于编写或审阅组件级 React 测试、修复不稳定的组件测试,或建立 React 测试模式。不适用于:Playwright E2E 测试(使用 webapp-testing)、canvas 游戏交互(使用 browser-canvas-testing)、TDD 工作流(使用 test-driven-development)、失败调试(使用 systematic-debugging)、UI 组件设计(使用 frontend-design),或随机属性测试(使用 property-based-testing)。
UI 界面视觉迭代优化
ui-iteration
可复用的截图驱动 UI 打磨工作流,用于迭代式视觉优化。适用于通过反复审阅与调整来改进布局、层级、间距、反馈或基于 Tailwind 的呈现效果。不适用于:功能性 Bug 修复、仅针对无障碍的审计,或重大重设计策略工作(使用 Code-Smith 或 frontend-design)。
跟踪文件格式与交接规范
tracking-format
跟踪文件的 frontmatter 与协调格式指南。适用于创建或审阅本地跟踪文件及相关交接约定。不适用于:本文档所引用资料之外的会话记忆(session-memory)计划编写规则。