Len*_*ler 5 testing error-handling automation environment-variables cypress
我有以下文件夹结构:
tests
cypress.env.json
cypress
fixtures
integration
test
test.spec.ts
plugins
support
Run Code Online (Sandbox Code Playgroud)
我错过了这个问题不必要的文件。
所以我的 cypress.env.json 看起来像这样:
tests
cypress.env.json
cypress
fixtures
integration
test
test.spec.ts
plugins
support
Run Code Online (Sandbox Code Playgroud)
现在我尝试访问 test.spec.ts 文件中的 env 变量:
{
"loginTestStage": {
"admin": {
"username": "value1",
"password": "value2"
},
"user": {
"username": "value3",
"password": "value4"
}
},
"vatid" : {
"x1": "value5",
"x2": "value6",
"x3": "value7",
"x4": "value8"
}
}
Run Code Online (Sandbox Code Playgroud)
当我尝试运行测试时,我总是在这里收到此错误:
Cannot read properties of undefined (reading 'admin')
Run Code Online (Sandbox Code Playgroud)
因此无法找到 Env 变量的值。如何解决这个问题?
提前致谢
cypress.env.json如果您移动到项目根目录,它将起作用。
就像cypress.config.js(v10) 或cypress.json(v9) 一样,该文件没有配置路径env,假定位于项目根目录。