When writing tests, it's all very good running them against your local build, however, this does not stop your website falling over, or, your staging environment from breaking. When writing end-to-end tests you will likely want to run them against multiple different environments, maybe triggered after a successful deployment to an environment, or nightly in the early days just to make sure your environments are still working as expected. There are several different ways you can configure your project; in today's tutorial, I will share my preferred approach. Sound good?
All the Config?
As Cypress is installed via NPM, after a successful installation, if you look within the project you should see a file called Cypress.json. Cypress.json is the file to update for all global settings. What it really wants to do is create a config file for each environment.
First, in your solution create a folder called 'config' or something similar. Copy your cypress.json file and create a new file for each environment you want to configure. So cypress.prod.json, cypress.stg.json etc.... Your config file might look similar to this:
Now you have some specific config files and a way to load the correct file before your tests run, the last part is to create some scrips within your package.json file for each environment you want to test, like so:
With these three bits of the puzzle solved, you can now run your integration tests against as many environments are you like, enjoy!