https://cypress.io logo
What is the correct way to set up a file with cred...
# i-need-help
f
Hey everyone, this is a pretty noob question but I've never had a project with this many accounts. In order to test my app I need to have a different account for every 4 or 5 tests. I have my global variables, settled in the environment, but I already have like 50 because of this so I would like to get those out in a file. What is the correct way/best practice to do this? Should I create a json file as a fixture or what do you recommend to keep it clean?
e
try to utilise cy.session()
yes, you can just create a JSON file to store the credentials. and utilise the cy.session to store the tokens
it will help you alot if you require to jump from one user to another.
h
I'm guessing the reason that @faint-ocean-92094 is currently using environment variables is to keep secrets out of version control. I would recommend that whatever json file you use to store the credentials, you add it to your
.gitignore
and only keep credentials on CI providers and locally on developer machines. This blog post touches on some of those security considerations pretty well - https://glebbahmutov.com/blog/keep-passwords-secret-in-e2e-tests/
Agreed on the recommendation for
cy.session
f
Thank you both. I'm actually using global variables cause I have to keep 4 environments so I'm using dynamic configurations depending on environment variables. (Users in each env, urls, etc)
I'm using github secrets as well for top secret stuff like admin credentials, or ssh keys for the DB, but this is just for environments
I guess what I was thinking is right then, store my credentials in a Json file for each environment, and instead of having a big config.env object for each env, I will just have.4 separate files and keep my cypress.config.json clean and simple
h
Yeah I would definitely not put it in your cypress config file at this point
You could even build some custom commands around the files to make them more ergonomic to interact with , but having them all in individual files will be a good baseline
4 Views