Cypress.io如何读取Windows环境变量? [英] How does Cypress.io read the Windows environment variables?
问题描述
我已在 Cypress.env.json文件中设置了环境变量,而在运行cypress测试时,它成功读取了Cypress.env变量。但是,为了更加注重安全性,而不是对值进行硬编码,我的团队要求我将此变量保留为单独的参数,该参数从Windows 10环境变量中读取。我该如何实现?
I have set my environment variables in 'Cypress.env.json' file, while running the cypress test, it read the Cypress.env variables successfully. But to be more on the security aspect, rather than 'hard-cording' the values, my team asked me to keep this variable as separate 'parameters' which read from Windows 10 Environment variables. How do I achieve this ? It would be really helpful if someone could advise on this.
{
"QA_Server": "https://sometestingsite.com",
"username": "testQA",
"password": "Password1234!"
}
推荐答案
来自赛普拉斯文档此处:
From cypress documentation here:
计算机上任何以 CYPRESS _
或 cypress _ $ c $开头的环境变量c>将自动添加并提供给您。
Any environment variable on your machine that starts with either CYPRESS_
or cypress_
will automatically be added and made available to you.
冲突值将覆盖 cypress.json
和 cypress.env.json
文件。
赛普拉斯将剥夺 CYPRESS _
添加环境变量时。
Cypress will strip off the CYPRESS_
when adding your environment variables.
从命令行导出cypress env变量:
export CYPRESS_HOST=laura.dev.local
export cypress_api_server=http://localhost:8888/api/v1/
如果使用Windows,则可以使用 set
或设置x
命令。
If you're using Windows you can set env variables using set
or setx
commands.
在测试文件中,您可以这样称呼:
And in your test files you can call this:
Cypress.env() // {HOST: "laura.dev.local", api_server: "http://localhost:8888/api/v1"}
Cypress.env("HOST") // "laura.dev.local"
Cypress.env("api_server") // "http://localhost:8888/api/v1/"
这篇关于Cypress.io如何读取Windows环境变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!