Home > OS >  How to assert attributes value using sibling attribute value in hamcrest matcher
How to assert attributes value using sibling attribute value in hamcrest matcher

Time:08-31

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.

CodePudding user response:

It would be

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