【问题标题】:How to use Cypress.env() inside Cypress/fixtures/sample.js file?如何在 Cypress/fixtures/sample.js 文件中使用 Cypress.env()?
【发布时间】:2021-03-10 11:48:49
【问题描述】:

我有一个像这样的sample.js 文件:

赛普拉斯/fixtures/sample.js

module.exports = {
  username: Cypress.env('username'),
  password: Cypress.env('password')
}

Cypress.json 就像:

{
  "baseUrl": "http://localhost:3000",
  "video": false,
  "viewportWidth": 375,
  "viewportHeight": 812,
  "defaultCommandTimeout": 10000,
  "retries": {
    "runMode": 2,
    "openMode": 0
  },
  "env": {
    "username": "******",
    "password": "******"
  }
}

但它不起作用并返回:

赛普拉斯没有定义!

【问题讨论】:

  • 跑步者将赛普拉斯全局注入测试,但不注入固定装置。我不记得看到将其导入 sample.js 的方法(尽管可能使用模块 api)。你是如何使用 sample.js 的?是否需要在那里动态设置属性?
  • @MarionMorrison 不一定,我删除了fixture文件并在命令中使用了envs。

标签: environment-variables next.js cypress fixtures


【解决方案1】:

您不需要从固定装置中调用它。 Cypress.env() 是全局变量,可以在任何地方访问,因此不需要固定装置。 简单地这样称呼它:

    Cypress.env('username'),
    Cypress.env('password')

【讨论】:

  • 其实是的,我也是这样做的。我删除了夹具文件并在命令中使用了这些环境。
  • 请用更详细的上下文更新您的答案。
猜你喜欢
  • 2023-02-12
  • 1970-01-01
  • 2022-09-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-05-07
相关资源
最近更新 更多