繁体   English   中英

如何使用空手道验证非JSON响应主体

[英]How to validate Non-JSON response body using Karate

我正在尝试验证非json格式的错误响应正文。 我尝试使用架构以及使用包含匹配的关键字。 它对我不起作用。

在帖子调用中观察到多个匹配项时,从API返回的实际响应响应:

{"error":{"text":SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'NewEmp' for key 'employee_name_unique'}}

我的空手道特征:

Given url 'http://dummy.restapiexample.com/api/v1/create'
def errResp = "error"  
And request {"name":"Hello1","salary":"123","age":"23"}
When method POST
Then status 200
Then match $ contains error #not working
Then match $ contains errResp #not working

https://gist.github.com/ptrthomas/2a1e30bcb4d782279019b3d5c10b3ed1也尝试过*匹配实际的[0] =='#(^ partSchema)'。 不工作

请首先了解类型转换: https : //github.com/intuit/karate#type-conversion

然后,在要执行字符串包含检查之前,将响应转换为字符串

* string temp = response
* match temp contains 'error'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM