rahul rai
rahul rai

Reputation: 2326

How to assert attributes value using sibling attribute value in hamcrest matcher

Given an API response as:

{
    "res": [
        {
            "id": 1,
            "name": "a",
        },
        {
            "id": 2,
            "name": "b",
        }
    ]
}

How can I assert using hamcrest matcher that name field for object with id 1 is a.

Upvotes: 0

Views: 39

Answers (1)

lucas-nguyen-17
lucas-nguyen-17

Reputation: 5917

It would be

given()...
        .then()
        .body("res.find {it.id == 1}.name", equalTo("a"));

Upvotes: 1

Related Questions