Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
971 views
in Technique[技术] by (71.8m points)

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...