1
votes

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.

1
What is your question? Where is your code? - dat3450
thanks for reply. I am using given().when().get(url).then().body("[0].name",equalTo(value)) . but when it is empty it's throwing cannot get name on null object illegal argument error - babu arigs

1 Answers

0
votes

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
}