Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
173 views
in Technique[技术] by (71.8m points)

Karate: Match repeating element in xml

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You have to match each serviceGroup.

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...