如何使用空手道验证非 JSON 响应主体
How to validate Non-JSON response body using Karate
我正在尝试验证非 json 格式的错误响应正文。我尝试过使用架构以及使用包含来匹配的关键字。它对我不起作用。
在 post 调用中观察到多个匹配项时从 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 中的 actual[0] == '#(^partSchema)' 匹配。不工作
请先了解类型转换:https://github.com/intuit/karate#type-conversion
然后在你想做之前将响应转换为字符串 string contains checks:
* string temp = response
* match temp contains 'error'
我正在尝试验证非 json 格式的错误响应正文。我尝试过使用架构以及使用包含来匹配的关键字。它对我不起作用。
在 post 调用中观察到多个匹配项时从 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 中的 actual[0] == '#(^partSchema)' 匹配。不工作
请先了解类型转换:https://github.com/intuit/karate#type-conversion
然后在你想做之前将响应转换为字符串 string contains checks:
* string temp = response
* match temp contains 'error'