1

Given have the following list of steps

Given path 'verify'
And header x-api-key = apiKey
And header tenant-id = tenantId
And request a_json_object_with_invalid_user_id_to_verify
When method put
Then status 404

When the endpoint returned HTTP 200 (which is a bug that i need to fix) but with an invalid json response such as

{
  "score" : 
}

This exception is thrown

com.jayway.jsonpath.InvalidJsonException: net.minidev.json.parser.ParseException: Unexpected character (}) at position 15.
    at com.jayway.jsonpath.spi.json.JsonSmartJsonProvider.parse(JsonSmartJsonProvider.java:64)
    at com.jayway.jsonpath.internal.JsonContext.parse(JsonContext.java:82)
    at com.jayway.jsonpath.JsonPath.parse(JsonPath.java:596)
    at com.intuit.karate.JsonUtils.toJsonDoc(JsonUtils.java:84)
    at com.intuit.karate.StepDefs.method(StepDefs.java:344)

I expect to see the test failed because of wrong status code 200 received of the expected 404. I would like to know if throwing this exception is correct in karate?

Thanks.

1 Answer 1

1

I apologize for mis-reading your question.

There is indeed a bug in Karate when handling malformed JSON responses.

We have opened an issue, you should be able to get a patch version very soon: https://github.com/intuit/karate/issues/259

Sign up to request clarification or add additional context in comments.

3 Comments

But in this case i am sending a valid json object (as request) and it is the reply json that is in an invalid format. The object that i am sending contains an invalid user id that is suppose to make the backend API return 404 (indicating user not found) I tried changing 404 to 200 but i am still getting json parsing error. it seems to be that if a response is invalid, karate is reporting parsing error and stopping there and not actually executing the Then step
@david sorry for my earlier response, thanks for finding this bug in Karate ! please see my edit.
@david can you try version 0.6.2.1 and see if it fixes the problem ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.