How to use karate.callSingle() in karate-config.js?

廉价感情. 提交于 2019-12-24 08:49:11

问题


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().


回答1:


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;

Now all your features can use the variable token.

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



来源:https://stackoverflow.com/questions/51288342/how-to-use-karate-callsingle-in-karate-config-js

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!