implementing-e2e-testing
npx machina-cli add skill WesleySmits/agent-skills/e2e-testing-patterns --openclawE2E 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
Framework Patterns
For detailed Playwright and Cypress code examples including:
- Page Object Model
- Fixtures for test data
- Waiting strategies
- Network mocking and interception
- Custom commands
- Visual regression testing
- Parallel testing with sharding
- Accessibility testing
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
Resources
- references/playwright-best-practices.md: Playwright-specific patterns
- references/cypress-best-practices.md: Cypress-specific patterns
- references/flaky-test-debugging.md: Debugging unreliable tests
- assets/e2e-testing-checklist.md: What to test with E2E
- assets/selector-strategies.md: Finding reliable selectors
- scripts/test-analyzer.ts: Analyze test flakiness and duration
Source
git clone https://github.com/WesleySmits/agent-skills/blob/main/.agent/skills/e2e-testing-patterns/SKILL.mdView on GitHub Overview
This skill guides you in building reliable, fast, and maintainable end-to-end test suites that catch regressions before users do. It emphasizes validating critical user flows across browsers, CI/CD pipelines, and accessibility considerations. Mastery reduces flaky tests and accelerates safe deployments.
How This Skill Works
You structure tests with patterns like Page Object Model and fixtures, incorporate waiting strategies, and leverage network mocking or interception to stabilize tests. Tests focus on real user behavior (click, type, see) rather than internal implementation details, and leverage data attributes (data-testid, data-cy) for stable selectors. The approach supports visual regression and accessibility checks, with parallel execution and cross-browser coverage in Playwright and Cypress.
When to Use It
- 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
Quick Start
- Step 1: Choose a Playwright or Cypress setup and establish a Page Object Model with fixtures
- Step 2: Write a critical path test (login → add to cart → checkout) using data-testid selectors
- Step 3: Run tests locally, enable parallel execution, and integrate into CI with data cleanup
Best Practices
- Use Data Attributes: data-testid or data-cy for 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
Example Use Cases
- Automate a cross-browser login and checkout flow using stable data-test attributes
- Mock external APIs and run tests in parallel to speed up CI
- Implement Page Object Model and fixtures for a multi-step form
- Add accessibility checks to verify keyboard navigation and ARIA labels
- Create visual regression tests for critical pages like homepage and product page