【问题标题】:How to loop SOAP request with values received from a response array如何使用从响应数组接收到的值循环 SOAP 请求
【发布时间】:2022-10-12 17:48:34
【问题描述】:

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

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

对于数组中的每个项目,我想发出另一个 SOAP 请求。我已经阅读了如何使用 tables 执行此操作并调用功能文件,并且我已经阅读了如何使用 loop through an array 并调用 js 函数。我不知道如何遍历数组,并将每个值传递给另一个 SOAP 请求 XML(一次一个)。

我想做这样的事情:

  • 给定soapURL
  • 和方法贴
  • def responseArray = /我想要的代码的xml路径/
  • def 结果 = 调用 read('otherRequest.feature') responseArray

otherRequest.feature 文件看起来像这样:

@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

如何循环遍历数组中的每个项目,并将每个值传递给另一个功能文件?

【问题讨论】:

    标签: arrays api cucumber karate


    【解决方案1】:

    添加这一行应该可以满足您的要求。是的,有一个硬性要求,即“循环”数组应该是 JSON 对象的数组。但是您可以一步转换一组基元:

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

    这记录在这里:https://github.com/intuit/karate#json-transforms

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-07-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多