Reputation: 584
What I had till today:
I have get_jwt.feature
and I call it as a part of karate-config.js
. Since I have used one account [email protected]
I needed only one jwt and I can reuse it across scenarios. callSingle
worked as a charm in this case.
Today:
Suddenly I have need for jwt's from two accounts which I dont want to generate for each scenario, callSingle
falls short of this task as it does exactly what its supposed to be doing. Now I have hacky idea, I can simply make two files, get_jwt.feature
and get_jwt_user2.feature
, and single call them each.
So my question: Is there a better way of doing this?
Upvotes: 3
Views: 170
Reputation: 58098
You can use "2 levels" of calls. So point the callSingle()
to a JS function that calls get_jwt.feature
2 times, maybe with different arguments and then return a JSON. Pseudo-code below. First is get_jwts.js
:
function fn(users) {
var jwt1 = karate.call('get_jwt.feature', users.user1);
var jwt2 = karate.call('get_jwt.feature', users.user2);
return { jwt1: jwt1, jwt2: jwt2 };
};
Then in karate-config.js
config.jwts = karate.callSingle('classpath:get_jwts.js', users);
And now you should be able to do this:
* print jwts.jwt1
* print jwts.jwt2
You can also do a feature-->feature call chain. Do let me know if this works !
EDIT: see Babu's answer in the comments, looks like you can pass an array to callSingle()
! so that may be quite convenient :)
Upvotes: 2