【问题标题】:RestAssured Assertion failingRestAssured 断言失败
【发布时间】:2019-12-26 21:38:20
【问题描述】:

功能文件片段:

那么messages.type的值应该是ERROR

实际服务响应: “消息”:[ { “类型”:“错误” }]

控制台日志:

JSON 路径 messages.type 不匹配。 预期:包含“错误”的字符串 实际:[错误]

我已经尝试从功能文件中提到的 ERROR 参数中删除双引号,它不起作用

【问题讨论】:

    标签: cucumber rest-assured rest-assured-jsonpath feature-file


    【解决方案1】:

    由于您没有提供您使用的代码,这可能是因为您将 json 响应转换为 String 。请尝试以下代码,因为它有一个如何将 Json 转换为 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
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-27
      • 2021-03-16
      • 2010-09-26
      • 2018-11-09
      • 2021-01-20
      • 2014-06-10
      • 2014-02-10
      相关资源
      最近更新 更多