[英]cypress: pass array as command line argument
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
. 由于
Cannot read property 'split' of undefined at piperToCommas
引发错误。
Can anyone tell/guide me, how to solve this issue? 谁能告诉/指导我如何解决这个问题?
EDIT: 编辑:
I think you could pass your variables with a JSON and then you can access them as a normal javascript object. 我认为您可以使用JSON传递变量,然后将其作为普通的javascript对象进行访问。
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. 现在在您的规范中,如果调用
Cypress.env('token')
,则将获得此对象作为输出。
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
. 这将创建两个环境变量,
host
的值为kevin.dev.local
和api_server
的值为http://localhost:8888/api/v1
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.