Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: 5.0.0 release docs test retries #2925

Merged
merged 35 commits into from
Aug 13, 2020
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
f52550c
docs: add test retries guide
bencodezen Jun 24, 2020
0d67dc0
docs: iterate on test retries docs
bencodezen Jun 26, 2020
f3c6961
Update source/guides/guides/test-retries.md
bencodezen Jun 29, 2020
f4715fa
docs: apply suggestions from Jen's code review
bencodezen Jun 29, 2020
e846f56
docs: add more improvements from Jen's code review
bencodezen Jun 29, 2020
0fe2373
docs: remove advice due to different behaviors
bencodezen Jun 29, 2020
f788560
docs: update test retries guide with screenshots and videos
bencodezen Jun 29, 2020
a4ae704
docs: optimize images
bencodezen Jun 29, 2020
cae8fb9
docs: add addendum on Cypress Dashboard
bencodezen Jun 29, 2020
d46eba1
Merge branch '5.0.0-release' into 5.0.0-release-docs-test-retries
jennifer-shehane Jun 30, 2020
19bba1f
add `retries` to allowed test config
jennifer-shehane Jun 30, 2020
c85345d
Add section to retry-ability doc mentioning that you can retry tests
jennifer-shehane Jun 30, 2020
91a7d19
Replace viewport example (which is broken) with retries example for t…
jennifer-shehane Jun 30, 2020
7f663a8
Add retries to config option
jennifer-shehane Jun 30, 2020
0b36b2f
docs: remove 5.0 specific version reference
bencodezen Jun 30, 2020
0452bf0
docs: add warning for before and after hooks
bencodezen Jun 30, 2020
9ac4277
docs: update sidebar with test retries for i18n
bencodezen Jul 1, 2020
c89ef17
docs: update hooks section based on Jen's feedback
bencodezen Jul 1, 2020
da40366
docs: update with new default of 0
bencodezen Aug 3, 2020
f772128
docs: add call to action for test retries at the bottom
bencodezen Aug 7, 2020
e0dc36e
docs: improve diction clarity
bencodezen Aug 7, 2020
ae7339e
Add section at top of retry-ability directing them to test retries
jennifer-shehane Aug 10, 2020
76baa16
Minor updates (see commit description)
jennifer-shehane Aug 10, 2020
3fd3b93
Update screenshot area to be explicit about why there are 6 screenshots
jennifer-shehane Aug 10, 2020
61c5731
Merge branch '5.0.0-release' into 5.0.0-release-docs-test-retries
jennifer-shehane Aug 10, 2020
04bc9ca
Commit recommendations from Ben's PR review
jennifer-shehane Aug 11, 2020
e580697
Merge branch '5.0.0-release' into 5.0.0-release-docs-test-retries
jennifer-shehane Aug 11, 2020
7ed0b1b
docs: remove strategies piece
bencodezen Aug 11, 2020
003b66f
docs: clarify meaning
bencodezen Aug 11, 2020
18b6a61
docs: make phrasing more accurate
bencodezen Aug 11, 2020
5fa4c6e
docs: add specific image name
bencodezen Aug 11, 2020
e123836
docs: show custom screenshot name in action
bencodezen Aug 11, 2020
28fd374
docs: standardize reference to retry attempts
bencodezen Aug 11, 2020
7c9ad73
docs: fix grammatical plural
bencodezen Aug 11, 2020
fd0a994
docs: centralize phrasing on retry attempts
bencodezen Aug 11, 2020
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
1 change: 1 addition & 0 deletions source/_data/sidebar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ guides:
module-api: module-api.html
debugging: debugging.html
network-requests: network-requests.html
test-retries: test-retries.html
continuous-integration: continuous-integration.html
parallelization: parallelization.html
environment-variables: environment-variables.html
Expand Down
192 changes: 192 additions & 0 deletions source/guides/guides/test-retries.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
---
title: Test Retries
---

{% note info %}
# {% fa fa-graduation-cap %} What you'll learn

- What are test retries?
- Why is test retries important?
bencodezen marked this conversation as resolved.
Show resolved Hide resolved
- How to configure test retries
{% endnote %}

## Introduction

End-to-end (E2E) tests excel at testing complex systems. However, there are still behaviors that are difficult to verify and make tests unintentionally flaky (i.e., unreliable) and fail intermittently due to unpredictable conditions (eg., temporary outages in external dependencies, random network errors, etc.) Some other common race conditions that could result in unreliable tests include:

- Animations
- API calls
- Test server / database availability
- Resource dependencies availability
- Network issues

With the new test retries feature, Cypress (5.0+) will be able to retry failed tests to help reduce test flakiness and continuous integration (CI) build failures. By doing so, this will save your team valuable time and resources so you can focus on what matters most to you.

## How It Works

As of Cypress 5.0, test retries are on by default in `cypress run` mode. This means that tests will automatically be re-run up to two additional times (for a total of three attempts) before being marked as a failed test. When each test is run again, the following lifecycle hooks will be re-run on each attempt:

- `beforeEach`
- `afterEach`

bencodezen marked this conversation as resolved.
Show resolved Hide resolved
The following is a detailed step-by-step example of how test retries will work:

1. A test runs for the first time. If the test passes, Cypress will move forward with any remaining tests as expected.

2. If the test fails, Cypress will inform you that the first attempt failed and will attempt to run the test a second time.

{% img /img/guides/test-retries/attempt-2-start.png %}

3. If the test passes after the second try, Cypress will continue with any remaining tests.

4. If it fails a second time, it will make the final third attempt to re-run the test.

{% img /img/guides/test-retries/attempt-3-start.png %}

5. If the test fails a third time, Cypress will mark the test as failed and then proceed with any remaining tests.

{% img /img/guides/test-retries/attempt-3-fail.png %}

The following is a screen capture of what test retries looks like on the same failed test when running `cypress run`.

{% img /img/guides/test-retries/cli-error-message.png %}

In addition, you will be able to see the number of attempts made in the Command Log and expand each attempt for further inspection and debugging if desired.

{% video local /img/guides/test-retries/attempt-expand-collapse-time-travel.mp4 %}

## Configuring Test Retries

If any tests fail, they will be automatically:

- Retried up to 2 times (for a total of 3 attempts) in `cypress run` mode
- Run normally with no retries in `cypress open` mode

The reason for this distinction is to avoid wasting developer time by preventing unnecessary runs while a test is being worked on.


### Global Configuration

If you need to change the number of attempts being made across your entire test suite for both `cypress run` and `cypress open`, you can configure this in your {% url "configuration file" command-line#cypress-open-config-file-lt-config-file-gt %} (`cypress.json` by default) by defining the `retries` property and giving it the desired number.

```jsx
{
"retries": 1
}
```
jennifer-shehane marked this conversation as resolved.
Show resolved Hide resolved

#### Disable Test Retries

If you would like to disable test retries, you can use the global configuration to do so by setting it to 0.

```jsx
{
"retries": 0
}
```

#### Configuring Specific Retries for Different Modes

However, in the event you need to define unique retry attempts for the different modes of Cypress, you can pass the `retries` option an object with the following options:

- `runMode` allows you to define the number of test retries when running `cypress run`
- `openMode` allows you to define the number of test retries when running `cypress open`

```jsx
{
"retries": {
// Configure retries for `cypress run`
// Default is 2
"runMode": 1,
// Configure retries for `cypress open`
// Default is 0
"openMode": 3
}
}
```
jennifer-shehane marked this conversation as resolved.
Show resolved Hide resolved

### Custom Configurations

#### Individual Test(s)

In the event a specific test requires a custom number of test retries configured, this can be achieved by using the test's configuration option.

```jsx
// Customizing retries for an individual test
describe('User sign-up and login', () => {
// `it` test block with no custom configuration
it('should redirect unauthenticated user to sign-in page', () => {
// ...
})

// `it` test block with custom configuration
it('allows user to login', {
retries: {
runMode: 3,
openMode: 2
}
}, () => {
// ...
})
})
```

#### Test Suite(s)

If you want a suite of tests to re-run a custom number of times, this can be achieved by using the suite's configuration option.

```jsx
// Customizing retries for a suite of tests
describe('User bank accounts', {
retries: {
runMode: 3,
openMode: 1,
}
}, () => {
// Individual tests will be run normally
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// Individual tests will be run normally

What? I'm confused, won't any test inside of the suite retry if it fails now that I said to retry 3 times? Why does it say they 'run normally'?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still confused by this comment. Can you clarify what it means by 'individual test will be run normally' - as I understand it all tests in the suite will have 3 attempts in run mode here.

bencodezen marked this conversation as resolved.
Show resolved Hide resolved
it('allows a user to view their transactions, () => {
// ...
}

it('allows a user to edit their transactions, () => {
// ...
}
})

```

You can find more information about custom configurations here: {% url "Test Configuration" configuration#Test-Configuration %}

## Screenshots and Videos

With test retries, Cypress will now generate any screenshots and videos per each test attempt. These will be properly labeled with the attempt number appended at the end of each filename.

```js
// Example file names
'User Sign-up and Login -- should display login errors.png'
'User Sign-up and Login -- should display login errors (failed).png'
'User Sign-up and Login -- should display login errors (attempt 2).png'
'User Sign-up and Login -- should display login errors (failed) (attempt 2).png'
'User Sign-up and Login -- should display login errors (attempt 3).png'
'User Sign-up and Login -- should display login errors (failed) (attempt 3).png'
jennifer-shehane marked this conversation as resolved.
Show resolved Hide resolved
```

## Dashboard

If you are using {% url "Cypress Dashboard" dashboard %}, test retries will not change your current experience at this time. However, if you are interested in future enhancements coming to the Dashboard experience, be sure to check out our {% url "product roadmap" https://cypress-io.productboard.com/roadmap/1238172-product-roadmap %}.

## Tips and Strategies

While test retries are great for helping to avoid false negatives from failing an entire test run, it is not a good replacement for writing good tests. As a result, here are some tips and strategies to keep in mind in order to maximize the effectiveness of your tests with test retries:

- If you are noticing that you need to increase the number of retries, the cause is more likely due to how the tests are written and is worth spending the time to investigate.

## Frequently Asked Questions (FAQs)

### Will retried tests be counted as more than one test recording in my billing?

No. Tests recorded during `cypress run` with the `--record` flag will be counted the same with or without test retries.

We consider each time the `it()` function is called to be a single test for billing purposes. The test retrying will not count as extra test recordings in your billing.

You can always see how many tests you’ve recorded from your organization’s Billing & Usage page within the {% url "Dashboard" https://on.cypress.io/dashboard %}.
1 change: 1 addition & 0 deletions themes/cypress/languages/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ sidebar:
parallelization: Parallelization
environment-variables: Environment Variables
launching-browsers: Launching Browsers
test-retries: Test Retries
cross-browser-testing: Cross Browser Testing
custom-commands: Custom Commands
web-security: Web Security
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.