e2e-testing-patterns
wshobson/agents
Master end-to-end testing with Playwright and Cypress to build reliable, maintainable test suites.
What is e2e-testing-patterns?
This skill teaches E2E testing patterns and best practices for building fast, reliable test suites that catch regressions and validate critical user workflows. Use it when implementing E2E tests, debugging flaky tests, or establishing testing standards across your team.
- Learn the testing pyramid and when to use E2E vs unit/integration tests
- Write stable, maintainable tests using data attributes and semantic selectors instead of brittle CSS classes
- Debug flaky tests using headed mode, debug mode, screenshots, and trace viewers
- Structure tests with page objects and meaningful assertions focused on user behavior
- Optimize test performance through mocking, parallel execution, and proper cleanup
- Test critical user journeys, cross-browser compatibility, accessibility, and responsive designs
How to install e2e-testing-patterns
npx skills add https://github.com/wshobson/agents --skill e2e-testing-patternsHow to use e2e-testing-patterns
- 1.Review the testing pyramid to understand what belongs in E2E tests vs unit/integration tests
- 2.Use data-testid or data-cy attributes in your application code for stable, semantic selectors
- 3.Write tests that follow user behavior (click, type, see) rather than testing implementation details
- 4.Structure tests with page objects to encapsulate page logic and reduce duplication
- 5.Run tests in headed mode or debug mode when investigating failures
- 6.Use test.step() to organize complex test flows and improve reporting
- 7.Clean up test data after each test to keep tests independent and deterministic
Use cases
- Setting up E2E test automation for critical user workflows like login, checkout, and signup
- Debugging and fixing flaky tests that fail intermittently due to timing or selector issues
- Establishing E2E testing standards and best practices across a development team
- Testing complex interactions like drag-and-drop and multi-step forms across multiple browsers
- Validating accessibility requirements and responsive design behavior in real browsers
- QA engineers building automated test suites
- Full-stack developers implementing E2E tests in CI/CD pipelines
- Engineering leads establishing testing standards
- Teams migrating from manual to automated testing
e2e-testing-patterns FAQ
Test critical user journeys (login, checkout, signup), complex interactions (drag-and-drop, multi-step forms), cross-browser compatibility, real API integration, and authentication flows. Avoid testing unit-level logic, API contracts, edge cases, and internal implementation details.
Flaky tests usually result from improper waits (using fixed timeouts instead of waiting for elements), brittle selectors that break with DOM changes, or tests that depend on each other. Use proper wait strategies, data-testid selectors, and ensure each test runs independently.
Run tests in headed mode (--headed) or debug mode (--debug) to see what's happening. Use page.screenshot() and page.video() to capture state, add test.step() for better reporting, and use page.pause() to inspect the page interactively.
No. E2E tests are slow and expensive. Test critical paths and user-visible behavior with E2E. Use unit tests for edge cases and internal logic. Follow the testing pyramid: many unit tests, some integration tests, few E2E tests.
Use data-testid or data-cy attributes for stable selectors, or semantic queries like getByRole() and getByLabel(). Avoid CSS classes, nth-child selectors, and DOM structure-dependent selectors that break when styling changes.
Full instructions (SKILL.md)
Source of truth, from wshobson/agents.
name: e2e-testing-patterns description: Master end-to-end testing with Playwright and Cypress to build reliable test suites that catch bugs, improve confidence, and enable fast deployment. Use when implementing E2E tests, debugging flaky tests, or establishing testing standards.
E2E Testing Patterns
Build reliable, fast, and maintainable end-to-end test suites that provide confidence to ship code quickly and catch regressions before users do.
When to Use This Skill
- Implementing end-to-end test automation
- Debugging flaky or unreliable tests
- Testing critical user workflows
- Setting up CI/CD test pipelines
- Testing across multiple browsers
- Validating accessibility requirements
- Testing responsive designs
- Establishing E2E testing standards
Core Concepts
1. E2E Testing Fundamentals
What to Test with E2E:
- Critical user journeys (login, checkout, signup)
- Complex interactions (drag-and-drop, multi-step forms)
- Cross-browser compatibility
- Real API integration
- Authentication flows
What NOT to Test with E2E:
- Unit-level logic (use unit tests)
- API contracts (use integration tests)
- Edge cases (too slow)
- Internal implementation details
2. Test Philosophy
The Testing Pyramid:
/\
/E2E\ ← Few, focused on critical paths
/─────\
/Integr\ ← More, test component interactions
/────────\
/Unit Tests\ ← Many, fast, isolated
/────────────\
Best Practices:
- Test user behavior, not implementation
- Keep tests independent
- Make tests deterministic
- Optimize for speed
- Use data-testid, not CSS selectors
Detailed patterns and worked examples
Detailed pattern documentation lives in references/details.md. Read that file when the navigation tier above is insufficient.
Best Practices
- Use Data Attributes:
data-testidordata-cyfor stable selectors - Avoid Brittle Selectors: Don't rely on CSS classes or DOM structure
- Test User Behavior: Click, type, see - not implementation details
- Keep Tests Independent: Each test should run in isolation
- Clean Up Test Data: Create and destroy test data in each test
- Use Page Objects: Encapsulate page logic
- Meaningful Assertions: Check actual user-visible behavior
- Optimize for Speed: Mock when possible, parallel execution
// ❌ Bad selectors
cy.get(".btn.btn-primary.submit-button").click();
cy.get("div > form > div:nth-child(2) > input").type("text");
// ✅ Good selectors
cy.getByRole("button", { name: "Submit" }).click();
cy.getByLabel("Email address").type("user@example.com");
cy.get('[data-testid="email-input"]').type("user@example.com");
Common Pitfalls
- Flaky Tests: Use proper waits, not fixed timeouts
- Slow Tests: Mock external APIs, use parallel execution
- Over-Testing: Don't test every edge case with E2E
- Coupled Tests: Tests should not depend on each other
- Poor Selectors: Avoid CSS classes and nth-child
- No Cleanup: Clean up test data after each test
- Testing Implementation: Test user behavior, not internals
Debugging Failing Tests
// Playwright debugging
// 1. Run in headed mode
npx playwright test --headed
// 2. Run in debug mode
npx playwright test --debug
// 3. Use trace viewer
await page.screenshot({ path: 'screenshot.png' });
await page.video()?.saveAs('video.webm');
// 4. Add test.step for better reporting
test('checkout flow', async ({ page }) => {
await test.step('Add item to cart', async () => {
await page.goto('/products');
await page.getByRole('button', { name: 'Add to Cart' }).click();
});
await test.step('Proceed to checkout', async () => {
await page.goto('/cart');
await page.getByRole('button', { name: 'Checkout' }).click();
});
});
// 5. Inspect page state
await page.pause(); // Pauses execution, opens inspector
Related skills
More from wshobson/agents and the wider catalog.
tailwind-design-system
Build production-ready design systems with Tailwind CSS v4, design tokens, and component libraries.
typescript-advanced-types
Master TypeScript's advanced type system: generics, conditional types, mapped types, and utility types for type-safe applications.
nodejs-backend-patterns
Build production-ready Node.js backends with Express/Fastify, middleware patterns, auth, and database integration.
python-performance-optimization
Profile and optimize Python code using cProfile, memory profilers, and performance best practices.
brand-landingpage
Brand-first landing page designer with guided interviews and Stitch-powered iteration.
python-testing-patterns
Implement comprehensive testing strategies with pytest, fixtures, mocking, and test-driven development.