Ignacio Degeneffe
Ignacio Degeneffe

Reputation: 85

How to do conditional check in karate response?

Is there any way to check if object is empty then ok if not then check if it matches a fixed structure?

I mean, something like:

* def expectedDelayEntries = response.delayEntries == "{}" ? {} : '#(delayEntries)'

Upvotes: 0

Views: 6118

Answers (1)

Peter Thomas
Peter Thomas

Reputation: 58058

Yes. Refer to the docs: https://github.com/intuit/karate#conditional-logic

Do this in 2 steps.

* def expected = condition ? { foo: '#string' } : { bar: '#number' }
* match response == expected

Upvotes: 2

Related Questions