Specify environment variables for tests

Learn how to specify environment variables on BrowserStack for your tests

You can specify the environment variables for your tests (using Cypress.env) while running them on BrowserStack in the following ways:

  1. Using the env key in your Cypress config file
  2. Creating a cypress.env.json file as supported by Cypress
  3. Using the --env param of our CLI

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.

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": "http://localhost:8888/api/v1/"
}

Using the CLI

You can pass the environment variables for your tests using the --env argument while running your tests on BrowserStack using the run command. This is similar to Cypress’ --env option. Learn more about it on Cypress docs.

For example:

Command Line
browserstack-cypress run --sync --env api_host=http://example.com,products_api_path=/api/v1/products.json

We're sorry to hear that. Please share your feedback so we can do better







Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked






Thank you for your valuable feedback

Is this page helping you?

Yes
No

We're sorry to hear that. Please share your feedback so we can do better







Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked






Thank you for your valuable feedback!

Talk to an Expert
Talk to an Expert