空手道 - 如何使用从响应数组接收到的值循环 Soap 请求 [英] Karate - How to loop Soap request with values received from a response array
问题描述
我正在发出 Soap 请求,我收到了作为数组返回的响应:
I am making a Soap request, and I am receiving the response that's returned as an array:
- [print] [
"M4205N",
"M4206U"
]
对于数组中的每个项目,我想发出另一个 Soap 请求.我已经阅读了如何使用 tables 执行此操作并调用功能文件,并且我已经阅读了如何 遍历数组,调用js函数.我不知道如何遍历数组,并将每个值传递给另一个肥皂请求 xml(一次一个).
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).
我想做这样的事情:
- 给定soapURL
- 和方法post
- def responseArray =/xml 我想要的代码路径/
- def result = call read('otherRequest.feature') responseArray
otherRequest.feature 文件如下所示:
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
但是,我收到此错误:
GetNewMessageList.feature:27 - 参数不是 json 或特征调用循环数组位置的映射:0,M4205N
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?
推荐答案
添加这一行应该做你想要的.是的,有一个硬性要求,即循环"数组应该是 JSON 对象的数组.但是您可以一步转换一组基元:
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')
这在此处记录:https://github.com/intuit/karate#json-变换
这篇关于空手道 - 如何使用从响应数组接收到的值循环 Soap 请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!