ashwanikumarjha
Thu Jun 29 2023
While writing Cypress test we generally create a cypress.env.json
file to store the environment variables.
{
"BASE_URL": "https://company.dev.com/",
"USER_EMAIL": "ashwani@example.com",
"USER_PASSWORD": "Test@12345",
}
To retrieve the value of our environment variable, we use the Cypress.env
method in the test file.
const baseUrl = Cypress.env('BASE_URL');
That's all we need to do locally to use the env vars in our Cypress test.
Now for CI, we can save these environment variables as Github action secrets.
To make these environment variables accessible from Github action secrets to our test, we need to keep a few things in mind.
• Add a value of empty string
to the env vars and expose the cypress.env.json
file.
{
"BASE_URL": "",
"USER_EMAIL": "",
"USER_PASSWORD": "",
}
• We need to add CYPRESS_
prefix to the env vars in the yml
file.
env:
CYPRESS_BASE_URL: ${{ secrets.BASE_URL }}
CYPRESS_USER_EMAIL: ${{ secrets.USER_EMAIL }}
CYPRESS_USER_PASSWORD: ${{ secrets.USER_PASSWORD }}
Happy testing!