Karate: Match repeating element in xml

人走茶凉 提交于 2021-02-05 09:12:00

问题


I'm trying to match a repeating element in a xml to karate schema.

XML message

* 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>
"""

I want to match each with following karate schema

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

This is how I tried

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

But it doesn't work. Any idea how can I make it work


回答1:


You have to match each serviceGroup.

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


来源:https://stackoverflow.com/questions/55416312/karate-match-repeating-element-in-xml

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!