Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/api/cypress-api/stop.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ To ensure tests stop immediately after a failure across any spec file, add the f
afterEach(function () {
if (this.currentTest.state === 'failed') {
Cypress.stop()
return
}
})
```
Expand All @@ -45,12 +46,22 @@ beforeEach(() => {
if (env !== 'expected-condition') {
cy.log('Stop tests - environment is not setup correctly')
Cypress.stop()
return
}
})
```

## Notes

Calling `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:

```javascript
if (someCondition) {
Cypress.stop()
return // Prevents further code execution in this block
}
```

### `cypress run` vs `cypress open` behavior

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.
Expand Down