E2E Tests Timing Out in Cursor-Generated Test Suites
End-to-end tests generated by Cursor using Playwright, Cypress, or Selenium time out during execution. Tests hang waiting for elements that never appear, pages that never load, or network requests that never complete. The tests work sometimes but fail intermittently, making your test suite unreliable and CI pipelines unpredictable.
E2E test flakiness is the number one reason teams abandon automated testing. Cursor generates tests that follow the happy path but don't account for the asynchronous, timing-dependent nature of real browser interactions. The AI writes selectors for elements that may not exist yet, clicks buttons before they're interactive, and asserts content that loads asynchronously.
The result is a test suite that passes locally (where the app is fast) but fails in CI (where resources are limited and the app is slower), or passes 80% of the time and fails randomly on the other 20%.
Error Messages You Might See
Common Causes
- Static waits instead of dynamic waits — Cursor uses
await page.waitForTimeout(3000)instead of waiting for specific elements or conditions, which is both slow and unreliable - Fragile CSS selectors — Tests use selectors like
.sc-bdfBwQ.iQNHGt(auto-generated class names) that change every build, or deeply nested selectors that break with minor DOM changes - Missing API/network wait — The test clicks a submit button and immediately checks for a success message, without waiting for the API request to complete
- Element not interactable — The test tries to click an element that's rendered but covered by a modal, loading overlay, or tooltip
- CI environment is slower — Tests assume fast load times from local development. CI runners have less CPU/memory, making everything slower and timing-dependent tests fail
- Navigation not awaited — The test clicks a link that triggers navigation but checks for content before the new page loads
How to Fix It
- Use data-testid attributes — Add
data-testid="submit-button"to important elements and select withpage.getByTestId('submit-button'). These are stable across builds and style changes - Wait for specific conditions, not time — Replace
waitForTimeoutwithawait page.waitForSelector('[data-testid="success-message"]')or Playwright's auto-waiting assertions likeawait expect(page.getByText('Success')).toBeVisible() - Wait for network idle after actions — Use
await page.waitForLoadState('networkidle')orawait page.waitForResponse(url => url.includes('/api/submit'))after form submissions - Increase default timeout for CI — Set
timeout: 60000in your Playwright/Cypress config for CI environments while keeping shorter timeouts locally - Use Playwright's built-in auto-waiting — Playwright's
click(),fill(), andexpect()methods auto-wait for elements to be visible and interactive. Use these instead of manual waits - Add retry logic for flaky assertions — Use Playwright's
expect().toBeVisible({ timeout: 10000 })or Cypress's built-in retry-ability to handle timing variations
Real developers can help you.
You don't need to be technical. Just describe what's wrong and a verified developer will handle the rest.
Get HelpFrequently Asked Questions
How do I make E2E tests less flaky?
Three key practices: 1) Never use fixed timeouts (waitForTimeout), always wait for specific conditions. 2) Use stable selectors (data-testid) instead of CSS classes or XPath. 3) Wait for network requests to complete before asserting results. Also run tests in a consistent environment with controlled test data.
Should I run E2E tests in CI on every commit?
Run fast unit tests on every commit. Run E2E tests on pull requests and before deployments. E2E tests are slow and resource-intensive, so running them on every commit slows down the feedback loop. Use parallelization and test sharding to speed them up when you do run them.