1

Feature File 1:inputData.feature

     @ignore
     Feature: Input data table
     Scenario: Input table for testing
* table testData
  | accountId           |  accountname    | expectedAccount  |
  | 'ADS5678543'   | 'Peter'              | 'DFCVSAEFRG'     |
  | 'ASDCF45678'   | 'Caroline'           |  'DFCWEAEFRG'    |

File 2: payload.json

{
"channelData": {
"data": "CHANNEL_DATA",
"salesChannel": "WEB",
"createdBy": "WEBSITE",
"accountId": "#(accountId)",
"sessionId": "#(accountname)"
 }
}

File 3: Request.feature

@ignore
Feature:

Scenario:
 # read the payload from json file
 * def Request = read('../payload.json')
 * def headersData = { "Content-Type" : "application/json"}
 Given url BaseUrl + '/account/'+'#(accountId)'
 And request Request
 And headers headersData
 When method post
 Then status 200
 * print response
  * def account = karate.jsonPath(response, "$.account")
 * print 'account is '+account
 Then match account == '#(expectedAccount)'

File 4: addressinfo.feature

@ignore
Feature:

Scenario:
   * def Request = “{
     “accountId": "#(resAccount)”
    }
 ”
 * def headersData = { "Content-Type" : "application/json"}
 Given url BaseUrl +'#(resAccount)’+'/address’
 And request Request
 And headers headersData
 When method post
 Then status 200
 * print response

File5: Account-token.feature

  Feature: 
Scenario: identify the reference account
 * def initTestData = read('../inputData.feature')
 * def reqRes = karate.call('../Request.feature', { initTestData : initTestData })
 * def resAccount =  $reqRes[*].account // output of this is [“SB987658”,”SB984345”]
 * def addressData = read('../addressinfo.feature’,{resAccount: resAccount}) 

In the above scenario, we have to pass the output of Request.feature as input to addressing.feature. java.net.URISyntaxException: Illegal character in path at index 34: http://10.36.145.196:9983/invoker/[“SB987658”,”SB984345”]/address . Our requirement is it should iterate each value of resAccount and we need to pass the o/p response of addressinfo.feature as I/p to another feature file.

1 Answers1

1

The rule for call args that need to be looped is that it has to be an array of JSONs. Refer: https://github.com/intuit/karate#data-driven-features

So you can transform the primitive array, refer: https://github.com/intuit/karate#json-transforms

* def resAccountList = karate.map(resAccount, function(x){ return { resAccount: x } })

I have to say your tests are badly designed and will cause you maintenance problems in the future. Try to avoid "too much reuse" and avoid call as far as possible. Refer to this answer for why: https://stackoverflow.com/a/54126724/143475

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • I have tried * def fun = function(x){ return { testcaseName: x } } * def resAccountList = karate.map(resAccount, fun) * def addressData = read('../addressinfo.feature’)resAccountList.resAccount .In addressinfo.feature when i try to print the * print "Calling scenario feature:"+ resAccountList.resAccount . it is printed as undefined. My requirement is ,When I hit first request I will get response [“SB987658”,”SB984345”] , I want to run another feature file by pass each value as inputparameter. – Murugesh Subramaniam Jan 18 '19 at 15:44
  • @MurugeshSubramaniam sorry I can't read and understand this and as I commented below your question it is too complex. here is my last piece of advice, all the best: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue – Peter Thomas Jan 18 '19 at 15:53
  • Still, my issue is not resolved. I am closing this issue and create a new with details. – Murugesh Subramaniam Jan 21 '19 at 10:32