This repository has been archived by the owner on Mar 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example with test retries built-in (#361)
- Loading branch information
Showing
4 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# test retries | ||
|
||
This plugin is compatible with Cypress [Test Retries](https://github.com/cypress-io/cypress/pull/3968). For example in [spec.js](spec.js) we fail the test on purpose until the desired UI happens | ||
|
||
```js | ||
const Hello = () => { | ||
// this is how you can get the current retry number | ||
// attempt 1: (first test execution) retry = 0 | ||
// attempt 2: (second test execution) retry = 1 | ||
// attempt 3: retry = 2, | ||
// etc | ||
const n = cy.state('test').currentRetry ? cy.state('test').currentRetry() : 0 | ||
return <div>retry {n}</div> | ||
} | ||
it('retries', { retries: 3 }, () => { | ||
mount(<Hello />) | ||
// now let's fail the test - it will retry several times and pass | ||
cy.contains('retry 3', { timeout: 1500 }) | ||
}) | ||
``` | ||
|
||
![Retries in action](images/retries.gif) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import React from 'react' | ||
import { mount } from 'cypress-react-unit-test' | ||
|
||
// test retries from | ||
// https://github.com/cypress-io/cypress/pull/3968 | ||
// you can skip the tests if there is no retries feature | ||
const describeOrSkip = Cypress.getTestRetries ? describe : describe.skip | ||
describeOrSkip('Test', () => { | ||
const Hello = () => { | ||
// this is how you can get the current retry number | ||
// attempt 1: (first test execution) retry = 0 | ||
// attempt 2: (second test execution) retry = 1 | ||
// attempt 3: retry = 2, | ||
// etc | ||
const n = cy.state('test').currentRetry | ||
? cy.state('test').currentRetry() | ||
: 0 | ||
return <div>retry {n}</div> | ||
} | ||
|
||
it('does not retry', { retries: 0 }, () => { | ||
mount(<Hello />) | ||
cy.contains('retry 0') | ||
|
||
// now let's fail the test - it won't retry it | ||
// enable manually to observe | ||
// cy.contains('retry 1') | ||
}) | ||
|
||
it('retries', { retries: 3 }, () => { | ||
mount(<Hello />) | ||
// now let's fail the test - it will retry several times and pass | ||
cy.contains('retry 3', { timeout: 1500 }) | ||
}) | ||
}) |