How to validate Non-JSON response body using Karat

2019-08-14 07:58发布

I am trying to validate an error response body of non-json format. I have tried using the schema as well as a keyword using contains to match. It is not working for me.

Actual Response response returned from API when multiple matches are observed in a post call:

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

My Karate Feature:

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

Tried * match actual[0] == '#(^partSchema)' too from https://gist.github.com/ptrthomas/2a1e30bcb4d782279019b3d5c10b3ed1 . Not working

1条回答
够拽才男人
2楼-- · 2019-08-14 08:39

Please understand type-conversions first: https://github.com/intuit/karate#type-conversion

Then convert the response to a string before you want to do string contains checks:

* string temp = response
* match temp contains 'error'
查看更多
登录 后发表回答