【问题标题】:Not able to compare response body parameter to its value无法将响应主体参数与其值进行比较
【发布时间】:2022-12-17 08:38:26
【问题描述】:

我的 Response Json 在下面,我想比较它的值

{
    "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",
}

这是我的代码,我在其中写了一些断言

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"));**

我收到以下错误

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

我想验证它的值应该是真的

【问题讨论】:

    标签: java eclipse selenium rest-assured


    【解决方案1】:

    你做错了比赛。你正在尝试比较布尔值true文本"true"

    因此,由于它们的字符串表示形式相同,因此匹配的错误消息看起来具有误导性。

    您应该将代码的最后一行更改为.body("Result.Success", Matchers.equalTo(true));

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多