I am looking to re-use a particular value across multiple step definitions in my Cypress/Cucumber test.

I was thinking of using a normal variable, but the problem is that the step definitions are stored in different files.

So I am wondering if I could assign the value to an environment variable & reference that in the other file.

I was trying to do something like Cypress.env('myUsername') = 'testUser', but I get this lint error:

enter image description here

2

Best Answer


Cypress environment variables can be set during a test by passing in the desired value as the second argument.

Cypress.env('HOST', 'asdf');

In the documentation, env API syntax should look like something below:

 - Cypress.env()- Cypress.env(name)- Cypress.env(name, value)- Cypress.env(object)

In your case the following will work

Cypress.env('myUsername', 'testUser')