如何将一个功能文件的json列表响应作为参数传递给另一功能文件 [英] How to pass the json list response of one feature file as parameter to another feature file
问题描述
我的要求是,我想将第一个功能文件的响应作为输入传递给第二个功能文件.第一个功能文件响应是一个json列表,因此可以预期的是应该为json列表的每个值调用第二个功能文件.
My requirement is, I want to pass the response of first feature file as input to second feature file. The first feature file response is a json list, so the expectation is second feature file should be called for each value of json list.
Feature:
Scenario: identify the reference account
* def initTestData = read('../inputData.feature')
* def accountData = $initTestData.response
* print "Account Details"+accountData // output of this is a json list ["SB987658","SB984345"]
* def reqRes = karate.call('../Request.feature', { accountData : accountData })
在Request.feature文件中,我们正在动态构建网址
In Request.feature file we are constructing the url dynamically
Given url BaseUrl + '/account/'+'#(accountId)' - here am facing issue http://10.34.145.126/account/["SB987658","SB984345"]
我的要求是Request.feature应该为"accountData" Json列表中的每个值调用
My requirement is Request.feature should be called for each value in ‘accountData’ Json list
我尝试过:
* def resAccountList = karate.map(accountData, function(x){accountId.add(x) })
* def testcaseDetails = call read('../requests/scenarios.feature') resAccountList.accountId
结果相同,accountId被替换为["SB987658","SB984345"]
Result is same, accountId got replaced as ["SB987658","SB984345"]
我需要两次致电Request.feature http://10.34.145.126/account/SB987658 http://10.34.145.126/account/SB984345 ,并使用每个呼叫对后续呼叫的响应功能文件调用.
my I need to call Request.feature twice http://10.34.145.126/account/SB987658 http://10.34.145.126/account/SB984345 and use the response of each call to the subsequent feature file calls.
推荐答案
我认为您在karate.map()
中有一个错误,请看以下示例:
I think you have a mistake in karate.map()
look at the below example:
* def array = ['SB987658', 'SB984345']
* def data = karate.map(array, function(x){ return { value: x } })
* def result = call read('called.feature') data
called.feature
是:
Feature:
Scenario:
Given url 'https://httpbin.org'
And path 'anything', value
When method get
Then status 200
哪个发出2个请求:
https://httpbin.org/anything/SB987658
https://httpbin.org/anything/SB984345
这篇关于如何将一个功能文件的json列表响应作为参数传递给另一功能文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!