When I run this code, it gives error. I am not getting what am I doing wrong with this.
export class Login{
enterEmail(){
return cy.get('input[type="email"]').type(Cypress.env('USER_LOGIN_EMAIL'))
}
enterPassword(){
return cy.get('input[type="password"]').type(Cypress.env('USER_LOGIN_PASSWORD'))
}
signInBtn(){
return cy.get('button[data-cy="login_signin_button"]').click()
}
}
CodePudding user response:
As ChrisG said, one of either Cypress.env('USER_LOGIN_EMAIL')
or Cypress.env('USER_LOGIN_PASSWORD')
is undefined. You can define environment variables in multiple ways, but I would suggest, if these values are going to be static, to define them in your configuration.
CodePudding user response:
how are you? There are a some points we need to check, to understand why you are getting undefined.
First we need to understand where those environment variables are saved, they could be saved in a cypress.env.json
file or in another .env
file.
If they are saved in a cypress.env.json
file, check if this file is in a JSON format like bellow with the correct variable names:
{
"USER_LOGIN_EMAIL": "[email protected]",
"USER_LOGIN_PASSWORD": "some.password"
}
If they aren't in a cypress.env.json
but they are in another .env
file, your environment variables in this other file should have a prefix CYPRESS_
so their correct names should be:
CYPRESS_USER_LOGIN_EMAIL
CYPRESS_USER_LOGIN_PASSWORD
If your environment variables don't exist in any .env
file you can create the cypress.env.json
like above or you can manually export in the terminal before running Cypress each time you open a new terminal using:
export [email protected]
export CYPRESS_USER_LOGIN_PASSWORD=some.password