如何根据反应条件空手道中止 [英] How to do conditional Karate abort based on response
问题描述
如果由于另一个团队的代码导致特定错误响应失败,我们将尝试中止方案.
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']
我们知道我们可以使用karate.abort(),但是在文档中我们仅看到基于状态码的示例:
* if (responseStatus == 404) karate.abort()
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()
谢谢
推荐答案
对于遇到类似情况(可选中止)的任何人,我们可以使用以下方法解决它:
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()
这篇关于如何根据反应条件空手道中止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!