放心-如何根据先前的Json节点的值验证Json响应值

时间:2019-02-15 19:35:58

标签: json rest-assured assertion rest-assured-jsonpath

In Rest Assured , I send a get request and below Json response is received. 

// Json响应

{
  "data": [
    {
      "Name": "REST",
      "Description": "Representational state transfer"
    },
    {
      "Name": "SOAP",
      "Description": "Simple Object Access Protocol"
    }
  }
}

我想验证名称是否为REST,然后描述为代表性状态传输,如果名称为SOAP,则描述为简单对象访问协议。响应中有20多个类似的记录,我该如何使用通用参数放心地做到这一点。

Also please advise how to parameter and do the assertion otherwise it will lead to more than 20 line of assertions alone.

1 个答案:

答案 0 :(得分:0)

完成如下

given()
    .when().get(url)
    .then()
      .root("data")
      .root("find { it.Name == 'REST' }")
          .body("Description", equalTo("Representational state transfer");

希望您能明白。