Features

Cypress Test Environment Variables

You can easily setup test environment variables to be used with Cypress and TestingBot Cypress CLI.


There are currently three ways to do this:

  1. Using the env option key in your Cypress configuration file
  2. Create a cypress.env.json file and specify your environment variables
  3. Use the --env CLI flag with testingbot-cypress

Cypress Configuration File

Cypress allows you to specify your environment variables in the cypress.json file, under the env option key.
You can learn more about this option in the Cypress Documentation.

"env": {
    "signup_url": "/signup",
    "pricing_url": "/pricing"
}

You can then access these values in Cypress with:

Cypress.env() // {signup_url: '/signup', pricing_url: '/pricing'}
Cypress.env('signup_url') // '/signup'
Cypress.env('pricing_url') // '/pricing'

cypress.env.json

You can also create your own cypress.env.json file.
TestingBot's Cypress CLI will send this together with your specs to instruct Cypress to use these environment variables.


Values in this file will overwrite conflicting environment variables in your cypress.json file.
See the Cypress env.json documentation.

{
    "host": "testingbot.com",
    "api": "api.testingbot.com"
}

You can then access these values in Cypress with:

Cypress.env() // {host: 'testingbot.com', api: 'api.testingbot.com'}
Cypress.env('host') // 'testingbot.com'
Cypress.env('api') // 'api.testingbot.com'

CLI Flag

You can also pass a comma-separated list of environment variables with the TestingBot Cypress CLI. We will pass these values to the Cypress Runner.


Argument Shorthand Argument Possible values
--env -e comma-separated environment variables

testingbot-cypress run --env host=testingbot.com,api=api.testingbot.com

You can then access these values in Cypress with:

Cypress.env() // {host: 'testingbot.com', api: 'api.testingbot.com'}
Cypress.env('host') // 'testingbot.com'
Cypress.env('api') // 'api.testingbot.com'
Cypress Environment Variables