For AI agents and LLMs: a machine-readable index is available at llms.txt. A plain-Markdown version of any documentation page is available by appending .md to its URL.
Skip to main content

Environment Variables Support for Cypress Tests


You can specify the environment variables that you want to use for your Cypress tests via the configuration file, via the cypress.env.json file, or via the TestMu AI Cypress CLI. However, if we set environment variables via both TestMu AI CLI and cypress.env.json, the cypress.env.json file will be ignored and only the variables set via CLI will be set into environment variables. If you want to understand these methods, go through the document below.

1. Via the Configuration File​

a. Cypress 9

A sample cypress.json file:

Verified
{
......
"env":{
"CYPRESS_BASE_URL":"https://example.cypress.io/",
"ACTIONS_URL": "commands/actions",
"WINDOW_URL": "commands/window"
},
......
}

b. Cypress 10

A sample cypress.config.js file:

Verified
module.exports = defineConfig({
env: {
'CYPRESS_BASE_URL':'https://example.cypress.io/',
'ACTIONS_URL' : 'commands/actions',
'WINDOW_URL': 'commands/window'
},

You can use both of these in your test specifications file. An example of a test specifications file is:

Verified
describe('Sample test', () => {
it('test case - actions', () => {
cy.visit(Cypress.env('CYPRESS_BASE_URL') + Cypress.env('ACTIONS_URL'))
cy.wait(3000)
})
it('test case - window', () => {
cy.visit(Cypress.env('CYPRESS_BASE_URL') + Cypress.env('WINDOW_URL'))
cy.wait(3000)
})
})

2. Via the cypress.env.json File​

Verified
{
"CYPRESS_BASE_URL":"https://example.cypress.io/",
"ACTIONS_URL" : "commands/actions",
"WINDOW_URL": "commands/window"
}

3. Via the TestMu AI Cypress CLI​

You can also add your environment variables via the parameter --envs in the TestMu AI Cypress CLI.

Verified
lambdatest-cypress run --envs "CYPRESS_BASE_URL=https://example.cypress.io/,ACTIONS_URL=commands/actions,WINDOW_URL=commands/window"

Terminal First Testing With Kane CLI

Natural language browser & mobile app tests right from terminal.

×
Schedule Your Personal Demo
Kane CLI terminal

Help and Support

Related Articles