1

We are trying to abort scenario if there is a failure with specific error response caused by another team's code.

Case example for this is that we want to abort the test if we received error

errors: [message: 'Data is not deployed....Etc etc']

We know that we can use karate.abort(), however on the documentation we only see example based on status code: * if (responseStatus == 404) karate.abort()

I wonder if it is possible for us to do something like

* if (response.errors[0].message contains 'Data is not deployed') karate.abort()

Thanks

Raymond
  • 561
  • 1
  • 8
  • 23

2 Answers2

1

Yes, it has to be pure JS.

* if (response.errors[0].message.includes('Data is not deployed')) karate.abort()
Peter Thomas
  • 47,282
  • 14
  • 68
  • 196
  • Hi Peter! I tried the above but I received an error instead: `javascript evaluation failed: if (response.errors[0].message.includes('Data is not deployed')) karate.abort(), TypeError: response.errors[0].message.includes is not a function` – Raymond Aug 09 '19 at 06:57
  • Hi Peter. Thanks a lot! I solved it by using `.indexOf` instead of `.includes`. Cheers – Raymond Aug 09 '19 at 07:13
1

For anyone facing similar situation (optional abort), we solve it using this:

* if (response.errors!= null && response.errors[0].message.indexOf('Error Message') > -1) karate.abort()
Raymond
  • 561
  • 1
  • 8
  • 23