本文介绍了如何在karate-config.js中使用karate.callSingle()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在所有功能文件中都使用了授权令牌.为了生成授权令牌,我需要调用特定的功能文件(token.feature).由于我在所有功能中都使用令牌,因此我不断地反复调用相同的功能文件.我发现的解决方案是在karate-config.js中使用karate.callSingle(),但我不知道如何使用karate.callSingle().

I am using an authorization token in all my feature files . To generate the authorization token i need to call a particular feature file(token.feature) . Since I am using the token in all features I keep calling the same feature file again and again. The solution i found is the use of karate.callSingle() in karate-config.js but i dont know how to use karate.callSingle().

推荐答案

karate-config.js中,您可以执行以下操作:

In karate-config.js you can do this:

var config = { myprop: 'myvalue', myurl: 'somevalue' };
var result = karate.callSingle('classpath:token.feature', config);
config.token = result.token; // assuming you did 'def token'
return config;

现在,您所有的功能都可以使用变量token.

Now all your features can use the variable token.

这在文档中得到了解释: https://github.com/intuit/karate#hooks

This is explained in the docs: https://github.com/intuit/karate#hooks

这篇关于如何在karate-config.js中使用karate.callSingle()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 07:03