skip to Main Content

I have below cypress nodeJS script commands in package.json

"scripts": {
"cy:run": "npx cypress run --browser chrome",
"cy:parallel" : "cypress-parallel -s cy:run -t 4 -d cypress/e2e/features/ -m false -a '"--env ENV=${ENVI}"'" 
}

-a is the argument that is dynamic, That I want to pass while running the tests like ENVI=QA or ENVI=LIVE

I have tried following things but did not work for me

SET ENVI=QA
npm run cy:parallel

ENVI=QA npm run cy:parallel

$ENVI=QA npm run cy:parallel

Please share the correct way to pass the argument from the command-line

3

Answers


  1. Chosen as BEST ANSWER

    It worked for me with below command:

    set the environment variable value like below:

    $env:ENVI=QA (On Windows)

    and change script command as follow:

    Instead of ENV=${ENVI}, Use ENV=%ENVI%

    "cy:parallel" : "cypress-parallel -s cy:run -t 4 -d cypress/e2e/features/ -m false -a '"--env ENV=%ENVI%"'"
    

  2. One way would use CYPRESS_ prefix.

    To make things easier (independent of OS) use the package cross-env.

    Install

    npm install --save-dev cross-env
    

    package.json

    "scripts": {
      "cy:run": "cross-env CYPRESS_ENVI=QA cypress run",
      ...
    }
    

    Tested with a simple test:

    it('checks cross-env has set up CYPRESS_ENVI', () => {
      expect(Cypress.env('ENVI')).to.eq('QA')                // passes
    })
    
    Login or Signup to reply.
  3. You can use -- to separate the npm command from the cypress command, and everything after it is passed as arguments to the cypress-parallel command:

    npm run cy:parallel -- --env ENV=QA
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search