RAKESH M
RAKESH M

Reputation: 153

Validating response xml based on condition in Karate

My response xml from the karate api call is as below

<?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>

I want to validate a use case --> if(true) match reposne contains reason

As I am having two type of messages based on a condition. How can I do if with match here.

Upvotes: 1

Views: 1923

Answers (1)

Peter Thomas
Peter Thomas

Reputation: 58058

Here you go, and please read the docs: 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

Upvotes: 1

Related Questions