在空手道DSL测试中使用环境变量

发布于 2025-01-25 16:46:13 字数 627 浏览 2 评论 0原文

我想将gitlab ci纳入我的空手道测试。我想通过不同的用户名和密码循环进行测试,以确保我们的API端点对不同的用户响应。

考虑到这一点,我希望能够将用户名和密码作为安全环境变量存储在gitlab中(而不是在karate-config作为纯文本中)并让空手道根据空心config或功能文件将其拉出。

浏览文档和Stackoverflow问题,我还没有看到一个示例。

在下面的彼得评论中使用新信息更新

,这就是我需要的内容,我尝试将其设置为以下内容:

在空手道config中设置客户端ID:
var client_id = java.lang.system.getenv('client_id');

在实际配置对象:
clientId:client_id

在我的功能文件中尝试访问它:
* def client_id = clientid

它仍然以null为单位。

I'd like to incorporate GitLab CI into my Karate testing. I'd like to loop through my tests with different user names and passwords to ensure our API endpoints are responding correctly to different users.

With that in mind, I'd like to be able to store the usernames and passwords as secure environment variables in GitLab (rather than in the karate-config as plain text) and have Karate pull them as needed from either the karate-config or the feature files.

Looking through the docs and StackOverflow questions, I haven't seen an example where it's being done.

Updating with new information

In regards to Peter's comment below, which is what I need I am trying to set it up as follows:

set client id in karate-config:
var client_id = java.lang.System.getenv('client_id');

in the actual config object:
clientId: client_id

In my feature file tried to access it:
* def client_id = clientId

It still comes through as null, unfortunately.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

何止钟意 2025-02-01 16:46:13

您可以使用空手道读取空手道的环境

karate.properties['java.home']

变量

但是,如果您的用户太多,您的配置和环境变量看起来会很麻烦。

如果您想与多个用户一起运行一些功能,建议您查看这篇文章,

”>我们可以循环功能文件,并使用空手道中的多个登录用户

编辑:

使用peter:to to to to to to to to

var systemPath = java.lang.System.getenv('PATH');

to to to to to to to to to to to to opop 查看哪些变量实际上是暴露的,

var evars= java.lang.System.getenv();
karate.log(evars);

并查看所有环境变量的列表。

You can read environment variables in karate using karate.properties,

eg,

karate.properties['java.home']

If this helps you to read the environment variables that you are keeping securely on your gitlab, then you can use it in your karate-config for authentication.

But your config and environment variable will look cumbersome if you are having too many users.

If you want to run a few features with multiple users, I would suggest you look into this post,

Can we loop feature files and execute using multiple login users in karate

EDIT:

Using java interop as suggested by peter:

var systemPath = java.lang.System.getenv('PATH');

to see which are all variables are actually exposed try,

var evars= java.lang.System.getenv();
karate.log(evars);

and see the list of all environment variables.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文