Prompt

How do I debug flaky browser tests that pass locally but fail in CI?

Technology / Testing & QA1 observationLast seen Oct 26, 2026

Latest observation

Oct 26, 2026OpenAI APIWeb search: off

Flaky browser tests usually come down to one of a few things: timing, environment differences, shared state, or test-order dependence. Here’s a practical way to debug them.

1) Reproduce the CI environment locally

The fastest way to debug is to make local runs look like CI:

  • Run the same browser version and mode as CI
  • Use the same viewport/device settings
  • Match OS/container if possible
  • Run headless if CI is headless
  • Use the same test command and env vars

If CI uses Docker or a cloud runner, try running the tests in that same image locally.

2) Get more evidence from the failing test

Enable artifacts on failure:

  • screenshots
  • video
  • browser console logs
  • network logs / HAR
  • DOM snapshots or HTML dumps
  • test runner traces if your framework supports them

This often shows whether the issue is:

  • a selector not found
  • an element not clickable
  • a redirect or auth problem
  • a race where the UI hasn’t settled yet

3) Look for timing and synchronization bugs

The most common cause is asserting too early or clicking before the UI is ready.

Typical fixes:

  • wait for the right condition, not just a fixed sleep
  • wait for navigation to finish
  • wait for the element to be visible, enabled, and stable
  • wait for API responses or state changes that drive the UI
  • avoid arbitrary sleep() calls unless temporarily for debugging

Examples of fragile patterns:

  • clicking immediately after an animation starts
  • asserting on text before async rendering completes
  • using waitForSelector but not checking visibility or readiness

4) Check for shared state and test isolation problems

Tests may pass alone but fail in CI when run in parallel or in a different order.

Verify that each test:

  • creates its own data
  • doesn’t depend on state from previous tests
  • cleans up after itself
  • uses unique user accounts, IDs, emails, etc.
  • resets cookies/local storage/session storage if needed

Common hidden dependency:

  • a test assumes a record already exists because another test created it earlier

5) Investigate race conditions in the app itself

Sometimes the test is exposing a real app bug.

Examples:

  • a loading spinner disappears before data is actually ready
  • a toast blocks clicks intermittently
  • state updates happen out of order
  • API responses arrive in a different order in CI

If your app is flaky in production too, browser tests are doing you a favor.

6) Check CI resource constraints

CI is often slower or less stable than local machines.

Issues to consider:

  • CPU starvation
  • low memory
  • slower disk/network
  • limited GPU or disabled hardware acceleration
  • browser startup differences
  • viewport too small causing responsive layout changes

This can change:

  • animation timing
  • element positions
  • lazy loading behavior
  • whether elements are hidden behind overlays

7) Add retries carefully

Retries can reduce noise, but don’t use them to hide the problem.

Good use:

  • temporary mitigation while you investigate
  • capturing more logs on first failure

Bad use:

  • masking real timing bugs indefinitely

If you add retries, still track failure rate and root cause.

8) Make failures deterministic

To debug a flaky test, try to force failure:

  • run it 20–100 times in a loop
  • run the full suite multiple times
  • run tests in random order
  • run with parallelism on and off
  • throttle CPU/network if possible

If a test fails only under load or when run with others, that’s a strong clue.

9) Instrument the app and test

Add temporary debugging output:

  • log key lifecycle events
  • log API requests/responses
  • log when UI state changes
  • log when elements become clickable
  • dump page HTML on failure

For browser automation, it’s often useful to log:

  • current URL
  • page title
  • console errors
  • failed network requests
  • visible text around the failing element

10) Use stronger locators

Flaky selectors are common.

Prefer:

  • data-testid / data-qa attributes
  • accessible roles and labels
  • stable IDs

Avoid:

  • brittle CSS chains
  • text that changes with localization or dynamic content
  • selecting by nth-child unless unavoidable

11) Common CI-only causes

A few especially common differences:

  • timezone/locale differences
  • missing fonts
  • headless browser behavior
  • popup blockers or permission prompts
  • auth/session expiration
  • third-party services unavailable in CI
  • test data collisions between parallel jobs
  • caching differences

12) A good debugging workflow

  1. Re-run failing test in a loop locally.
  2. Capture screenshots/video/logs on failure.
  3. Compare local vs CI browser/environment.
  4. Check for timing assumptions.
  5. Check isolation and shared state.
  6. Inspect app/network logs for the exact failure point.
  7. Fix the root cause, not just the symptom.

13) If you want a quick checklist

Ask:

  • Is the environment really the same?
  • Is the test waiting for the right thing?
  • Does it depend on prior state?
  • Does it fail more under load or parallelism?
  • Are selectors stable?
  • Are there console/network errors?
  • Is the app itself flaky?

If you want, I can also give you a framework-specific debugging guide for Playwright, Cypress, Selenium, or WebdriverIO.

Observation history

How did Obsurfable measure this prompt?

Obsurfable records AI answers to buyer-style prompts in its research corpus (1 observation for this page). Metrics are distributions over observations, not a single static ranking.

Which AI systems does Obsurfable collect answers from?

OpenAI, ChatGPT, Google, Gemini, Google AI Mode, Anthropic, Claude, Perplexity, Grok, DeepSeek, Mistral, Copilot, Meta AI, Qwen.

How can brands improve their AEO?

Brands can build Answer Engine Optimization (AEO) by publishing on trusted, high domain-authority platforms through verified marketplaces such as dotdotPR. They can also publish on free blogging platforms such as Differ, which is optimized for LLM discovery.

Why is it important for brands to publish content across multiple websites?

Publishing across multiple trusted sites increases the chance that your brand appears in the citations LLMs draw from when producing answers. Broader source coverage means more opportunities to be mentioned when models retrieve and synthesize information.

Want this interpreted for your brand?

Explorer is the free public corpus. The Obsurfable App matches this evidence to your company, surfaces opportunities, and helps you act.