Script command tips for passing environment variables
P粉295616170
P粉295616170 2023-09-02 13:07:19
0
2
383

I have the following cypress nodeJS script command 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 a dynamic parameter that I want to pass when running the test, such as ENVI=QA or ENVI=LIVE

I tried the following but none of them worked for me:

SET ENVI=QA npm run cy:parallel

ENVI=QA npm run cy:parallel

$ENVI=QA npm run cy:parallel

Please tell me the correct way of passing parameters from the command line.

P粉295616170
P粉295616170

reply all (2)
P粉465675962

One way is to use theCYPRESS_prefix.

To make things simpler (OS independent), use packagecross-env.

Install

npm install --save-dev cross-env

package.json

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

Test with a simple test:

it('检查cross-env是否已设置CYPRESS_ENVI', () => { expect(Cypress.env('ENVI')).to.eq('QA') // 通过 })
    P粉384679266

    Using the following command worked for me:

    Set the value of the environment variable as follows:

    $env:ENVI=QA(on Windows)

    And change the script command as follows:

    UseENV=%ENVI%instead ofENV=${ENVI}

    "cy:parallel" : "cypress-parallel -s cy:run -t 4 -d cypress/e2e/features/ -m false -a '\"--env ENV=%ENVI%\"'"
      Latest Downloads
      More>
      Web Effects
      Website Source Code
      Website Materials
      Front End Template
      About us Disclaimer Sitemap
      php.cn:Public welfare online PHP training,Help PHP learners grow quickly!