Member-only story
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.
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…