Search code examples
environment-variablesnext.jscypressfixtures

How to use Cypress.env() inside Cypress/fixtures/sample.js file?


I have a sample.js file like this:

Cypress/fixtures/sample.js

module.exports = {
  username: Cypress.env('username'),
  password: Cypress.env('password')
}

and Cypress.json is like:

{
  "baseUrl": "http://localhost:3000",
  "video": false,
  "viewportWidth": 375,
  "viewportHeight": 812,
  "defaultCommandTimeout": 10000,
  "retries": {
    "runMode": 2,
    "openMode": 0
  },
  "env": {
    "username": "******",
    "password": "******"
  }
}

But it doesn't works and returns:

Cypress is not defined!


Solution

  • You don't need to call it from fixtures. Cypress.env() are global varibales and can be access everywhere so no need of fixtures. Simply call it like:

        Cypress.env('username'),
        Cypress.env('password')