关于 XML 空手道响应的断言

Assertions on XML response in Karate

如何在 XML 中的此类响应中应用断言。

我尝试先使用

在 json 中转换它

* json response = response

但是这个 returns 在通过 json 验证器检查时无效 json。正如我认为在 JSON 中转换然后匹配响应会更容易。

** 断言**

  1. 检查第一个标签是否为 Resource
  2. 检查 typetype1
  3. 检查 valueTotal 是 7
  4. 检查 /Resource/entry/url 值为 https://myurl1
  5. 勾选/Resource/entry/resource/user/identifier/type/coding/code 值为 CC
<Resource xmlns="http://myurl">
   <type xmlns="" value="type1"/>
   <valueTotal xmlns="" value="7"/>
   <entry xmlns="">
      <url value="https://myurl1"/>
      <resource>
         <user>
            <id value="123"/>
            <identifier>
               <type>
                  <coding>
                     <system value="http://myurl2"/>
                     <code value="CC"/>
                     <display value="abcedflk"/>
                  </coding>
                  <text value="test"/>
               </type>
               <system value="http://myurl3"/>
               <value value="90204343"/>
            </identifier>
            <patient>
               <reference value="value/new"/>
            </patient>
            <relationship>
               <extension url="http://myurl4">
                  <valueCodeableConcept>
                     <coding>
                        <system value="http://myurl5"/>
                        <code value="xyz"/>
                        <display value="value11111"/>
                     </coding>
                     <text value="value11111"/>
                  </valueCodeableConcept>
               </extension>
            </relationship>
            <name>
               <family value="ABC"/>
               <given value="TEST"/>
               <given value="JON"/>
            </name>
            <gender value="male"/>
            <birthDate value="1990-02-17"/>
         </user>
      </resource>
      <search>
         <mode value="123zbc"/>
      </search>
   </entry>
      <entry xmlns="">
      <url value="https://myurl1"/>
      <resource>
         <user>
            <id value="123"/>
            <identifier>
               <type>
                  <coding>
                     <system value="http://myurl2"/>
                     <code value="CC"/>
                     <display value="abcedflk"/>
                  </coding>
                  <text value="test"/>
               </type>
               <system value="http://myurl3"/>
               <value value="90204343"/>
            </identifier>
            <patient>
               <reference value="value/new"/>
            </patient>
            <relationship>
               <extension url="http://myurl4">
                  <valueCodeableConcept>
                     <coding>
                        <system value="http://myurl5"/>
                        <code value="abc"/>
                        <display value="value22222"/>
                     </coding>
                     <text value="value22222"/>
                  </valueCodeableConcept>
               </extension>
            </relationship>
            <name>
               <family value="ABC"/>
               <given value="TEST"/>
               <given value="JON"/>
            </name>
            <gender value="male"/>
            <birthDate value="1990-02-17"/>
         </user>
      </resource>
      <search>
         <mode value="123yyy"/>
      </search>
   </entry>
</Resource>

假设 XML 在变量 response 中:

# the first 2 lines are un-necessary, as all the
# XPath assertions start with /Resource
* json asJson = response
* match asJson contains { Resource: '#present' }
* match /Resource/type/@value == 'type1'
* match /Resource/valueTotal/@value == '7'
* match /Resource/entry[1]/url/@value == 'https://myurl1'
* match /Resource/entry[1]/resource/user/identifier/type/coding/code/@value == 'CC'

如果需要,请复习 XML 和 XPath:https://github.com/karatelabs/karate#advanced-xpath