Learn how to specify environment variables on BrowserStack for your Cypress tests
We support the following ways of specifying environment variables for your Cypress tests:
- Using the
envkey in yourcypress.jsonconfig file - Creating a
cypress.env.jsonfile as supported by Cypress - Using the
--envparam of our CLI - Defining environment variables starting with
CYPRESS_in your system - Specifying environment variables in a
.envfile and using dotenv npm package to read the values - Setting any system level environment variable in your/CI system and using the same in your Cypress tests
Using your Cypress config file
Any key/value you set in your Cypress configuration file (cypress.json by default) under the env key will become an environment variable that you can access using Cypress.env in your tests.
Learn more about this option on Cypress docs.
For example:
cypress.json
{
...
"env": {
"login_url": "/login",
"products_url": "/products",
}
}
Using the cypress.env.json file
You can create your own cypress.env.json file that Cypress will automatically check. Values in here will overwrite conflicting environment variables in your configuration file (cypress.json by default). Learn more about this option on Cypress docs.
For example:
cypress.env.json
{
"host": "veronica.dev.local",
"api_server": ""
}