Cypress How to store global constants in a file that can be used across all spec files?

Ryan Parker picture Ryan Parker · Apr 6, 2018 · Viewed 16.4k times · Source

I'm looking for a way to store global constants in a file that could be used across all my spec files. Can anyone help?

Answer

TJH picture TJH · Apr 9, 2018

Use the cypress.json file that is in your project root like this:

{
    "env": {
        "your_var": "your_value"
    }
}

https://docs.cypress.io/guides/references/configuration.html

Once you set some env variables, you can reference them from your specs like this: Cypress.env('your_var');