如何在空手道中创建全局变量? [英] How to create global variable in karate?
问题描述
我已经配置了基本URL,现在我必须配置一个(存储的)变量,该变量将在许多请求中使用.为了针对不同的商店运行2-3次测试,我需要手动访问每个功能并修改已存储的内容.那么,我将如何声明全局变量以及如何将其绑定到请求?
I have configured base URL, and now I have to configure one variable(storied), which will be used in the many of the requests. for running test 2-3 times for different stores I need to manually go to every feature and modify storied. So how would I declare a global variable and how to bind it to a request?
推荐答案
与 baseUrl
一样,只需在 karate-config.js
中添加一个变量,然后它将在所有测试中可用.
The same way like you did baseUrl
, just add a variable in karate-config.js
and it will be available in all tests.
如果使用 def
设置变量,则该变量将在其余方案中可用.如果要重复使用,请使用 Background
部分或查看 call
的文档.
If you set a variable using def
it will be available to the rest of the scenario. If you want re-use, use a Background
section or look at the documentation for call
.
()
请参阅文档: https://github.com/intuit/karate#configuration
如果这令人困惑,请与了解JavaScript的任何人一起花费5分钟,并让他们阅读上一节.您将很快获得解决方案.祝一切顺利!
If this is confusing, just spend 5 minutes with anyone who knows JavaScript and make them read the above section. You will get a solution in no time. All the best !
这篇关于如何在空手道中创建全局变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!