Home > Software design >  Not able to compare response body parameter to its value
Not able to compare response body parameter to its value

Time:12-19

My Response Json is below which i want to compare its value

{
    "Result": {
        "user": {
           "PersonData": null,
            "Locale": null,
            "Attributes": {
                "IsEnabled": null,
                "LocaleSettings": null,
                "LockoutEnabled": "True",
                "AccessFailedCount": "0"
            }
        },
        "RefreshToken": "745acf0f-de47-4f4c-8abe-b3d7d505fc60",
        "Success": true,
        "Errors": null
    },
    "StatusCode": "200",
}

Here is my code where i have written some assertions

given().body(request.toJSONString()).header("Content-Type", sitedata.getProperty("Content-Type"))
                .header("ApplicationCode", sitedata.getProperty("ApplicationCode"))
                .header("Authorization", sitedata.getProperty("Authorization")).when()
                .post(sitedata.getProperty("BaseUrl")   sitedata.getProperty("login"))
                                .then().log().all().statusCode(200)
                .body(Matchers.containsString("Success"))
                               ** .body("Result.Success", Matchers.equalTo("true"));**

I am getting below error

JSON path Result.Success doesn't match.
Expected: true
  Actual: true

I want to validate its value should be true

CodePudding user response:

You are doing wrong match. You are trying to compare boolean true vs text "true"

So since their string representations are equal the matching error message looks misleading.

You should change the last line of your code to .body("Result.Success", Matchers.equalTo(true));

  • Related