October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk5 min

How to Manage Flaky Tests in Cypress

A retry pass does not fix a flaky Cypress test. Learn how to isolate state, wait for observable conditions, inspect CI evidence, and set a deliberate retry policy.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A Cypress test that fails once and passes on retry is flaky—not fixed. Use retries to expose inconsistent outcomes, then trace the cause: shared state, timing assumptions, unstable selectors, or differences between CI and local runs. Make the test wait for observable conditions, capture evidence from the failed attempt, and track each flake until its cause is corrected.

Confirm what is actually flaky

Start by recording the exact spec and test, assertion or command that failed, browser, run mode, environment, and CI job. Establish whether it fails only in CI, only after another test runs, or on the first attempt before passing on a retry. Cypress retries can reveal that a test changes outcome across attempts, but a retry pass is a signal to investigate rather than proof of a repair. See Cypress’s test retries guidance.

As an Amazon Associate I earn from qualifying purchases.

Run the test by itself and in its normal suite context. If it passes alone but fails in the suite, look for order dependence or state left by another test. If it fails only in CI, compare the application build, browser, configuration, test data, server startup, network access, and available resources with the local run.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Make tests independent of shared state

Cypress states that “Tests should always be able to be run independently from one another and still pass.” End-to-end test isolation is enabled by default, and Cypress cleans the browser context between tests when isolation is enabled. That does not reset every database, service, shared account, or server-side fixture.

  • Give each test predictable data and setup; avoid depending on records created by another test.
  • Check whether shared accounts or persistent data are being changed by parallel jobs or prior runs.
  • Use programmatic login and controlled application state when login itself is not the behavior being tested.
  • Run the suspect test alone, then in its suite, to distinguish external-state issues from order dependence.

Use Cypress’s writing and organizing tests guidance when deciding how to isolate test behavior.

Wait for observable conditions, not guessed durations

A fixed sleep assumes the application always becomes ready within the duration chosen. Network speed, animations, API responses, server startup, or database availability can invalidate that assumption. Cypress identifies these and other race conditions in its retry documentation.

  1. Identify the state the next action actually requires: a button enabled, a result rendered, a request completed, or a loading indicator gone.
  2. Use Cypress’s retryable queries and assertions to wait for that state rather than inserting an arbitrary delay.
  3. For important actions and requests, assert the required intermediate result before proceeding. This localizes failure to the step that did not complete as expected.

Cypress’s debugging guide notes that insufficient assertions around actions or requests are a common flake pattern.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Reduce selector and test-scope fragility

  • Prefer stable data-* attributes for selectors when the application can provide them. Selectors tied to styling or implementation details are more likely to break when the interface changes.
  • Keep each test focused enough that its failure location points maintainers toward the broken behavior.
  • Do not exercise unrelated setup through the UI when a controlled setup path is appropriate. Cypress recommends programmatic login when login is not the behavior under test.

See Cypress’s best practices for additional guidance on selectors and test setup.

Investigate CI failures using the failed attempt

Compare an actual failing attempt with a passing attempt on the same code where possible. Inspect the failure location and the state immediately before it, then compare relevant application and environment differences: build, server startup, browser, configuration, test data, network access, and resource availability. Cypress’s debugging guide recommends reviewing CI build changes and recognizes network speed variation as a source of local-versus-CI differences.

If the run is recorded in Cypress Cloud, Test Replay can provide the DOM, network requests, console logs, and element state from a test attempt. Comparing a failing replay with a passing attempt can help show whether the cause was an unmet UI state, a request, or an environmental difference. Cloud’s Flaky Test Management applies to recorded runs with retries enabled; the current documentation says its detection, analytics, and alerting require a Team plan. See Cypress Cloud Flaky Test Management.

Choose a retry policy deliberately

Cypress retries are disabled by default. You can configure retry counts for run mode and open mode. Retries rerun the test and its hooks, so they increase execution time; use a restrained setting and review which tests rely on retries. A retry may reduce noisy failures while the team investigates, but should not become the permanent substitute for a root-cause fix. The details are in Cypress test retries.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

There is no universally correct retry count or pass/fail policy. Decide based on suite duration and the reliability signal your release process needs:

  • Signal policy: Does a test that fails and then passes count as passing, or should detected flakiness fail the run?
  • Feedback cost: How much time do extra test attempts and rerun hooks add?
  • Evidence: Can the team inspect attempt logs, DOM state, network records, console messages, screenshots, video, or replay?
  • Operational fit: Can the team record CI runs and access the Cypress Cloud plan required for its analytics, or should it rely on local and CI artifacts?
  • Ownership: Is each flaky test assigned and tracked to a root-cause fix?

Cypress documents experimental strategies that change how detected flakes affect the final pass/fail result. They are experimental: verify the current names and behavior in Cypress’s experimental features documentation before adopting them. Align the signal with your release needs rather than treating a particular setting as a universal standard.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot by symptom

Symptom Likely area to inspect Next step
Passes alone, fails in the suite Test order, shared account or server-side data, setup that runs only once Compare isolated and suite runs; make setup and data independent.
Fails before a retry, then passes Nondeterministic state, timing, requests, or environment Inspect the failed attempt and replace timing assumptions with assertions on required state.
Fails in CI but passes locally Build, browser, configuration, server readiness, test data, network, or resource differences Compare CI and local conditions and inspect recorded attempt evidence where available.
Fails after a UI change Selector coupled to styling or implementation details Use a stable application-provided data-* selector where practical.
Failures move between unrelated steps Insufficient assertions around earlier actions or requests Add assertions at the state transitions the later steps depend on.

Or skip the browser setup

For capturing a page screenshot as part of a debugging workflow, ScreenshotNeo provides a single-request screenshot API; it is not a replacement for diagnosing Cypress test behavior. Example using cURL (replace the URL with the page you need):

ScreenshotNeo API documentation

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

Cookie banners, newsletter popups, and chat widgets are removed before capture; bot checks, blank pages, failed loads, timeouts, and cache hits are not billed. Its MCP server lets AI agents use screenshot tools, and the free plan includes 1,000 screenshots a month without a card; paid plans start at $5 for 3,000. Sign up for ScreenshotNeo’s free plan.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.