【发布时间】:2022-11-07 21:59:02
【问题描述】:
在 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");
});
【问题讨论】:
-
为什么不改用
console.log(password)? -
对我来说 Cypress.env('email') 会返回 test@email.com。您的 cypress.json 在哪里?它应该在顶部的 cypress 文件夹中,而不是底部的文件夹中
-
@PhilipAllStar 是的,文件被放置在错误的目录中
标签: javascript node.js automation cypress