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 1 commit
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 @@ -30,6 +30,7 @@ guides:
network-requests: network-requests.html
continuous-integration: continuous-integration.html
parallelization: parallelization.html
test-retries: test-retries.html
environment-variables: environment-variables.html
stubs-spies-and-clocks: stubs-spies-and-clocks.html
screenshots-and-videos: screenshots-and-videos.html
Expand Down
185 changes: 185 additions & 0 deletions source/guides/guides/test-retries.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
---
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

A scenario that often comes up when running end-to-end (E2E) tests is that tests may be unintentionally flaky (i.e., unreliable) and fail intermittently. For example, because E2E tests often involves multiple integrations, it is not uncommon to have services that have intermittent outages. Some other common race conditions that could result in unreliable tests include:

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

Just like an average user, if they run into an error when loading your application, you would want them to refresh and try again before submitting a bug report. However, without test retries, this often resulted in random failed tests and broken continuous integration (CI) build fails which are a waste of resources. As a result, rather than fail the entire test run, Cypress 5.0 introduces native test retries.
bencodezen marked this conversation as resolved.
Show resolved Hide resolved

## How It Works

By default, tests being run in `cypress run` mode will automatically be retried 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:
bencodezen marked this conversation as resolved.
Show resolved Hide resolved

- `before`
- `beforeEach`
- `afterEach`
- `after`

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 by default:
bencodezen marked this conversation as resolved.
Show resolved Hide resolved

1. A test runs for the first time. If it passes, Cypress will move forward with any remaining tests as expected.
bencodezen marked this conversation as resolved.
Show resolved Hide resolved

🖼 Insert screenshot

2. If the test fails, it will inform users that the first attempt failed and it will attempt to run the test a second time.
bencodezen marked this conversation as resolved.
Show resolved Hide resolved

🖼 Insert screenshot

3. If the test succeed after the second try, Cypress will continue with any remaining tests.
bencodezen marked this conversation as resolved.
Show resolved Hide resolved

🖼 Insert screenshot

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

Choose a reason for hiding this comment

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

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


🖼 Insert screenshot

5. If it fails a third time, Cypress will make the test as failed and then proceed with any remaining tests.
bencodezen marked this conversation as resolved.
Show resolved Hide resolved

🖼 Insert screenshot

The following is a screen capture of what test retries looks like on a failed test.

🖼 Insert screenshot

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.

🖼 Insert screenshot

## Configuring Test Retries

Starting with Cypress 5.0, if any tests fail, they will be automatically:
bencodezen marked this conversation as resolved.
Show resolved Hide resolved

- Retried up to two times (for a total of three attempts) in `cypress run` mode
bencodezen marked this conversation as resolved.
Show resolved Hide resolved
- Run normally with no retries in `cypress open` mode

The reason for this distinction is to avoid adding unnecessary

retried up to two times (for a total of three attempts) in with no additional configuration needed. When developing locally with Cypress' Open Mode, test retries is disabled by default to prevent blocking developers with unnecessary retries.
Copy link
Member

Choose a reason for hiding this comment

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

what happened here?


If you need more information on how to migrate to 5.x, please see our official migration guide here.
bencodezen marked this conversation as resolved.
Show resolved Hide resolved

### 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 `cypress.json` by defining the `retries` property and giving it the desired number.
bencodezen marked this conversation as resolved.
Show resolved Hide resolved

```jsx
{
"retries": 1
}
```

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 local configuration option.
bencodezen marked this conversation as resolved.
Show resolved Hide resolved

```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', () => {
...
bencodezen marked this conversation as resolved.
Show resolved Hide resolved
})

// `it` test block with custom configuration
it('allows user to login', {
retries: {
runMode: 3,
openMode: 2
}
}, () => {
...
bencodezen marked this conversation as resolved.
Show resolved Hide resolved
})
})

bencodezen marked this conversation as resolved.
Show resolved Hide resolved
```

#### Test Suite(s)

If you want a suite of tests to re-run in requires a custom number of test retries configured, this can be achieved by using the test's local configuration option
bencodezen marked this conversation as resolved.
Show resolved Hide resolved

```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, () => {
...
bencodezen marked this conversation as resolved.
Show resolved Hide resolved
}

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

```

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

## Assets
bencodezen marked this conversation as resolved.
Show resolved Hide resolved

With test retries, Cypress will now generate any assets (i.e., screenshots, video recordings, etc.) per each test attempt. The assets will be properly labeled with the attempt number appended at the end of each asset.
bencodezen marked this conversation as resolved.
Show resolved Hide resolved

🖼 Insert screenshot

## 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, this cause is more likely due to how the tests are written and is worth spending the time to investigate
bencodezen marked this conversation as resolved.
Show resolved Hide resolved
- If you use `Run all specs` a lot in `cypress open` mode, make sure to configure your Cypress instance to have a global `retries` of `2` so you can simulate what is being run in `cypress run` mode.
bencodezen marked this conversation as resolved.
Show resolved Hide resolved
bencodezen marked this conversation as resolved.
Show resolved Hide resolved

## Frequently Asked Questions (FAQs)

#### Will runs with test retries be counted as more than one run?

No. When recording to the Cypress Dashboard, runs with test retries will be counted as a single run.
bencodezen marked this conversation as resolved.
Show resolved Hide resolved


{% note warning 'Firefox Garbage Collection' %}
Cypress triggers Firefox's internal garbage collection (GC) to better manage the browser's memory consumption. {% url "Learn more here" configuration#firefoxGcInterval %}.
{% endnote %}

Excluding {% url "Electron" launching-browsers#Electron-Browser %}, any browser you want to run Cypress tests in needs to be installed on your local system or CI environment. A full list of detected browsers is displayed within the browser selection menu of the {% url "Test Runner" test-runner %}.

{% imgTag /img/guides/cross-browser-testing/cypress-browser-selector.png "Cypress Test Runner with Firefox selected as the browser" "no-border" %}
bencodezen marked this conversation as resolved.
Show resolved Hide resolved

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