Cypress + Next.js Environment Variables

Join The JS Discord

A chill community of Javascript hackers, pair programming, product launching and learning together

Signing in to an app using Cypress, but don't want to hard code the values to accidently upload them to github?

Using dotenv also isn't a simple set up here, so here's the workaround.

  • Create a cypress.env.json file at the root of the project.
  • Add it to the gitignore file.
  • Create your key value pairs and index into it using Cypress.env('ObjectName').key
  "userOne": {
    "email": "",
    "password": "thePassWordWord"
let username = Cypress.env("userOne").email;