6

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?

  • The error comes from 'ng' command not the cypress. If you need to set up cypress environment wouldn't it be running cypress command? – Pigbrainflower Oct 17 '19 at 22:07
  • It looks like your error is connected with nx framework usage, as it's known issue in their infrastructure. Take a look at this discussion: https://github.com/nrwl/nx/issues/1970 – Olga Govor May 25 '20 at 07:25

1 Answers1

4

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

Arnon Axelrod
  • 1,444
  • 2
  • 13
  • 21
  • I tried that option as well, the problem here is according to the framework .nodemodules is sitting in projects root folder 'dyno\node_modules' , whereas my cypress framework is sitting in 'dyno\apps\admin-web\ui-e2e' so, when I am trying to execute 'cypress open --env environment=Dev', a sample cypress framework and cypress.json file is getting created in the root folder ('dyno\cypress.json') and executing cypress example integration tests provided by cypress guys, instead of my project tests –  Oct 18 '19 at 14:02
  • Where is your cypress.json file? Is it under dyno\apps\admin-web\ui-e2e? If so firstly go to that folder where cypress json file has. Then run the command ''cypress open --env environment=Dev'. If it cannot find cypress executable add it to environment variable or use the absolute path. – Pigbrainflower Oct 18 '19 at 18:31