Reputation: 153
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
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