从 CLI 执行时,Cypress 环境变量会选取多个值。如何在赛普拉斯测试中传递多个环境变量?

Cypress environment variable picking multiple values when executed from CLI. How to pass multiple environment variables in Cypress tests?

我正在使用带有 Cucumber 预处理器和 Typescript 的 Cypress 当我从 CLI 运行ning Cypress(不使用 package.json 中的脚本对象)并传递多个环境变量值时,第一个值是在执行测试用例时选择所有剩余的逗号分隔值. 例如:当我 运行 下面的命令 命令:

./node_modules/.bin/cypress run --env URL1=https://testurl.com,URL2=https://testurl2.com --headed --browser chrome

URL 在脚本中被选中的是 "https://testurl.com,URL2=https://testurl2.com" 但它应该只选择 " https://testurl.com".

一般来说,您应该可以指定多个环境变量,如下所示:

cypress run --env host=kevin.dev.local,api_server=http://localhost:8888/api/v1

然后您可以在测试中访问这些内容,例如:

Cypress.env() // {host: 'kevin.dev.local', api_server: 'http://localhost:8888/api/v1'}
Cypress.env('host') // 'kevin.dev.local'
Cypress.env('api_server') // 'http://localhost:8888/api/v1/'

我从赛普拉斯文档中获取了右上角的示例 here

乍一看你的代码看起来是正确的,也许你可以再次检查变量名并尝试执行:

npx cypress run --headed --env host=kevin.dev.local,api_server=http://localhost:8888/api/v1