Files
cypress/docs/source/api/cypress-api/config.md
T
2017-05-15 14:10:01 -04:00

2.7 KiB

title: config comments: true

Cypress.config allows you to get and set your configuration options.

This document covers the API for consuming your configuration options in your tests.

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

Cypress.config()

Returns all of your configuration options as an object literal.


Cypress.config( key )

Returns the value of a single configuration option by its key.


Cypress.config( key, value )

Sets a configuration option for a specific key.


Cypress.config( object )

Sets multiple configuration options.


No Arguments Usage

Get all configuration options.

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

Key Usage

Return just a single configuration option value.

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

Key Value Usage

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

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


Object Usage

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.


Related