简体   繁体   中英

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.

     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

   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

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”]

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.

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

And called.feature is:

Feature:

Scenario:
Given url 'https://httpbin.org'
And path 'anything', value
When method get
Then status 200

Which makes 2 requests:

https://httpbin.org/anything/SB987658
https://httpbin.org/anything/SB984345

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM