user10251019
user10251019

Reputation:

How to set environment variables in cypress.json file through command line? (Angular CLI - nrwl nx)

I am new to cypress and learning day by day, we are trying to implement e2e tests using cypress in angular project.

I am facing issues when I want to set env variables in cypress.json file through the command line

This is my cypress.json file

{
  "defaultCommandTimeout": 10000,
  "viewportWidth": 1440,
  "viewportHeight": 900,
  "env": {
    "environment": "Stagging"
  },
  "fileServerFolder": ".",
  "fixturesFolder": "./src/fixtures",
  "integrationFolder": "./src/integration",
  "pluginsFile": "./src/plugins/index",
  "supportFile": "./src/support/index.ts",
  "video": true,
  "videosFolder": "../../../dist/cypress/apps/web/e2e/videos",
  "screenshotsFolder": "../../../dist/cypress/apps/web/e2e/screenshots",
  "chromeWebSecurity": false
}

I wanted to dynamically relace the Environment value, in my case from Stagging to dev. I am trying to use the following ng command

ng e2e --env environment=Dev

it's throwing me this error enter image description here

when I worked on POC, this option worked fine as they mentioned in cypress docs (https://docs.cypress.io/guides/guides/environment-variables.html#Setting)

can someone help me to solve this?

Upvotes: 7

Views: 4004

Answers (1)

Arnon Axelrod
Arnon Axelrod

Reputation: 1672

You need to run cypress open --env environment=Dev instead of the ng CLI command. If you want to run the tests directly, instead of opening the Test Runner, then use cypress run --env environment=Dev

Upvotes: 4

Related Questions