How to send meaningful failure reason in karate when the response array is empty?

Viewed 295

I am trying to display a meaningful failure reason if the returned response is empty. I have tried to do it in the following way:

* def message = offers == "#[_ > 0]" ? 'OK' : 'Empty response'
* match message == 'OK'

The code returns 'Empty response' even if the offers is not empty. If I run separately

* match offers == "#[_ > 0]"

the check passes.

I have two questions:

  1. Why is the expression evaluated to false in the condition?

  2. Is there another way to display failure messages in karate?

1 Answers

You are trying to use a match short-cut where JavaScript is expected.

Please change to:

* def offers = []
* def message = offers.length > 0 ? 'ok' : 'empty'
* match message == 'empty'

No Karate does not support custom messages because the HTML reports typically have everything you need, including HTTP traffic / logs. But you can always print anything you want.

Related