Files
cypress/docs/source/api/cypress-api/config.md
T
Jennifer Shehane 175fbc1e8d docs: fix 'description' in head / fix api page titles
- removed description from each api file since default is better
- fixed camelcase in api page titles
2017-06-07 12:30:40 -04:00

2.9 KiB

title, comments
title comments
Cypress.config true

get and set configuration options in your tests.

{% note info New to Cypress? %} Read about configuration first. {% endnote %}

Syntax

Cypress.config()
Cypress.config(name)
Cypress.config(name, value)
Cypress.config(object)

Usage

.config() requires being chained off Cypress.

{% fa fa-check-circle green %} Valid Usage

Cypress.config() // Get configuration options

{% fa fa-exclamation-triangle red %} Invalid Usage

cy.config()  // Errors, cannot be chained off 'cy'

Arguments

{% fa fa-angle-right %} name (String)

The name of the configuration to get or set.

{% fa fa-angle-right %} value (String)

The value of the configuration to set.

{% fa fa-angle-right %} object (Object)

Set multiple configuration options with an object literal.

Examples

No Arguments

Get all configuration options.

cypress.json

{
  "defaultCommandTimeout": 10000
}
Cypress.config() // => {defaultCommandTimeout: 10000, pageLoadTimeout: 30000, ...}

Name

Return just a single configuration option value.

cypress.json

{
  "pageLoadTimeout": 60000
}
Cypress.config("pageLoadTimeout") // => 60000

Name and Value

Cypress allows you to change the values of your configuration options from within your tests.

{% note warning %} Any value you change will be permanently changed for the remainder of your tests. {% endnote %}

cypress.json

{
  "viewportWidth": 1280,
  "viewportHeight": 720
}
Cypress.config("viewportWidth", 800)

Cypress.config("viewportWidth") // => 800

Using config to set baseUrl

{% note info %} Check out our example recipe where we reset our baseUrl using Cypress.config {% endnote %}

Object

You can set multiple values by passing an object literal.

cypress.json

{
  "defaultCommandTimeout": 4000,
  "pageLoadTimeout": 30000,
}
Cypress.config({
  defaultCommandTimeout: 10000,
  viewportHeight: 900
})

Cypress.config() // => {defaultCommandTimeout: 10000, viewportHeight: 900, ...}

Notes

Why use Cypress.config instead of cy.config?

As a rule of thumb anything you call from Cypress affects global state. Anything you call from cy affects local state.

Methods on cy are local and specific to a single test. Side effects from cy methods are restored between each test. We chose to use Cypress because changes to your configuration options take effect for the remainder of ALL tests.

See also