1

I have a question about how to handle different responses for the same request in Karate api test. E.g. The same request: Given path '/tickets/2000' When method get Response: 1> if ticket #2000 is not expired, then match response = expected result 2> if ticket #2000 is expired, then matching response.error = 'Ticket is expired'

So how to match the 2 different results. I need to handle both. Can I use "Try... Catch", how to use it? Can you give me a syntax example in Karate, please?

Thanks

qalinda
  • 31
  • 1

1 Answers1

0

Karate discourages "conditional logic" like this. What I would do is just set that field to #ignore or #string:

* match response == { error: '#string' }

For conditional checks, you can refer this answer: https://stackoverflow.com/a/50676868/143475

Also please refer this answer for some extra guidance: https://stackoverflow.com/a/54126724/143475

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248