Search code examples
javarest-assuredrest-assured-jsonpath

How can I validate a body response without a string?


I'm developing an API Automation test using rest assured. My API response is like:

{
    "is_active": true,
    "token": "s4vj75pj6********"
}

When I send an invalid count is like:

{
    "is_active": false,
    "token": ""
}

So I want to validate the reponse is "true", I developed the following code:

public void responseLoginFacebookBody () {
            Assert.assertTrue(ResponseHolder.getResponseBody().contains("is_active"));
            String responseStatus = ResponseHolder.getResponseJson().get("is_active");
            Assert.assertTrue(responseStatus.equalsIgnoreCase("true"));
        }

but I'm receiving the following message:

java.lang.ClassCastException: java.lang.Boolean cannot be cast to java.lang.String

How can I validate it?


Solution

  • change responseStatus to boolean. It isn't a string in your API response