Sometimes GET call is returning [] empty array
. I can use .body(size)
, but I do not want to use hard assertions.
It can be empty or have an array of objects, so I want to use if condition to make a decision to proceed further based on empty/not empty.
The code is as below:
given().when().get(url).then().body("[0].name",equalTo(value))
Any help would be appreciated.
you can try with the below way
Response res = given().when().get(url);
if(!(res.body().asString().equals("null"))
{
// do what you want to check or action
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.