[英]How to pass the json list response of one feature file as parameter to another feature file
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.
第一个功能文件响应是一个json列表,因此可以预期的是应该为json列表的每个值调用第二个功能文件。
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 })
In Request.feature file we are constructing the url dynamically 在Request.feature文件中,我们正在动态构建url
Given url BaseUrl + '/account/'+'#(accountId)' - here am facing issue http://10.34.145.126/account/[“SB987658”,”SB984345”]
My requirement is Request.feature should be called for each value in 'accountData' Json list 我的要求是Request.feature应该为'accountData'Json列表中的每个值调用
I have tried: 我努力了:
* def resAccountList = karate.map(accountData, function(x){accountId.add(x) })
* def testcaseDetails = call read('../requests/scenarios.feature') resAccountList.accountId
Result is same, accountId got replaced as [“SB987658”,”SB984345”] 结果相同,accountId被替换为[“ SB987658”,“ 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. 我需要两次调用Request.feature http://10.34.145.126/account/SB987658 http://10.34.145.126/account/SB984345并使用每个调用对后续功能文件调用的响应。
I think you have a mistake in karate.map()
look at the below example: 我认为您在
karate.map()
有一个错误, karate.map()
以下示例:
* def array = ['SB987658', 'SB984345']
* def data = karate.map(array, function(x){ return { value: x } })
* def result = call read('called.feature') data
And called.feature
is: called.feature
是:
Feature:
Scenario:
Given url 'https://httpbin.org'
And path 'anything', value
When method get
Then status 200
Which makes 2 requests: 发出2个请求:
https://httpbin.org/anything/SB987658
https://httpbin.org/anything/SB984345
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.