Reputation: 2572
I am working on cypress for automatic testing. I want to pass list of variables through the command prompt.
For ex:
$(npm bin)/cypress run --env pages=page1,page2 --spec 'cypress/integration/atests/test.spec.js'
But it fails. Error is thrown as Cannot read property 'split' of undefined at piperToCommas
.
Can anyone tell/guide me, how to solve this issue?
Upvotes: 0
Views: 2542
Reputation: 10615
EDIT:
I think you could pass your variables with a JSON and then you can access them as a normal javascript object.
Example:
$(npm bin)/cypress run --env token='{"a":"5", "b":{"c":"x"}}'
Now in your spec, if you call Cypress.env('token')
you'll get this object as output.
If you want the enviroment variable as an array, you could pass it this way:
$(npm bin)/cypress run --env token='["a", "b"]'
Output:
If I understood the question correctly, you should pass the variables in the form:
cypress run --env name1=value1,name2=value2,...
Example:
cypress run --env host=kevin.dev.local,api_server=http://localhost:8888/api/v1
This will create two environment variables, host
with value kevin.dev.local
and api_server
with value http://localhost:8888/api/v1
.
Upvotes: 3