Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober 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 PC×
Skip to content
World desk5 min

How to Stop Cypress Tests at the Right Time

Cypress has different stop mechanisms for one test, the current spec, and a recorded Cloud run. Choose by scope and intended test outcome.

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.

Use Cypress.stop() to stop the remaining tests in the current spec, control the Cypress command queue to end one test early, or configure Cypress Cloud Auto Cancellation to stop assigning new specs after a failure threshold. These mechanisms have different scopes and outcomes: Cypress.stop() does not cancel an entire parallel Cloud run, and a passing test cannot have a partial-pass status.

Choose the stop mechanism by scope

First decide what should stop and what result the test should have. A test can pass, fail, or be pending/skipped; Cypress does not provide a separate “partially passed” outcome for ending a test successfully at a condition.

As an Amazon Associate I earn from qualifying purchases.

What should stop? Use Effect
Remaining tests in the current spec Cypress.stop() In cypress run, Cypress skips the rest of that spec. In cypress open, execution stops and the app remains open for inspection.
Optional commands in one test Conditional command-queue control Leave the test passing by not queueing the optional commands. Commands queued elsewhere are not cancelled.
One test that should fail or be skipped Throw an error, or call Mocha’s this.skip() Failing early records a failure; skipping records a pending/skipped outcome.
New specs across a recorded Cloud run Cypress Cloud Auto Cancellation After the configured failure threshold, Cloud stops assigning new specs and marks the run cancelled. Specs already running finish.

Stop the remaining tests in the current spec

To stop after a test fails, use Cypress.stop() in an afterEach hook. The documented pattern is:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
afterEach(function () {
  if (this.currentTest.state === 'failed') {
    Cypress.stop()
    return
  }
})

The return prevents later statements in that same hook from running after the stop call. Without it, code later in the hook can still execute. This hook stops the current spec’s remaining tests; it does not stop all specs in a parallel Cloud run.

In cypress run, remaining tests in the spec are skipped. In cypress open, execution stops and the app is left open so you can inspect it.

End one test early without failing it

Cypress commands are queued. A return from a .then() callback prevents commands inside that callback from being queued after the return, but it cannot cancel commands that the test already queued elsewhere. Put conditional follow-up work inside the callback when it may need to be skipped.

it('checks for a dashboard link when one is available', () => {
  cy.get('a').then(($links) => {
    const hasDashboard = [...$links].some(
      (el) => el.innerText.trim() === 'Dashboard'
    )

    if (hasDashboard) {
      return
    }

    // Queue any conditional follow-up commands here.
    cy.get('[data-cy="fallback-content"]').should('be.visible')
  })
})

Here, finding the Dashboard link returns from the callback before the fallback check is queued. If commands that you meant to avoid were queued outside the callback, they still run; reorganize the test so those commands are only queued in the branch that needs them.

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

Choose failure or skip when that is the intended result

  • Fail early: throw an error from the callback when the condition means the test has failed. The test is recorded as failed.
  • Skip at runtime: call this.skip() in a regular function () {} Mocha test callback. Do not use an arrow function for that callback, because Mocha binds this for the skip operation.

Cancel a recorded Cloud run after a failure threshold

For a recorded Cypress Cloud run, Auto Cancellation is the run-wide option. It applies across machines: after the threshold is reached, Cloud stops handing out new specs and marks the run cancelled, while specs already in progress finish. The Cypress documentation lists a default threshold of one genuine failure. You can configure a different threshold or disable the project setting for an individual run.

npx cypress run --record --key YOUR_RECORD_KEY --auto-cancel-after-failures 5

To disable the project setting for one run, pass false for the option:

npx cypress run --record --key YOUR_RECORD_KEY --auto-cancel-after-failures false

Auto Cancellation is documented for Cypress Cloud Business and Enterprise plans. Plan availability and Cloud settings can change, so verify current availability in your project’s Cypress Cloud settings before relying on it.

When not to cancel the whole run

Keeping the full suite running can be useful when a branch or scheduled workflow needs results from every spec—for example, to establish release readiness or gather broad audit or coverage results. In that case, disable Auto Cancellation for that run or choose a higher threshold rather than treating a cancelled run as a complete suite result.

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

Retries do not stop the suite

Retries rerun a failing test; they are not a stop mechanism. Cypress reruns that test’s beforeEach and afterEach hooks, which adds execution time. Failures in before and after hooks do not trigger retries. A configured retry count means additional attempts beyond the initial attempt.

Cypress documents retries as zero by default in both run mode and open mode. Set retry behavior intentionally for each workflow, and avoid using a large retry count as a substitute for deciding when a spec or run should stop.

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

Troubleshoot the common scope and queue mistakes

  • Other specs keep running after Cypress.stop(). That call stops the current spec, not the whole parallel Cloud run. Use Auto Cancellation for a recorded run-wide threshold.
  • Statements later in the hook still execute. Return after calling Cypress.stop() if the rest of that same hook must not run.
  • Commands run even after an early return. They were likely queued outside the .then() callback. Move optional follow-up commands inside the callback and queue them only in the branch that needs them.
  • this.skip() cannot access the test context. Use a regular function callback rather than an arrow function so Mocha can bind this.
  • Auto Cancellation does not stop an active spec immediately. It stops Cloud from assigning new specs once the threshold is met; specs already in progress finish.
  • Retries make a failing run take longer. Check configured retries and remember that each failed test attempt reruns its beforeEach and afterEach hooks.

Or skip the browser setup

For a website screenshot—not for controlling Cypress test execution—ScreenshotNeo offers a one-request capture through its website screenshot API. See the ScreenshotNeo documentation for API options.

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 are accepted and removed before capture; known consent platforms, newsletter popups, and chat widgets can also be removed, with each step configurable.
  • Bot checks, blank pages, failed loads, timeouts, and cache hits are not billed; response headers identify the page verdict and billing status.
  • An MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents and MCP clients.
  • The Free plan includes 1,000 screenshots per month with no card required; paid plans start at $5 for 3,000 screenshots.

Sign up for ScreenshotNeo free: 1,000 screenshots a month, no card required.

Free tools Windows power users keep installed

One-click scans. No signup required.

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
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair 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.