How to do conditional Karate abort based on response

守給你的承諾、 提交于 2021-01-28 06:00:49

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!