Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Implement end-to-end testing patterns across frameworks with proper test structure, data setup, and CI integration.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
SKILL.md
1---2name: e2e-testing-patterns3description: 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.4---56# E2E Testing Patterns78Build reliable, fast, and maintainable end-to-end test suites that provide confidence to ship code quickly and catch regressions before users do.910## When to Use This Skill1112- Implementing end-to-end test automation13- Debugging flaky or unreliable tests14- Testing critical user workflows15- Setting up CI/CD test pipelines16- Testing across multiple browsers17- Validating accessibility requirements18- Testing responsive designs19- Establishing E2E testing standards2021## Core Concepts2223### 1. E2E Testing Fundamentals2425**What to Test with E2E:**2627- Critical user journeys (login, checkout, signup)28- Complex interactions (drag-and-drop, multi-step forms)29- Cross-browser compatibility30- Real API integration31- Authentication flows3233**What NOT to Test with E2E:**3435- Unit-level logic (use unit tests)36- API contracts (use integration tests)37- Edge cases (too slow)38- Internal implementation details3940### 2. Test Philosophy4142**The Testing Pyramid:**4344```45/\46/E2E\ ← Few, focused on critical paths47/─────\48/Integr\ ← More, test component interactions49/────────\50/Unit Tests\ ← Many, fast, isolated51/────────────\52```5354**Best Practices:**5556- Test user behavior, not implementation57- Keep tests independent58- Make tests deterministic59- Optimize for speed60- Use data-testid, not CSS selectors6162## Detailed patterns and worked examples6364Detailed pattern documentation lives in `references/details.md`. Read that file when the navigation tier above is insufficient.6566## Best Practices67681. **Use Data Attributes**: `data-testid` or `data-cy` for stable selectors692. **Avoid Brittle Selectors**: Don't rely on CSS classes or DOM structure703. **Test User Behavior**: Click, type, see - not implementation details714. **Keep Tests Independent**: Each test should run in isolation725. **Clean Up Test Data**: Create and destroy test data in each test736. **Use Page Objects**: Encapsulate page logic747. **Meaningful Assertions**: Check actual user-visible behavior758. **Optimize for Speed**: Mock when possible, parallel execution7677```typescript78// ❌ Bad selectors79cy.get(".btn.btn-primary.submit-button").click();80cy.get("div > form > div:nth-child(2) > input").type("text");8182// ✅ Good selectors83cy.getByRole("button", { name: "Submit" }).click();84cy.getByLabel("Email address").type("[email protected]");85cy.get('[data-testid="email-input"]').type("[email protected]");86```8788## Common Pitfalls8990- **Flaky Tests**: Use proper waits, not fixed timeouts91- **Slow Tests**: Mock external APIs, use parallel execution92- **Over-Testing**: Don't test every edge case with E2E93- **Coupled Tests**: Tests should not depend on each other94- **Poor Selectors**: Avoid CSS classes and nth-child95- **No Cleanup**: Clean up test data after each test96- **Testing Implementation**: Test user behavior, not internals9798## Debugging Failing Tests99100```typescript101// Playwright debugging102// 1. Run in headed mode103npx playwright test --headed104105// 2. Run in debug mode106npx playwright test --debug107108// 3. Use trace viewer109await page.screenshot({ path: 'screenshot.png' });110await page.video()?.saveAs('video.webm');111112// 4. Add test.step for better reporting113test('checkout flow', async ({ page }) => {114await test.step('Add item to cart', async () => {115await page.goto('/products');116await page.getByRole('button', { name: 'Add to Cart' }).click();117});118119await test.step('Proceed to checkout', async () => {120await page.goto('/cart');121await page.getByRole('button', { name: 'Checkout' }).click();122});123});124125// 5. Inspect page state126await page.pause(); // Pauses execution, opens inspector127```128