Skip to content

Commit 8ee76ce

Browse files
14.2.0 Release (#6118)
* changelog title * docs: Document Cypress.stop (#6115) * docs: Document Cypress.runner.stop * Update benefits and make it a shared partial * lint * Update API to Cypress.stop * fix sidebar label * Add distinction between open and run mode behavior * chore: add changelog --------- Co-authored-by: AtofStryker <[email protected]>
1 parent 8a81200 commit 8ee76ce

File tree

7 files changed

+111
-7
lines changed

7 files changed

+111
-7
lines changed

docs/api/cypress-api/stop.mdx

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
---
2+
title: 'Cypress.stop() | Cypress Documentation'
3+
description: Stop Cypress on failure or any other conditions
4+
sidebar_label: stop
5+
---
6+
7+
<ProductHeading product="app" />
8+
9+
# Cypress.stop
10+
11+
Stop the Cypress App on the current machine while tests are running. This can be useful for stopping test execution upon failures or other predefined conditions.
12+
13+
:::tip
14+
15+
**Auto Cancellation**: If you're looking to automatically stop _all tests_ across _multiple machines_ when a test fails, consider using the [Auto Cancellation feature](/cloud/features/smart-orchestration/run-cancellation) in Cypress Cloud.
16+
17+
<AutoCancellationBenefits />
18+
19+
:::
20+
21+
## Syntax
22+
23+
```javascript
24+
Cypress.stop()
25+
```
26+
27+
## Examples
28+
29+
### Stop tests when a test fails
30+
31+
To ensure tests stop immediately after a failure across any spec file, add the following snippet to your `support/index.js` file:
32+
33+
```javascript
34+
afterEach(function () {
35+
if (this.currentTest.state === 'failed') {
36+
Cypress.stop()
37+
}
38+
})
39+
```
40+
41+
### Abort tests when a condition is met
42+
43+
```javascript
44+
beforeEach(() => {
45+
if (env !== 'expected-condition') {
46+
cy.log('Stop tests - environment is not setup correctly')
47+
Cypress.stop()
48+
}
49+
})
50+
```
51+
52+
## Notes
53+
54+
### `cypress run` vs `cypress open` behavior
55+
56+
Calling `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](/cloud/features/test-replay) will still successfully upload.
57+
58+
![Terminal output of a Cypress run displays running an `example.cy.ts` file with 1 test passing in green and 1 test passing in red with an error message. The Results table shows 4 tests, 1 passing, 1 failing, and 2 skipped.](/img/api/stop/cypress-stop-during-run-mode.png)
59+
60+
Calling `Cypress.stop()` during `cypress open` will stop execution of the Cypress App, but remain open for inspection. The remaining tests will not run.
61+
62+
![Cypress App shows an example.cy.ts file as running with 1 passing test collapsed, 1 failing test expanded with the assertion error and the remaining tests having not run, showing square neutral icons for their status.](/img/api/stop/cypress-stop-during-open-mode.png)
63+
64+
### Why choose Auto Cancellation?
65+
66+
[Auto Cancellation](/cloud/features/smart-orchestration/run-cancellation) is available with Cypress Cloud's Business+ plan. It offers several advantages over `Cypress.stop` for stopping tests on **failure**:
67+
68+
1. **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.
69+
2. **Configurable Thresholds:** Auto Cancellation allows you to define failure thresholds. `Cypress.stop` executes immediately when the specified condition is met.
70+
3. **Simplified Configuration**: Auto Cancellation settings can be managed in Cypress Cloud, whereas `Cypress.stop` requires manual code changes.
71+
4. **Optimization with Spec Prioritization**: Combined with [Spec Prioritization](/cloud/features/smart-orchestration/spec-prioritization) (another Business+ feature), Auto Cancellation helps efficiently allocate resources by running previously failing specs first in a new run.
72+
73+
<CloudFreePlan />
74+
75+
## See also
76+
77+
- [Auto Cancellation](/cloud/features/smart-orchestration/run-cancellation)
78+
- [`Cypress.currentTest`](/api/cypress-api/currenttest)
79+
- [`Cypress.currentRetry`](/api/cypress-api/currentretry)
80+
- [Load Balancing](/cloud/features/smart-orchestration/load-balancing)
81+
- [Parallelization](/cloud/features/smart-orchestration/parallelization)
82+
- [Spec Prioritization](/cloud/features/smart-orchestration/spec-prioritization)

docs/app/references/changelog.mdx

+19
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,25 @@ sidebar_label: Changelog
88

99
# Changelog
1010

11+
## 14.2.0
12+
13+
_Released 3/12/2025_
14+
15+
**Features:**
16+
17+
- [`Cypress.stop()`](https://on.cypress.io/cypress-stop) is now available to stop the Cypress App on the current machine while tests are running. This can be useful for stopping test execution upon failures or other predefined conditions. Addresses [#518](https://github.com/cypress-io/cypress/issues/518). Addressed in [#31225](https://github.com/cypress-io/cypress/pull/31225).
18+
19+
**Misc:**
20+
21+
- The browser dropdown now has a more minimal design - showing only the icon of the browser selected to the left of the URL. The currently selected browser also now shows at the top of the browser dropdown. Browsers with longer names will now have their names correctly left aligned in the browser dropdown. Addresses [#21755](https://github.com/cypress-io/cypress/issues/21755) and [#30998](https://github.com/cypress-io/cypress/issues/30998). Addressed in [#31216](https://github.com/cypress-io/cypress/pull/31216).
22+
- Additional CLI options will be displayed in the terminal for some Cloud error messages. Addressed in [#31211](https://github.com/cypress-io/cypress/pull/31211).
23+
- Updated Cypress Studio with url routing to support maintaining state when reloading. Addresses [#31000](https://github.com/cypress-io/cypress/issues/31000) and [#30996](https://github.com/cypress-io/cypress/issues/30996).
24+
25+
**Dependency Updates:**
26+
27+
- Upgraded `cli-table3` from `0.5.1` to `0.6.5`. Addressed in [#31166](https://github.com/cypress-io/cypress/pull/31166).
28+
- Upgraded `simple-git` from `3.25.0` to `3.27.0`. Addressed in [#31198](https://github.com/cypress-io/cypress/pull/31198).
29+
1130
## 14.1.0
1231

1332
_Released 2/25/2025_

docs/cloud/features/smart-orchestration/run-cancellation.mdx

+1-7
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,7 @@ changes. When Auto Cancellation is enabled, once the number of failed tests goes
2626
over a preset threshold, the entire test run is canceled. Note that any
2727
in-progress specs will continue to run to completion.
2828

29-
<Icon name="check-circle" color="green" /> **Benefits:** Canceling an **entire**
30-
test run, even if parallelized, upon the first test failure will:
31-
32-
1. **Save time**. Resolve test outcomes faster.
33-
2. **Reduce CI costs**. These cost savings can be significant for large test
34-
suites.
35-
3. **Free-up CI resources** for validating fixes, and helping other users.
29+
<AutoCancellationBenefits />
3630

3731
### Activate Auto Cancellation in Cypress Cloud
3832

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<Icon name="check-circle" color="green" /> **Benefits:** Stopping a test run on the
2+
first failure across parallelized machines will:
3+
4+
1. **Save time.** Identify failures early and resolve issues faster.
5+
2. **Reduce CI costs.** Cut down on unnecessary test execution, leading to significant savings for large test suites.
6+
3. **Free up CI resources.** Prioritize critical tests and keep CI pipelines available for validating fixes.
7+
4. **Optimize future runs.** With **[Spec Prioritization](/cloud/features/smart-orchestration/spec-prioritization)** and **Auto Cancellation**, failed tests run first in the next attempt, stopping early if issues persist to maximize efficiency.

src/theme/MDXComponents.js

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import MDXComponents from "@theme-original/MDXComponents";
33
import AnatomyOfAnError from "@site/docs/partials/_anatomy-of-an-error.mdx";
44
import AccessibilityAddon from "@site/docs/partials/_accessibility-addon.mdx";
5+
import AutoCancellationBenefits from "@site/docs/partials/_auto-cancellation-benefits.mdx";
56
import Badge from "@site/src/components/badge";
67
import Btn from "@site/src/components/button";
78
import ComponentOnlyBadge from "@site/src/components/component-only-badge";
@@ -160,6 +161,7 @@ export default {
160161
...MDXComponents,
161162
AnatomyOfAnError,
162163
AccessibilityAddon,
164+
AutoCancellationBenefits,
163165
Badge,
164166
Btn,
165167
ComponentOnlyBadge,
Loading
Loading

0 commit comments

Comments
 (0)