如何将一个特征文件的 json 列表响应作为参数传递给另一个特征文件
How to pass the json list response of one feature file as parameter to another feature file
我的要求是,我想将第一个特征文件的响应作为输入传递给第二个特征文件。第一个特征文件响应是一个 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 })
在 Request.feature 文件中,我们正在构建 url 动态
Given url BaseUrl + '/account/'+'#(accountId)' - here am facing issue http://10.34.145.126/account/[“SB987658”,”SB984345”]
我的要求是 Request.feature 应该为“accountData”Json 列表中的每个值调用
我试过:
* def resAccountList = karate.map(accountData, function(x){accountId.add(x) })
* def testcaseDetails = call read('../requests/scenarios.feature') resAccountList.accountId
结果相同,accountId 被替换为 [“SB987658”,”SB984345”]
my 我需要调用Request.feature 两次http://10.34.145.126/account/SB987658 http://10.34.145.126/account/SB984345 并将每次调用的响应用于后续的特征文件调用。
我认为你有误 karate.map()
看下面的例子:
* 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 列表,因此应该为 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 })
在 Request.feature 文件中,我们正在构建 url 动态
Given url BaseUrl + '/account/'+'#(accountId)' - here am facing issue http://10.34.145.126/account/[“SB987658”,”SB984345”]
我的要求是 Request.feature 应该为“accountData”Json 列表中的每个值调用
我试过:
* def resAccountList = karate.map(accountData, function(x){accountId.add(x) })
* def testcaseDetails = call read('../requests/scenarios.feature') resAccountList.accountId
结果相同,accountId 被替换为 [“SB987658”,”SB984345”]
my 我需要调用Request.feature 两次http://10.34.145.126/account/SB987658 http://10.34.145.126/account/SB984345 并将每次调用的响应用于后续的特征文件调用。
我认为你有误 karate.map()
看下面的例子:
* 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