Karate - How to loop Soap request with values received from a response array

风格不统一 提交于 2019-12-13 18:03:13

问题


I am making a Soap request, and I am receiving the response that's returned as an array:

 - [print] [
  "M4205N",
  "M4206U"
]

For each item in the array, I want to make another Soap request. I've read how you can do this with tables and call a feature file, and I've read how to loop through an array, and call a js function. I cannot figure out how to loop through the array, and pass each value to another soap request xml (one at a time).

I want to do something like this:

  • Given soapURL
  • And method post
  • def responseArray = /xml path for the codes I want/
  • def result = call read('otherRequest.feature') responseArray

The otherRequest.feature file would look something like this:

@ignore
Feature:

Background:
* def myNewRequest = read('soap.xml')

Scenario:
  Given soapURL
  * replace myNewRequest 
  | token      | value              |
  | @@refNum@@ | responseArrayValue |
  When request myNewRequest 
  And method post

However, I get this error:

GetNewMessageList.feature:27 - argument not json or map for feature call loop array position: 0, M4205N

How can I loop through each item in the array, and pass each value to the other feature file?


回答1:


The addition of this one line should do what you want. Yes there is a hard requirement that the "loop" array should be an array of JSON objects. But you can convert an array of primitives in one step:

* def responseArray = karate.mapWithKey(responseArray, 'responseArrayValue')

This is documented here: https://github.com/intuit/karate#json-transforms



来源:https://stackoverflow.com/questions/58984158/karate-how-to-loop-soap-request-with-values-received-from-a-response-array

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!