【问题标题】:Karate: Match repeating element in xml空手道:匹配 xml 中的重复元素
【发布时间】:2019-08-20 07:53:19
【问题描述】:

我正在尝试将 xml 中的重复元素与空手道模式相匹配。

XML 消息

* def xmlResponse =
"""
<Envelope>
   <Header/>
   <Body>
      <Response>
         <Customer>
            <keys>
               <primaryKey>1111111</primaryKey>
            </keys>
            <simplePay>false</simplePay>
         </Customer>
         <serviceGroupList>
            <serviceGroup>
               <name>XXXX</name>
               <count>1</count>
               <parentName>DDDDD</parentName>
               <pendingCount>0</pendingCount>
               <pendingHWSum>0.00</pendingHWSum>
            </serviceGroup>
            <serviceGroup>
               <name>ZZZZZ</name>
               <count>0</count>
               <parentName/>
               <pendingCount>3</pendingCount>
               <pendingHWSum>399.00</pendingHWSum>
            </serviceGroup>
         </serviceGroupList>
      </Response>
   </Body>
</Envelope>
"""

我想将每个与以下空手道模式匹配

 Given def serviceGroupItem =
  """
    <serviceGroup>
               <name>##string</name>
               <count>##string</count>
               <parentName>##string</parentName>
               <pendingCount>##string</pendingCount>
               <pendingHWSum>##string</pendingHWSum>
            </serviceGroup>
  """

我就是这样尝试的

  * xml serviceGroupListItems = get xmlResponse //serviceGroupList
  * match each serviceGroupListItems == serviceGroupItem

但它不起作用。知道如何使它工作

【问题讨论】:

标签: karate


【解决方案1】:

你必须匹配每个 serviceGroup。

* xml serviceGroupListItems = get xmlResponse //serviceGroupList
* match each serviceGroupListItems.serviceGroupList.serviceGroup == serviceGroupItem.serviceGroup

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-21
    • 1970-01-01
    • 2017-11-30
    • 1970-01-01
    相关资源
    最近更新 更多