Reputation: 5
Feature File Snippet:
Then The value of messages.type should be ERROR
Actual Service Response: "messages": [ { "type": "ERROR" }]
Console Log:
JSON path messages.type doesn't match. Expected: a string containing "ERROR" Actual: [ERROR]
I have tried removing double quotes from ERROR parameter mentioned in feature file, it doesn't works
Upvotes: 0
Views: 498
Reputation: 2000
SInce you not provided the code you used, this can be due to the fact that you dint convert the json response to a String . Please try with below code since it has an example to how to convert Json to String .
public void jsonPathExample() {
Response response=given().contentType(ContentType.JSON).get("http://localhost:3000/posts");
//we need to convert response as a String
JsonPath jsonPath = new JsonPath(response.asString());
String actualtype = jsonPath.getString("type");
//Then do your assertion
}
Upvotes: 0