All skills
wshobson avatar

/e2e-testing-patterns

@be57c0b
by Seth Hobsonwshobson/agents40k stars
4,281

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.

Use this Skill: https://skilld.dev/gh/wshobson/agents/e2e-testing-patterns

This session only. Nothing lands on disk.

SKILL.md

≈65 tokens always: the name and description. ≈933 when used: this file. ≈2.6k more on demand in 1 file.

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

  1. Use Data Attributes: data-testid or data-cy for stable selectors
  2. Avoid Brittle Selectors: Don't rely on CSS classes or DOM structure
  3. Test User Behavior: Click, type, see - not implementation details
  4. Keep Tests Independent: Each test should run in isolation
  5. Clean Up Test Data: Create and destroy test data in each test
  6. Use Page Objects: Encapsulate page logic
  7. Meaningful Assertions: Check actual user-visible behavior
  8. 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

Source: SKILL.md on GitHub

No alerts16d5 checks · Risk SAFE
  • Gen Agent Trust Hub16d

    No security issues detected. The skill provides educational content and code patterns for implementing end-to-end testing with Playwright and Cypress, following industry best practices.

  • Socket16d

    No alerts

  • Snyk16d

    Risk: LOW · No issues

  • Runlayer6mo

    1/1 file flagged

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at be57c0b. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 days ago.

Activeupdated 4 months ago
  • Testing
  • playwright
  • cypress
  • e2e-testing
  • automation
  • flaky-tests
  • ci-cd
  • browser-testing
  • accessibility
  • page-objects

README badge

README badge for wshobson/agents/e2e-testing-patterns

Teaches end-to-end testing patterns for Playwright and Cypress, covering test structure, selector strategies, and debugging flaky tests. Focuses on critical user workflows like login and checkout rather than unit-level logic, with guidance on the testing pyramid and best practices for stable, maintainable test suites.

Generated from the current SKILL.md.

Does this skill cover both Playwright and Cypress?
Yes. The skill addresses end-to-end testing patterns applicable to both Playwright and Cypress, including best practices, debugging strategies, and test philosophy.
What should I NOT test with E2E according to this skill?
Unit-level logic, API contracts, edge cases, and internal implementation details—those belong in unit and integration tests. E2E should focus on critical user journeys.
How does this skill help with flaky tests?
It provides debugging techniques including headed mode, debug mode, trace viewers, and guidance on using proper waits instead of fixed timeouts to eliminate flakiness.
Does this skill include working code examples?
Yes. It includes TypeScript examples showing bad vs. good selector patterns, debugging approaches with test.step, screenshots, and pause points for inspection.

Generated from the current SKILL.md. These answers refresh after source changes.