I tryna pass the param param1 and param2 when I run the script by command Line.
Here code in test.cy.js
it('Clean data', () => {
const param1 = process.env.npm_config_param1;
const param2 = process.env.npm_config_param2;
before(function () {
cy.visit('/')
//Login
cy.get('#username').type(param1)
cy.get('#password').type(param2)
cy.get('#loginBtn').click()
})
I defined script in package.json
"my-script": "npx cypress run --spec "test.cy.js" --param1 value1 --param2 value2"
I run in CL
npm [email protected] --param2=11111111 run-script my-script
I got the error ‘error: unknown option: –param1‘
Can I pass the param into npm script of Cypress?
2
Answers
You should define them as environment variable and it’s possible in command lines (see documentation).
In your case, it would be:
and
You can also refer to this How to use variables in npm scripts on windows
Double-dash is correct way to pass params to inner script, but it needs a space before it.
This answer Sending command line arguments to npm script shows good example code.
You define script in
package.json
You run in CLI
You use in test