javascript - Cypress 环境变量未定义

标签 javascript node.js automation cypress

在 cypress.json 文件中,我有以下代码

{
  "baseUrl": "test",
  "ignoreTestFiles": [],
  "viewportHeight": 768,
  "viewportWidth": 1024,
  "video": false,

  "env": { "email": "test@email.com", "password": "password" }
}

当我尝试通过调用 Cypress.env('password') 访问它时,它在打印时在控制台日志中显示未定义,这是什么问题。

const password: string = Cypress.env('password')

describe("Login to the application", () => {
  beforeEach(() => {
    cy.visit("/");
  });

  it.only("user should login successfully", () => {
    console.log(Cypress.env('email')).   --- undefined 
    loginPage.login(email, password);
    cy.url().should("include", "/wallet");
  });

最佳答案

我的错误是不知道或没有检查我的 cypress.json 文件的位置,将它移到了顶部的 cypress 文件夹中,值显示正确。

关于javascript - Cypress 环境变量未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72212781/

相关文章:

javascript - 使用 localStorage 存储对象

javascript - 不清楚 V8 垃圾收集

powershell - 通过 PowerShell 导出非事件用户的上次登录日期

javascript - 在 Watir 中加载 js 文件

javascript - 在 testcafe 中断言空文本框

javascript - 显示当前日期前 2 天的日期名称

javascript - 按字母顺序排列的数组排序 - 小写在前

javascript - 正则表达式不起作用

javascript - 如何拦截 puppeteer 上的下载请求并读取被拦截的文件

javascript - "Failed to instantiate module ' app ' due to" Angular 和平均堆栈