小编nna*_*fun的帖子

cypress:使用 npm run cy:open 从命令行传递环境变量

在 cypress.json 中有一个环境变量:

  "env": {
    "AUTH_TOKEN": "token_1"
  },
Run Code Online (Sandbox Code Playgroud)

我在数据库中有多个用户,想在不编辑 cypress.json 的情况下单独测试它们。Cypress 文档提供了两种可能的方法来覆盖命令行中的环境变量:

cypress run --env AUTH_TOKEN="token_2"
Run Code Online (Sandbox Code Playgroud)

AUTH_TOKEN="token_2" cypress run
Run Code Online (Sandbox Code Playgroud)

当我运行 cypress 界面时

npm run cy:open --env AUTH_TOKEN="token_2"
Run Code Online (Sandbox Code Playgroud)

或者

AUTH_TOKEN="token_2" npm run cy:open
Run Code Online (Sandbox Code Playgroud)

token_1 不会被 token_2 覆盖。为什么 cypress 忽略命令行中提供的选项?

testing environment-variables cypress

3
推荐指数
1
解决办法
5760
查看次数

标签 统计

cypress ×1

environment-variables ×1

testing ×1