Member-only story

Running Cypress against multiple environments

Kristijan
2 min readJul 2, 2020

If you are using Cypress, chances are you have your application deployed to multiple different environments. Those might be development, testing, and production. Sometimes, there might be many more environments. But you want to test and ensure they all work correctly. This post is my way of structuring tests to be able to run them against different environments painlessly.

Cypress logo

Running tests

I am starting with this top to bottom. How do we want to run it? The easiest way is to pass environment selection trough CLI. There is the env flag that you can use to pass data and that data is accessible in tests. This flag is something I am using for environment selection.

Example:

cypress run — env environment=development

The environment is the key we are using, and development is value. But we can pass any number of values as strings.

If you are running tests as npm command, it is similar but slightly different. Before passing CLI arguments, you need to add two more dashes.

Example:

npm run cypress:run — — env environment=development

Values for environments

Data required for tests are in the fixtures folder by convention. And this is where I keep URL…

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Responses (1)

What are your thoughts?

Cy.fixtures should instead be cy.fixture
I also had issues with cy.visit(domains[env]); that I couldn't resolve, but a great jumping off point for setting environment variables

1