Running the same tests for different user types using multiple config files
In the Determ app, each user organization can have a different pricing plan. Different pricing plans mean that some users can use some features while others can’t. You can check out the detailed feature description for each plan here – pricing.
Recently we changed our pricing plan structure. This means we needed to check every feature for users in each pricing plan. This included running all the same tests and test cases for users in each pricing plan.
Read How to Read Emails in Cypress
How did the multiple config files help?
In our Cypress automated tests, we use the access token, organization id, and query id parameters for logging in and visiting pages to which the logged-in user has access. These parameters are different for each user. If you want to run a test with a different user, you need to change all the parameters or write a different test for each user. We didn’t want to change these every time inside the test code. So, we made config files for each user where we can store their access token, organization id, and query id. This way, when we wanted to run a set of tests for a user with the “Agency” price plan, we’d run the config file we made for that particular user. Nevertheless, in the config file, you can exclude the tests that are unrelated to that user and don’t want to run at all.
By running these tests for different users on different price plans, we validate if a particular user should or shouldn’t have access to the features available in their pricing plan. That way, you can check all the features for one user in a few minutes.
Creating and Running New Config Files
The easiest and safest way to create a new config file is to duplicate the existing Cypress config file (“cypress.config.js). Then, change its name to something new, for example, cypress.development.config.js, and configure it as you wish.
You can run your tests with different config files by running your standard command with added “–config-file” flag and the path to the config file. For example, “cypress run –config-file configs/cypress.individualplan.config.js”
Another way, and a much better way, is by setting a reference in your package.json file with a unique command:
Other use cases
Another use case for our app is running the same tests for different user roles inside one organization. For us, inside one organization, you can be Admin, Analyst, Editor, or just a Viewer. However, much broader use cases are running your tests in different environments so you can have development, staging, and production config files. Or, for example, you can have a config file with a different resolution set up if you want to validate your web application in mobile view.
Feel free to contact me if you have any questions or if you know a better way to approach these cases.