返回顶部
e

e2e-testing-patterns端到端测试模式

Build reliable, fast E2E test suites with Playwright and Cypress. Critical user journey coverage, flaky test elimination, CI/CD integration.

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 1.0.0
安全检测
已通过
6,062
下载量
免费
免费
5
收藏
概述
安装方式
版本历史

e2e-testing-patterns

E2E Testing Patterns

Test what users do, not how code works. E2E tests prove the system works as a whole — they're your confidence to ship.

Installation

OpenClaw / Moltbot / Clawbot

CODEBLOCK0



WHAT This Skill Does

Provides patterns for building end-to-end test suites that:

  • - Catch regressions before users do
  • Run fast enough for CI/CD
  • Remain stable (no flaky failures)
  • Cover critical user journeys without over-testing

WHEN To Use

  • - Implementing E2E test automation for a web application
  • Debugging flaky tests that fail intermittently
  • Setting up CI/CD test pipelines with browser tests
  • Testing critical user workflows (auth, checkout, signup)
  • Choosing what to test with E2E vs unit/integration tests

Test Pyramid — Know Your Layer

CODEBLOCK1

What E2E Tests Are For

E2E Tests ✓NOT E2E Tests ✗
Critical user journeys (login → dashboard → action → logout)Unit-level logic (use unit tests)
Multi-step flows (checkout, onboarding wizard)
API contracts (use integration tests) | | Cross-browser compatibility | Edge cases (too slow, use unit tests) | | Real API integration | Internal implementation details | | Authentication flows | Component visual states (use Storybook) |

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.



Core Principles


PrincipleWhyHow
Test behavior, not implementationSurvives refactorsAssert on user-visible outcomes, not DOM structure
Independent tests
Parallelizable, debuggable | Each test creates its own data, cleans up after |
| Deterministic waits | No flakiness | Wait for conditions, not fixed timeouts |
| Stable selectors | Survives UI changes | Use data-testid, roles, labels — never CSS classes |
| Fast feedback | Developers run them | Mock external services, parallelize, shard |


Playwright Patterns

Configuration

CODEBLOCK2

Pattern: Page Object Model

Encapsulate page logic. Tests read like user stories.

CODEBLOCK3

Pattern: Fixtures for Test Data

Create and clean up test data automatically.

CODEBLOCK4

Pattern: Smart Waiting

Never use fixed timeouts. Wait for specific conditions.

CODEBLOCK5

Pattern: Network Mocking

Isolate tests from real external services.

CODEBLOCK6



Cypress Patterns

Custom Commands

CODEBLOCK7

Network Intercepts

CODEBLOCK8



Selector Strategy


PrioritySelector TypeExampleWhy
1Role + nameINLINECODE1Accessible, user-facing
2
Label | getByLabel("Email address") | Accessible, semantic |
| 3 | data-testid | getByTestId("checkout-form") | Stable, explicit for testing |
| 4 | Text content | getByText("Welcome back") | User-facing |
| ❌ | CSS classes | .btn-primary | Breaks on styling changes |
| ❌ | DOM structure | div > form > input:nth-child(2) | Breaks on any restructure |

CODEBLOCK9



Visual Regression Testing

CODEBLOCK10



Accessibility Testing

CODEBLOCK11



Debugging Failed Tests

CODEBLOCK12

CODEBLOCK13



Flaky Test Checklist

When a test fails intermittently, check:

IssueFix
Fixed waitForTimeout() callsReplace with waitForSelector() or expect assertions
Race conditions on page load
Wait for networkidle or specific elements |
| Test data pollution | Ensure tests create/clean their own data |
| Animation timing | Wait for animations to complete or disable them |
| Viewport inconsistency | Set explicit viewport in config |
| Random test order issues | Tests must be independent |
| Third-party service flakiness | Mock external APIs |


CI/CD Integration

CODEBLOCK14



NEVER Do

  1. 1. NEVER use fixed waitForTimeout() or cy.wait(ms) — they cause flaky tests and slow down suites
  2. NEVER rely on CSS classes or DOM structure for selectors — use roles, labels, or data-testid
  3. NEVER share state between tests — each test must be completely independent
  4. NEVER test implementation details — test what users see and do, not internal structure
  5. NEVER skip cleanup — always delete test data you created, even on failure
  6. NEVER test everything with E2E — reserve for critical paths; use faster tests for edge cases
  7. NEVER ignore flaky tests — fix them immediately or delete them; a flaky test is worse than no test
  8. NEVER hardcode test data in selectors — use dynamic waits for content that varies

Quick Reference

Playwright Commands

CODEBLOCK15

Cypress Commands

CODEBLOCK16

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 e2e-testing-patterns-1776420003 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 e2e-testing-patterns-1776420003 技能

通过命令行安装

skillhub install e2e-testing-patterns-1776420003

下载

⬇ 下载 e2e-testing-patterns v1.0.0(免费)

文件大小: 6.81 KB | 发布时间: 2026-4-17 20:14

v1.0.0 最新 2026-4-17 20:14
Initial release — best-practice patterns for building bulletproof end-to-end test suites with Playwright and Cypress.

- Provides guidance and example code for stable, fast, CI/CD-friendly E2E testing.
- Covers test pyramid philosophy, what (and what not) to test with E2E.
- Includes concrete Playwright patterns: config, page objects, fixtures, smart waiting, network mocking.
- Adds Cypress patterns: custom commands, network intercepts.
- Emphasizes critical workflows, flake resistance, and practical test architecture.
- Quick install instructions via Clawhub.

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部