如何将信用固定在剧作家测试中的React中?
我有一个React Web应用程序,我想使用playwright进行测试。该应用是基于登录的,这意味着我必须登录才能进行测试。 如何安全地存储用户名和密码?
它们必须存在于Git的某个地方,因为我希望测试成为CI的一部分并自动运行。这就是为什么我认为.env在这里没有帮助的原因。
有什么想法吗?方法?
I have a react web app which I want to test using Playwright. The app is login-based, meaning I have to login in order to test.
How can I store username and password securely?
They has to exist somewhere in git because I want the tests to be part of the CI and run automatically. That's why I think .env won't help here.
Any ideas? approaches?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
询问您的DevOps团队,他们如何处理CI中的证书?
只需给他们凭据,然后在运行测试时将这些变量传递到命令行中。
您可以使用:
https://playwright.dev/dev/dev/dev/dev/dev/dev/test-parameterize#pass-pass-pass-pass-pass-pass-pass-pass-rironment-inrienlpass-wironment--rironnment-变量
Ask your Devops team, how did they handle credentials in CI?
Just give them the credentials and pass these variables in command line when running the tests.
You can use:
https://playwright.dev/docs/test-parameterize#passing-environment-variables
您可以将所需的变量存储在
.env
文件中(将此文件扩展名添加到您的git忽略文件中,因此它不会提交您的存储库)。然后构建钥匙值对并将其添加到您的代码中。示例:
通过这种方式,
.env
文件在您的设备上本地工作,您可以测试您的应用程序。将
dotenv
添加到您的代码导入中,使用
crypto.js
开源源来加密此.env
如果使用共享服务器(请记住其他人们可以阅读团队上的所有环境变量,因此,如果您不是服务器上的管理员并与其他人共享服务器,则可能需要这样做。在您自己的电脑上并在服务器上对其进行加密)。You can store the variables you need in a
.ENV
file (add this file extension to your Git Ignore file so it wont commit to your repo). Then build out the key value pairs and add that to your code.Example:
This way the
.ENV
file works locally on your device and you can test your app.Add the
DotEnv
package to your code importsUse the
Crypto.js
open source to encrypt this.ENV
file if using a shared server (remember other folks can read all the environment variables on your team so you might want to do this if you are not the admin on your server and share the server with others. It is a best practice to use.ENV
files on your own PC and on the server to encrypt it).