根据空手道中的条件验证响应xml

时间:2020-06-17 03:11:36

标签: karate

我从空手道api调用中获取的响应XML如下

<?xml version="1.0" encoding="UTF-8"?>
<response>
   <header>
      <node>
         <p n="CURRENCY">USD</p>
         <p n="REASON">This is a currency breach</p>
      </node>
   </header>
</response>
  • 字符串原因='这是货币违约'

我要验证用例-> if(true)匹配回执包含原因

因为我有两种基于条件的消息。如果在这里匹配,该怎么办。

1 个答案:

答案 0 :(得分:0)

您在这里,请阅读文档:https://github.com/intuit/karate#conditional-logic

* def response =
"""
<?xml version="1.0" encoding="UTF-8"?>
<response>
   <header>
      <node>
         <p n="CURRENCY">USD</p>
         <p n="REASON">This is a currency breach</p>
      </node>
   </header>
</response>
"""
* def condition = true
* def expected = condition ? 'This is a currency breach' : 'blah'
* match /response/header/node/p[@n='REASON'] == expected