首页 > 解决方案 > How to use karate.callSingle() in karate-config.js?

问题描述

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

解决方案


karate-config.js你可以这样做:

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.

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


推荐阅读