Cypress configuration
Cypress configs are located in cypress/cypress.config.js
. The following is the
configuration we use for most of the projects.
Browser
- chromeWebSecurity Enables Chromium-based browser's Web Security
for same-origin policy and insecure mixed content.
Set the value as false
, as some of specs we may write have to navigate to any
superdomain without cross-origin errors with or without cy.origin()
.
Retries
- runMode allows us to define the number of test retries when running
cypress run.
- openMode allows us to define the number of test retries when running
cypress open.
Set the value as 1
for both of them. By default the value is 0
. Do not
increase the value as that adds to the cost of running the tests on CI.
Timeouts
- execTimeout is the time, in milliseconds, to wait for a system command
to finish executing during a
cy.exec()
command.
- defaultCommandTimeout is the time in milliseconds, to wait until most
DOM based commands are considered timed out.
- requestTimeout is the time, in milliseconds, to wait for a request to go
out in a
cy.wait()
command.
- pageLoadTimeout is the time, in milliseconds, to wait for page
transition events or
cy.visit()
, cy.go()
, cy.reload()
commands to fire
their page load events.
- responseTimeout is the time, in milliseconds, to wait until a response
in a
cy.request()
, cy.wait()
, cy.fixture()
commands.
Set defaultCommandTimeout and requestTimeout to 5000
(5 seconds),
execTimeout to 1800000
(30 minutes), pageLoadTimeout to 40000
(40
seconds), requestTimeout to 10000
(10 seconds).
The values for these timeouts should not be increased to higher value as that
adds to our cost of running the tests on CI.
Viewport
- viewportHeight is the height in pixels for the application under tests'
viewport. Default value is
660
.
- viewportWidth is the width in pixels for the application under tests'
viewport. Default value is
1000
.
The values for these viewport differs from requirement and is set to 960
viewportHeight and 1200
viewportWidth in the config.
E2E Options
- setupNodeEvents is a function in which node events can be registered and
config can be modified. Used to setup Cypress plugins like @cypress/grep.
- baseURL is URL used as prefix for
cy.visit()
or cy.request()
command's URL.
- specPattern is the String or Array of glob patterns of the test files to
load.
- experimentalSessionAndOrigin is used to enable cross-origin and improved
session support, including the
cy.origin()
and cy.session()
commands. Only
available in end-to-end testing.
- experimentalRunAllSpecs is used to enable the "Run All Specs" UI
feature, allowing the execution of multiple specs sequentially.
There are also different config files that are used to override some options
based on development environment. The config files are:
cypress/cypress-test/config/cypress.development.json
cypress/cypress-test/config/cypress.review.json
cypress/cypress-test/config/cypress.staging.json
Project settings on cypress dashboard
Run failed specs first
It is often helpful to be aware of test failures earlier within a CI test run so
that debugging and iterations can resume and progress much faster. Being able to
catch issues sooner within the CI process can save valuable time in
troubleshooting failures and deploying fixes.
Enable this feature in Cypress dashboard by:
- Navigate to the project from cypress dashboard.
- Click "Project Settings" on the left sidebar.
- Scroll to the Smart Orchestration section.
- Toggle "Run failed specs first" on.
Cancel test run when a test fails
Continuous Integration (CI) pipelines are typically costly processes that can
demand significant compute time. When a test failure occurs in CI, it often does
not make sense to continue running the remainder of a test suite since the
process has to start again upon merging of subsequent fixes and other code
changes.
Enable this feature in Cypress dashboard by:
- Navigate to the project from cypress dashboard.
- Click "Project Settings" on the left sidebar.
- Scroll to the Smart Orchestration section.
- Toggle "Cancel run on test failure" on.