空手道-如何使用从响应数组接收的值循环Soap请求 [英] Karate - How to loop Soap request with values received from a response array

查看:84
本文介绍了空手道-如何使用从响应数组接收的值循环Soap请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在发出一个Soap请求,并且收到作为数组返回的响应:

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

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

对于数组中的每个项目,我想发出另一个Soap请求.我已经阅读了如何使用来做到这一点并调用功能文件,并且我已经阅读了如何

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
  • 方法发布
  • def responseArray =我想要的代码的/xml路径/
  • def result =调用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-对于功能调用循环数组位置:0,M4205N,参数不是json或映射

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-转换

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

这篇关于空手道-如何使用从响应数组接收的值循环Soap请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆