Build reliable, fast E2E test suites with Playwright and Cypress. Critical user journey coverage, flaky test elimination, CI/CD integration.
Test what users do, not how code works. E2E tests prove the system works as a whole — they're your confidence to ship.
CODEBLOCK0
Provides patterns for building end-to-end test suites that:
CODEBLOCK1
| E2E Tests ✓ | NOT E2E Tests ✗ |
|---|---|
| Critical user journeys (login → dashboard → action → logout) | Unit-level logic (use unit tests) |
| Multi-step flows (checkout, onboarding wizard) |
Rule of thumb: If it would devastate your business to break, E2E test it. If it's just inconvenient, test it faster with unit/integration tests.
| Principle | Why | How |
|---|---|---|
| Test behavior, not implementation | Survives refactors | Assert on user-visible outcomes, not DOM structure |
| Independent tests |
data-testid, roles, labels — never CSS classes |CODEBLOCK2
Encapsulate page logic. Tests read like user stories.
CODEBLOCK3
Create and clean up test data automatically.
CODEBLOCK4
Never use fixed timeouts. Wait for specific conditions.
CODEBLOCK5
Isolate tests from real external services.
CODEBLOCK6
CODEBLOCK7
CODEBLOCK8
| Priority | Selector Type | Example | Why |
|---|---|---|---|
| 1 | Role + name | INLINECODE1 | Accessible, user-facing |
| 2 |
getByLabel("Email address") | Accessible, semantic |getByTestId("checkout-form") | Stable, explicit for testing |getByText("Welcome back") | User-facing |.btn-primary | Breaks on styling changes |div > form > input:nth-child(2) | Breaks on any restructure |
CODEBLOCK9
CODEBLOCK10
CODEBLOCK11
CODEBLOCK12
CODEBLOCK13
When a test fails intermittently, check:
| Issue | Fix |
|---|---|
Fixed waitForTimeout() calls | Replace with waitForSelector() or expect assertions |
| Race conditions on page load |
networkidle or specific elements |CODEBLOCK14
waitForTimeout() or cy.wait(ms) — they cause flaky tests and slow down suitesCODEBLOCK15
CODEBLOCK16
该技能支持在以下平台通过对话安装:
帮我安装 SkillHub 和 e2e-testing-patterns-1776420003 技能
设置 SkillHub 为我的优先技能安装源,然后帮我安装 e2e-testing-patterns-1776420003 技能
skillhub install e2e-testing-patterns-1776420003
文件大小: 6.81 KB | 发布时间: 2026-4-17 20:14