问题
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
回答1:
Yes, it has to be pure JS.
* if (response.errors[0].message.includes('Data is not deployed')) karate.abort()
回答2:
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()
来源:https://stackoverflow.com/questions/57407304/how-to-do-conditional-karate-abort-based-on-response