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 27 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
1 change: 1 addition & 0 deletions source/_partial/allowed_test_config.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- `env`
- `requestTimeout`
- `responseTimeout`
- `retries`
- `viewportHeight`
- `viewportWidth`
- `waitForAnimations`
5 changes: 5 additions & 0 deletions source/guides/core-concepts/retry-ability.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ title: Retry-ability

A core feature of Cypress that assists with testing dynamic web applications is retry-ability. Like a good transmission in a car, it usually works without you noticing it. But understanding how it works will help you write faster tests with fewer run-time surprises.

{% note info "Test Retries" %}
If you are looking to retry tests a configured number of times when the test fails, check out our official guide on {% url "Test Retries" test-retries %}.
{% endnote %}

# Commands vs assertions

There are two types of methods you can call in your Cypress tests: **commands** and **assertions**. For example, there are 6 commands and 2 assertions in the test below.
Expand Down Expand Up @@ -436,3 +440,4 @@ Watch the short video below to see this example in action
- You can add retry-ability to your own {% url "custom commands" custom-commands %}; see {% url 'this pull request to cypress-xpath' https://github.com/cypress-io/cypress-xpath/pull/12/files %} for an example.
- You can retry any function with attached assertions using this 3rd party plugin {% url cypress-pipe https://github.com/NicholasBoll/cypress-pipe %}.
- See retry-ability examples in the {% url "Cypress should callback" https://glebbahmutov.com/blog/cypress-should-callback/ %} blog post.
- To learn how to enable Cypress' test retries functionality, which retries tests that fail up to the configured number, check out our official guide on {% url "Test Retries" test-retries %}.
34 changes: 20 additions & 14 deletions source/guides/core-concepts/writing-and-organizing-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -331,33 +331,39 @@ specify(name, config, fn)

{% partial allowed_test_config %}

### Suite of test configuration
### Suite configuration

You can configure the size of the viewport height and width within a suite.
If you want to target a suite of tests to run or be excluded when run in a specific browser, you can override the `browser` configuration within the suite configuration. The `browser` option accepts the same arguments as {% url "`Cypress.isBrowser()`" isbrowser %}.

```js
describe('page display on medium size screen', {
viewportHeight: 1000,
viewportWidth: 400
}, () => {
it('does not display sidebar', () => {
cy.get('#sidebar').should('not.be.visible')
describe('When in Chrome', { browser: '!chrome' } () => {
it('Shows warning', () => {
cy.get('.browser-warning')
.should('contain', 'For optimal viewing, use Chrome browser')
})

it('shows hamburger menu', () => {
cy.get('#header').find('i.menu').should('be.visible')
it('Links to browser compatibility doc', () => {
cy.get('a.browser-compat')
.should('have.attr', 'href')
.and('include', 'browser-compatibility)
})
})
```

### Single test configuration

If you want to target a test to run or be excluded when run in a specific browser, you can override the `browser` configuration within the test configuration. The `browser` option accepts the same arguments as {% url "`Cypress.isBrowser()`" isbrowser %}.
You can configure the number of times to retry a test if they fail during `cypress run` or `cypress open` separately. See {% url "Test Retries" test-retries %} for more information.
bencodezen marked this conversation as resolved.
Show resolved Hide resolved

```js
it('Show warning outside Chrome', { browser: '!chrome' }, () => {
cy.get('.browser-warning')
.should('contain', 'For optimal viewing, use Chrome browser')
it('should redirect unauthenticated user to sign-in page', {
retries: {
runMode: 3,
openMode: 2
}
} () => {
cy.visit('/')
// ...
})
})
```

Expand Down
200 changes: 200 additions & 0 deletions source/guides/guides/test-retries.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
---
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 hard to verify and make tests flaky (i.e., unreliable) and fail sometimes 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 test retries, Cypress is 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

By default, tests will not retry when they fail. You will need to {% urlHash "enable test retries in your configuration" Configure-Test-Retries %} to use this feature.

When test retries is on, tests will automatically be retried up to X additional times based on your desired configuration. For example, if test retries is set to `2`, Cypress will retry tests up to 2 additional times (for a total of 3 attempts) before potentially being marked as a failed test.

When each test is run again, the following {% url "hooks" writing-and-organizing-tests#Hooks %} will be re-run also:

- `beforeEach`
- `afterEach`

bencodezen marked this conversation as resolved.
Show resolved Hide resolved
{% note warning %}
However, failures in `before` and `after` hooks will not trigger a retry.
{% endnote %}

**The following is a detailed step-by-step example of how test retries works:**

Assuming we have set test retries to `2` (for a total of 3 attempts), the following is how the tests would run.

1. A test runs for the first time. If the {% fa fa-check-circle green %} test passes, Cypress will move forward with any remaining tests as usual.

2. If the {% fa fa-times red %} test fails, Cypress will tell you that the first attempt failed and will to run the test a second time.

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

3. If the {% fa fa-check-circle green %} test passes after the second attempt, Cypress will continue with any remaining tests.

4. If the {% fa fa-times red %} test fails a second time, Cypress will make the final third attempt to re-run the test.

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

5. If the {% fa fa-times red %} test fails a third time, Cypress will mark the test as failed and then move on to run 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 run via {% url "`cypress run`" command-line#cypress-run %}.

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

During {% url "`cypress open`" command-line#cypress-open %} you will be able to see the number of attempts made in the {% url "Command Log" test-runner#Command-Log %} and expand each attempt for review and debugging if desired.

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

# Configure Test Retries

## Global Configuration

Typically you will want to define different retry attempts for `cypress run` versus `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 passing 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 0
"runMode": 2,
// Configure retries for `cypress open`
// Default is 0
"openMode": 0
}
}
```

### Configure specific retries for all modes

If you want to change the number of attempts being made for all tests run 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 setting the desired number of retries.

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

## Custom Configurations

### Individual Test(s)

If you want a specific test to run a custom number of retries, you can set this by using the {% url "test's configuration" writing-and-organizing-tests#Test-Configuration %}.
bencodezen marked this conversation as resolved.
Show resolved Hide resolved

```jsx
// Customize 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: 2,
openMode: 1
}
}, () => {
// ...
})
})
```

### Test Suite(s)

If you want a suite of tests to re-run a custom number of times, you can do this by setting the suite's configuration.

```jsx
// Customizing retries for a suite of tests
describe('User bank accounts', {
retries: {
runMode: 2,
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
jennifer-shehane marked this conversation as resolved.
Show resolved Hide resolved

When a test retries, Cypress will continue to take screenshots for each failed attempt or {% url "`cy.screenshot()`" screenshot %} and suffix each new screenshot with `(attempt n)`, corresponding to the current test attempt number.

With the following test code, you would see the below screenshot filenames when all 3 attempts fail:

```js
describe('User Login', () => {
it('displays login errors', () => {
cy.visit('/')
cy.screenshot()
// ...
})
bencodezen marked this conversation as resolved.
Show resolved Hide resolved
})
```

```js
// screenshot filename from cy.screenshot() on 1st attempt
'User Login -- displays login errors.png'
// screenshot filename on 1st failed attempt
'User Login -- displays login errors (failed).png'
// screenshot filename from cy.screenshot() on 2nd attempt
'User Login -- displays login errors (attempt 2).png'
// screenshot filename on 2nd failed attempt
'User Login -- displays login errors (failed) (attempt 2).png'
// screenshot filename from cy.screenshot() on 3rd attempt
'User Login -- displays login errors (attempt 3).png'
// screenshot filename on 3rd failed attempt
'User Login -- displays login errors (failed) (attempt 3).png'
bencodezen marked this conversation as resolved.
Show resolved Hide resolved
```

# Dashboard

If you are using the {% url "Cypress Dashboard" dashboard %}, information related to test retries is not currently shown. Showing this information and other analytics related to test retries is on 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. 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.
bencodezen marked this conversation as resolved.
Show resolved Hide resolved

# 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 %}.
20 changes: 12 additions & 8 deletions source/guides/references/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Option | Default | Description
`port` | `null` | Port used to host Cypress. Normally this is a randomly generated port
`reporter` | `spec` | The {% url 'reporter' reporters %} used during `cypress run`
`reporterOptions` | `null` | The {% url 'reporter options' reporters#Reporter-Options %} used. Supported options depend on the reporter.
`retries` | `{ "runMode": 0, "openMode": 0 }` | The number of times to retry a failing test. Can be configured to apply to `cypress run` or `cypress open` separately. See {% url "Test Retries" test-retries %} for more information.
`watchForFileChanges` | `true` | Whether Cypress will watch and restart tests on test file changes

## Timeouts
Expand Down Expand Up @@ -216,19 +217,21 @@ The configuration values passed in will only take effect during the suite or tes

### Suite configuration

You can configure the size of the viewport height and width within a suite.
You can configure the number of times to retries a suite of tests if they fail during `cypress run` and `cypress open` separately.

```js
describe('page display on medium size screen', {
viewportHeight: 1000,
viewportWidth: 400
describe('login', {
retries: {
runMode: 3,
openMode: 2
}
}, () => {
it('does not display sidebar', () => {
cy.get('#sidebar').should('not.be.visible')
it('should redirect unauthenticated user to sign-in page', () => {
// ...
})

it('shows hamburger menu', () => {
cy.get('#header').find('i.menu').should('be.visible')
it('allows user to login', () => {
// ...
})
jennifer-shehane marked this conversation as resolved.
Show resolved Hide resolved
})
```
Expand Down Expand Up @@ -395,6 +398,7 @@ Run GC cleanup before every 3rd test during {% url "`cypress run`" command-line#
IntelliSense is available for Cypress while editing your configuration file. {% url "Learn how to set up Intelligent Code Completion." IDE-integration#Intelligent-Code-Completion %}

{% history %}
{% url "5.0.0" changelog %} | Added `retries` configuration.
{% url "5.0.0" changelog %} | Renamed `blacklistHosts` configuration to `blockHosts`.
{% url "4.1.0" changelog#4-12-0 %} | Added `screenshotOnRunFailure` configuration.
{% url "4.0.0" changelog#4-0-0 %} | Added `firefoxGcInterval` configuration.
Expand Down
1 change: 1 addition & 0 deletions themes/cypress/languages/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ sidebar:
screenshots-and-videos: Screenshots and Videos
guides: Guides
command-line: Command Line
test-retries: Test Retries
continuous-integration: Continuous Integration
parallelization: Parallelization
environment-variables: Environment Variables
Expand Down
1 change: 1 addition & 0 deletions themes/cypress/languages/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ sidebar:
screenshots-and-videos: Capturas de pantalla y videos
guides: Guías
command-line: Línea de comandos
test-retries: Test Retries
continuous-integration: Integración Continua
parallelization: Paralelización
environment-variables: Variables de entorno
Expand Down
1 change: 1 addition & 0 deletions themes/cypress/languages/ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ sidebar:
screenshots-and-videos: スクリーンショットとビデオ
guides: ガイド
command-line: コマンドライン
test-retries: Test Retries
continuous-integration: 継続的インテグレーション
parallelization: Parallelization
environment-variables: 環境変数
Expand Down
1 change: 1 addition & 0 deletions themes/cypress/languages/pt-br.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ sidebar:
screenshots-and-videos: Screenshots e Vídeos
guides: Guias
command-line: Linha de Comando
test-retries: Test Retries
continuous-integration: Integração Contínua
parallelization: Paralelização
environment-variables: Variáveis de Ambiente
Expand Down
1 change: 1 addition & 0 deletions themes/cypress/languages/ru.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ sidebar:
screenshots-and-videos: Скриншоты и видео
guides: Руководства
command-line: Командная строка
test-retries: Test Retries
continuous-integration: Непрерывная интеграция
parallelization: Параллелизация
environment-variables: Переменные среды
Expand Down
1 change: 1 addition & 0 deletions themes/cypress/languages/zh-cn.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ sidebar:
screenshots-and-videos: 截图和视频
guides: 指南
command-line: 命令行
test-retries: Test Retries
continuous-integration: 持续集成
parallelization: 并行化
environment-variables: 环境变量
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.