Karate 空手道中基于条件的响应xml验证

Karate 空手道中基于条件的响应xml验证,karate,Karate,我对KarateAPI调用的响应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>

我对KarateAPI调用的响应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>

美元

这是货币违约

  • 字符串原因='这是货币违约'
我想验证用例-->是否(true)匹配reposne包含原因


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

给你,请阅读文档:

*def响应=
"""
美元

这是货币违约

""" *def条件=真 *def预期=条件?“这是货币违约“:“废话” *匹配/响应/标题/节点/p[@n='REASON']==应为
对不起,Peter thomas,我已经更新了。我曾试图诚实地格式化它,但网站只是把它还给了我。我使用了另一个网站并更正了它。非常感谢,很抱歉xml格式的早期问题。
* 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