问题描述
我有一个.feature文件,它将以__arg的形式接收来自另一个功能文件的参数,从而为oAuth生成令牌
I have a .feature file that will receive argument from another feature file as __arg to generate token for oAuth
Given url urlRefreshToken
Given def json = __arg
And header Content-Type = 'application/json; charset=utf-8'
And request json
* header Authorization = 'Bearer' + __arg.refresh_token
When method POST
Then status 200
* def bearer = 'Bearer ' + response.access_token
我只尝试一次将令牌生成集中在 karate-config.js
上.但是我似乎无法将karate.callSingle()与传递的参数一起使用.
I am trying to centralise the token generation for only one time on karate-config.js
. However I cannot seem to be able to use karate.callSingle() with passed parameters.
我使用功能部件文件在其他功能部件文件上生成令牌,如下所示:
I use the feature file to generate token on other feature files as:
* def getToken = call read('classpath:features/Utils/GetToken.feature') refreshTokenRaymond
* header Authorization = getToken.bearer
我试图调用功能文件以在 karate-config.js
上生成令牌,但无济于事.我试图在 karate-config.js
上传递这样的附加参数:
I am trying to invoke the feature file for generating token on karate-config.js
to no avail. I tried to pass in the additional parameter like this on karate-config.js
:
var config = {
baseUrl: 'url',
urlRefreshToken: 'url',
refreshToken: '{refreshToken: refreshToken}'
};
var token = karate.callSingle('classpath:features/Utils/GetToken.feature', [config, config.refreshToken])
我想知道是否可以将多个参数传递给从 karate-config.js
调用的 karate.callSingle()
吗?
I wonder if it is possible to pass multiple parameter to karate.callSingle()
called from karate-config.js
?
任何帮助将不胜感激.谢谢!
Any help will be greatly appreciated. Thanks!
推荐答案
call
和 karate.callSingle()
仅采用一个参数,但是您可以轻松地创建一个新参数JSON之外的其他JSON.实际上,由于您似乎在传递 config
作为参数-您可以轻松地将 config.refreshToken
作为 __ arg.refreshToken
.
call
and karate.callSingle()
take only one argument, but you can easily create a new JSON out of other JSONs. Actually since you seem to be passing config
as the argument - you can easily access config.refreshToken
as __arg.refreshToken
.
您的代码非常混乱-但希望此提示能助您一臂之力:
Your code is very confusing - but hope that this hint is what gets you on your way:
Given def json = __arg.refreshToken
如果您需要根据其他数据创建JSON-我想您已经知道该怎么做:
If you need to create a JSON out of other data - I think you already know how to do that:
var temp = { config: config, refreshToken: refreshToken };
var token = karate.callSingle('classpath:features/Utils/GetToken.feature', temp);
这篇关于如何传递多个参数以调用karate-config.js上的单个空手道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!