Skip to content
Back to AI Coding

E2E Test Generation

Generate end-to-end tests (Playwright/Cypress) for critical user flows.

Testing & ReviewAdvanced

Why

GitHub's 2024 survey found 92% of US respondents use AI coding tools for test case generation, and 98% of organizations have experimented with AI for tests. E2E tests catch UI + API + DB integration bugs that unit/integration miss.

AI scaffolds the happy-path flow fast; you add the assertions that matter.

When

Use for the top 3-5 critical flows (login, checkout, search). Skip for low-stakes UI.

How

1. Pick a critical flow; write it as steps in words. 2. Ask: "Playwright test for these steps; assert on visible UI + URL + key data". 3. Run against a staging build; fix flakiness with waitFor, not sleep. 4. Add to CI on PRs (parallelized, sharded). 5. Keep the suite small; E2E is slow.

Example

Flow: login → search "dune" → add to cart → checkout → confirmation page test("purchase a book", async ({ page }) => { await page.goto("/login"); await page.fill("#email", "[email protected]"); ... await page.fill("#search", "dune"); await page.click("text=Add to cart"); await page.click("text=Checkout"); await expect(page).toHaveURL(/\/order\/\d+/); await expect(page.locator("text=Confirmation")).toBeVisible(); });

Common Problems

  • ⚠Error: Cannot find module 'jest' / 'vitest' → run `npm install --save-dev vitest` (or jest); verify the test script in package.json.
  • ⚠Error: "Test timed out after 5000ms" → increase `testTimeout` in config or await the async operation; common with network calls.
  • ⚠AssertionError: expected undefined to equal 'x' → the mock returned undefined; verify the mock setup returns the expected shape.

Best Practices

  • ✓Use waitFor, never sleep, to avoid flakiness.
  • ✓Keep E2E to the top critical flows; parallelize in CI.
  • ✓Measure the outcome with a concrete metric (time saved, defect rate, test coverage) so the practice can be justified and improved.

FAQ

What is E2E Test Generation?

Generate end-to-end tests (Playwright/Cypress) for critical user flows. It helps developers quickly grasp the core value and use cases of E2E Test Generation.

How do I get started with E2E Test Generation?

To get started with E2E Test Generation, focus on these points first: Pick a critical flow; write it as steps in words.

What are common mistakes with E2E Test Generation?

Common mistakes when using E2E Test Generation include: Error: Cannot find module 'jest' / 'vitest' → run `npm install --save-dev vitest` (or jest); verify the test script in package.json.; Error: "Test timed out after 5000ms" → increase `testTimeout` in config or await the async operation; common with network calls.; AssertionError: expected undefined to equal 'x' → the mock returned undefined; verify the mock setup returns the expected shape..

What are the best practices for E2E Test Generation?

Best practices for E2E Test Generation include: Use waitFor, never sleep, to avoid flakiness.; Keep E2E to the top critical flows; parallelize in CI.; Measure the outcome with a concrete metric (time saved, defect rate, test coverage) so the practice can be justified and improved..

How do I learn more about E2E Test Generation?

Start with the official docs, then search real-world examples on GitHub. Validate patterns in a small scratch repo before applying them to production code.