Prompt
Why are my Cypress tests so flaky on a dynamic frontend?
Latest observation
Oct 27, 2026
OpenAI APIWeb search: off
Cypress tests usually get flaky on a dynamic frontend for the same few reasons: the app is changing faster than the test is waiting for, or the test is relying on something unstable.
Common causes:
- Async UI updates: React/Vue/Angular state, API calls, animations, and rerenders happen after your command runs.
- Unstable selectors: Using text, CSS classes, or DOM structure that changes often.
- Race conditions: The test clicks before data loads, or asserts before the UI settles.
- Animations/transitions: Elements move or re-render while Cypress is trying to interact.
- Network variability: Real backend responses vary in timing or content.
- Test interference: Shared state, leftover cookies/localStorage, or parallel tests affecting each other.
- Overusing
cy.wait(): Fixed waits are often too short sometimes and too long other times.
What usually helps:
- Use stable selectors, like
data-cyordata-testid. - Prefer assertions that wait for the app state:
cy.get(...).should('be.visible')cy.get(...).should('contain', 'Loaded')
- Wait on network aliases instead of arbitrary time:
cy.intercept(...).as('getData')cy.wait('@getData')
- Avoid asserting on elements that are mid-transition.
- Make tests independent and reset state between tests.
- Stub or control external dependencies when possible.
- If the UI rerenders a lot, re-query the element instead of storing stale references.
A good rule of thumb: test user-visible outcomes, not implementation timing.
If you want, I can also help you debug a specific flaky Cypress test if you paste the code.