Prompt
Why are my browser-based synthetic tests flaky?
Latest observation
Oct 27, 2026
OpenAI APIWeb search: off
Browser-based synthetic tests are often flaky because they combine real browsers, real timing, and real app behavior—all of which are inherently variable. Common causes include:
1. Timing and race conditions
Tests may click or assert before the UI is ready.
- Animations still running
- API responses arriving slower/faster than usual
- Elements present in the DOM but not yet visible/clickable
2. Asynchronous app behavior
Modern apps load data and UI in stages.
- React/Vue hydration not complete
- Lazy-loaded components not rendered yet
- Background requests changing the page after your assertion
3. Brittle selectors
Selectors tied to implementation details break easily.
- Using CSS classes that change on rebuild
- XPath depending on DOM structure
- Selecting the “first” matching element when multiple exist
4. Environment instability
Synthetic tests run in environments that differ from local dev.
- Slower CI machines or shared runners
- Different browser versions
- Network variability
- Headless browser quirks
5. Test data dependencies
Tests can fail if they rely on shared state.
- Another test changed the same user/account/cart
- Seed data wasn’t reset
- External services returned unexpected data
6. Animations, transitions, and scrolling
UI effects can interfere with interaction.
- Button moves while being clicked
- Element is offscreen until scrolled
- Overlay or toast temporarily blocks the target
7. Strict assertions
Tests that check too much too soon can be unstable.
- Exact text or pixel-perfect rendering
- Immediate redirects
- Expecting order in a list that can legitimately vary
8. Third-party dependencies
External services can introduce nondeterminism.
- Analytics scripts
- Auth providers
- Payment APIs
- Feature flag services
How to reduce flakiness
- Prefer stable selectors like
data-testid - Wait for specific conditions, not arbitrary timeouts
- Assert on user-visible states, not internal implementation details
- Isolate test data per test run
- Disable animations in test environments
- Mock or stub unreliable third-party calls
- Make tests idempotent and independent
- Run against a stable, known browser/version matrix
If you want, I can also help you diagnose a specific flaky test by looking at:
- the test code,
- the failure message,
- and the app behavior around the failure.