简体   繁体   English

cypress:将数组作为命令行参数传递

[英]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.localapi_server的值为http://localhost:8888/api/v1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 通过赛普拉斯在命令行中传递自定义API密钥 - Pass custom API key in command line with Cypress npm将命令行参数传递给命令 - npm pass command line argument to command 如何在NodeJS中传递命令行参数? - How to Pass a Command Line Argument in NodeJS? 如何将命令行参数传递给嵌套脚本? - How to pass a command line argument to a nested script? 为什么即使我使用 chrome 浏览器,赛普拉斯在 GUI(柏树打开)中的测试通过但在命令行(柏树运行)中失败? - Why does Cypress test in GUI(cypress open) pass but fails in command line(cypress run) even though I using chrome browser? 将数组作为原始命令行参数 - Getting Array as a raw command line argument 是否可以通过数组命令行 arguments nodejs? - Is it possible to pass array command line arguments nodejs? 如何通过命令行将变量作为参数传递给CasperJS脚本? - How to pass a variable as an argument to a CasperJS script through the command line? 如何使用 npm 在命令行中传递参数并在反应 javascript 代码中读取它 - How to pass argument in command line with npm and read it in react javascript code 如何在命令行中传递参数以运行纱线脚本 - How to pass an argument in command line to run the script for yarn
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM