The process of establishing private environment variables for Cypress tests involves the following steps:
Create a new file named .env
at the root of your project directory.
Add the private environment variables one per line in the following format:
MY_VARIABLE=value
ANOTHER_VARIABLE=value
dotenv
package to load the environment variables in your test code. require('dotenv').config()
const myVariable = process.env.MY_VARIABLE
const anotherVariable = process.env.ANOTHER_VARIABLE
it('should log in with private credentials', () => {
cy.visit('https://example.com/login')
.get('#username').type(process.env.MY_USERNAME)
.get('#password').type(process.env.MY_PASSWORD)
.get('#login-button').click()
})
Note that you should never include .env
in your Git repository, and you should never share your private environment variables with others.
Asked: 2022-04-17 11:00:00 +0000
Seen: 9 times
Last updated: Jul 21 '21