{
  "doc": {
    "id": "api/cypress-api/stop",
    "title": "Cypress.stop() | Cypress Documentation",
    "description": "Stop Cypress on failure or any other conditions",
    "section": "api",
    "source_path": "/llm/markdown/api/cypress-api/stop.md",
    "version": "e6988a974973e9090ce70406c38cb2b9e0eac9fa",
    "updated_at": "2026-05-15T15:50:22.536Z",
    "headings": [
      {
        "id": "api/cypress-api/stop#cypress-stop",
        "text": "Cypress.stop",
        "level": 1
      },
      {
        "id": "api/cypress-api/stop#syntax",
        "text": "Syntax",
        "level": 2
      },
      {
        "id": "api/cypress-api/stop#examples",
        "text": "Examples",
        "level": 2
      },
      {
        "id": "api/cypress-api/stop#stop-tests-when-a-test-fails",
        "text": "Stop tests when a test fails",
        "level": 3
      },
      {
        "id": "api/cypress-api/stop#abort-tests-when-a-condition-is-met",
        "text": "Abort tests when a condition is met",
        "level": 3
      },
      {
        "id": "api/cypress-api/stop#notes",
        "text": "Notes",
        "level": 2
      },
      {
        "id": "api/cypress-api/stop#cypress-run-vs-cypress-open-behavior",
        "text": "cypress run vs cypress open behavior",
        "level": 3
      },
      {
        "id": "api/cypress-api/stop#why-choose-auto-cancellation",
        "text": "Why choose Auto Cancellation?",
        "level": 3
      },
      {
        "id": "api/cypress-api/stop#see-also",
        "text": "See also",
        "level": 2
      }
    ]
  },
  "chunks": [
    {
      "id": "api/cypress-api/stop#examples",
      "doc_id": "api/cypress-api/stop",
      "heading": "Examples",
      "heading_level": 2,
      "content_markdown": "## Examples\n\n### Stop tests when a test fails\n\nTo ensure tests stop immediately after a failure across any spec file, add the following snippet to your `support/index.js` file:\n\n```\nafterEach(function () {  if (this.currentTest.state === 'failed') {    Cypress.stop()    return  }})\n```\n\n### Abort tests when a condition is met\n\n```\nbeforeEach(() => {  if (env !== 'expected-condition') {    cy.log('Stop tests - environment is not setup correctly')    Cypress.stop()    return  }})\n```\n",
      "section": "api",
      "anchors": [
        "examples"
      ],
      "path": "/llm/json/chunked/api/cypress-api/stop.json",
      "token_estimate": 95
    },
    {
      "id": "api/cypress-api/stop#stop-tests-when-a-test-fails",
      "doc_id": "api/cypress-api/stop",
      "heading": "Stop tests when a test fails",
      "heading_level": 3,
      "content_markdown": "### Stop tests when a test fails\n\nTo ensure tests stop immediately after a failure across any spec file, add the following snippet to your `support/index.js` file:\n\n```\nafterEach(function () {  if (this.currentTest.state === 'failed') {    Cypress.stop()    return  }})\n```\n",
      "section": "api",
      "anchors": [
        "stop-tests-when-a-test-fails"
      ],
      "path": "/llm/json/chunked/api/cypress-api/stop.json",
      "token_estimate": 53
    },
    {
      "id": "api/cypress-api/stop#notes",
      "doc_id": "api/cypress-api/stop",
      "heading": "Notes",
      "heading_level": 2,
      "content_markdown": "## Notes\n\nCalling `Cypress.stop()` will stop the execution of remaining tests, but any code after `Cypress.stop()` in the same container block (such as `beforeEach` or `afterEach`) will still run. To prevent additional logic from executing after `Cypress.stop()`, add a `return` statement immediately after it:\n\n```\nif (someCondition) {  Cypress.stop()  return // Prevents further code execution in this block}\n```\n\n### `cypress run` vs `cypress open` behavior\n\nCalling `Cypress.stop()` during `cypress run` will skip any remaining tests in the current specfile. If recording to Cypress Cloud, all screenshots, videos, and [Test Replay](/llm/markdown/cloud/features/test-replay.md) will still successfully upload.\n\nCalling `Cypress.stop()` during `cypress open` will stop execution of the Cypress App, but remain open for inspection. The remaining tests will not run.\n\n### Why choose Auto Cancellation?\n\n[Auto Cancellation](/llm/markdown/cloud/features/smart-orchestration/run-cancellation.md) is available with Cypress Cloud's Business+ plan. It offers several advantages over `Cypress.stop` for stopping tests on **failure**:\n\n1.  **Scope of Cancellation:** `Cypress.stop` halts only the current spec file, skipping remaining tests within it. Auto Cancellation, however, stops all tests across all machines and marks the entire run as **cancelled** in Cypress Cloud for better visibility.\n2.  **Configurable Thresholds:** Auto Cancellation allows you to define failure thresholds. `Cypress.stop` executes immediately when the specified condition is met.\n3.  **Simplified Configuration**: Auto Cancellation settings can be managed in Cypress Cloud, whereas `Cypress.stop` requires manual code changes.\n4.  **Optimization with Spec Prioritization**: Combined with [Spec Prioritization](/llm/markdown/cloud/features/smart-orchestration/spec-prioritization.md) (another Business+ feature), Auto Cancellation helps efficiently allocate resources by running previously failing specs first in a new run.\n\nTo get started with Cypress Cloud, [sign up](https://cloud.cypress.io/signup) to start your **30 day free trial** - including all premium Cypress Cloud features and plenty of test results to let you experience the power of Cypress Cloud!\n",
      "section": "api",
      "anchors": [
        "notes"
      ],
      "path": "/llm/json/chunked/api/cypress-api/stop.json",
      "token_estimate": 377
    },
    {
      "id": "api/cypress-api/stop#cypress-run-vs-cypress-open-behavior",
      "doc_id": "api/cypress-api/stop",
      "heading": "cypress run vs cypress open behavior",
      "heading_level": 3,
      "content_markdown": "### `cypress run` vs `cypress open` behavior\n\nCalling `Cypress.stop()` during `cypress run` will skip any remaining tests in the current specfile. If recording to Cypress Cloud, all screenshots, videos, and [Test Replay](/llm/markdown/cloud/features/test-replay.md) will still successfully upload.\n\nCalling `Cypress.stop()` during `cypress open` will stop execution of the Cypress App, but remain open for inspection. The remaining tests will not run.\n",
      "section": "api",
      "anchors": [
        "cypress-run-vs-cypress-open-behavior"
      ],
      "path": "/llm/json/chunked/api/cypress-api/stop.json",
      "token_estimate": 79
    },
    {
      "id": "api/cypress-api/stop#why-choose-auto-cancellation",
      "doc_id": "api/cypress-api/stop",
      "heading": "Why choose Auto Cancellation?",
      "heading_level": 3,
      "content_markdown": "### Why choose Auto Cancellation?\n\n[Auto Cancellation](/llm/markdown/cloud/features/smart-orchestration/run-cancellation.md) is available with Cypress Cloud's Business+ plan. It offers several advantages over `Cypress.stop` for stopping tests on **failure**:\n\n1.  **Scope of Cancellation:** `Cypress.stop` halts only the current spec file, skipping remaining tests within it. Auto Cancellation, however, stops all tests across all machines and marks the entire run as **cancelled** in Cypress Cloud for better visibility.\n2.  **Configurable Thresholds:** Auto Cancellation allows you to define failure thresholds. `Cypress.stop` executes immediately when the specified condition is met.\n3.  **Simplified Configuration**: Auto Cancellation settings can be managed in Cypress Cloud, whereas `Cypress.stop` requires manual code changes.\n4.  **Optimization with Spec Prioritization**: Combined with [Spec Prioritization](/llm/markdown/cloud/features/smart-orchestration/spec-prioritization.md) (another Business+ feature), Auto Cancellation helps efficiently allocate resources by running previously failing specs first in a new run.\n\nTo get started with Cypress Cloud, [sign up](https://cloud.cypress.io/signup) to start your **30 day free trial** - including all premium Cypress Cloud features and plenty of test results to let you experience the power of Cypress Cloud!\n",
      "section": "api",
      "anchors": [
        "why-choose-auto-cancellation"
      ],
      "path": "/llm/json/chunked/api/cypress-api/stop.json",
      "token_estimate": 220
    }
  ]
}