0

私は自分のAPIを自動化したことで安心して訴訟を起こしています。これが私のjsonResponseです:-

{
    "al": [{
            "aid": 1464,
            "_r": "Bus Stand,",
            "_l": "spaze it park2,",
            "_c": ",",
            "_s": "Haryana,",
            "co": "India,",
            "pc": "122001",
            "fa": "Sona Road, spaze it park, Gurgaon, Haryana,",
            "fn": "225,",
            "lm": "omax mall",
            "pa": null,
            "at": 1
        },
        {
            "aid": 1462,
            "_r": "Bus Stand,",
            "_l": "spaze it park2,",
            "_c": "Gurgaon,",
            "_s": "Haryana,",
            "co": "India,",
            "pc": "122001",
            "fa": "Sona Road, spaze it park, Gurgaon, Haryana,",
            "fn": "225,",
            "lm": "omax mall",
            "pa": null,
            "at": 1
        },
        {
            "aid": 1461,
            "_r": null,
            "_l": null,
            "_c": "Gurgaon1",
            "_s": "",
            "co": null,
            "pc": "122003",
            "fa": "Gurgaon, HRyana, 122003",
            "fn": "",
            "lm": "",
            "pa": null,
            "at": -1
        },
        {
            "aid": 1460,
            "_r": "Bus Stand,",
            "_l": "spaze it park2,",
            "_c": "Gurgaon,",
            "_s": "Haryana,",
            "co": "India,",
            "pc": "122001",
            "fa": "Sona Road, spaze it park, Gurgaon, Haryana,",
            "fn": "225,",
            "lm": "omax mall",
            "pa": null,
            "at": 2
        }
    ]
}

ここで、"aid": 1460 を持つ jasonarray のアサーションを入れたいと思います。たとえば、lm の値などのパラメータです。安心して同じことができる方法。「援助」を持つjsonarrayのインデックス位置も知りたい:1460.助けてください!!

4

2 に答える 2

0

アサーションに関しては、RestAssured 組み込みGPathクエリ構文を使用できます。

RestAssured.given()
        .baseUri("http://your.server.com")
        .accept(ContentType.JSON)
        .get("/jsonFile")
        .then()
        .statusCode(200)
        .body("al.findIndexOf { it.aid == 1461 }", is(2))       // findIndexOf returns zero-based list index
        .body("al.find { it.aid == 1461 }._c", is("Gurgaon1"))
        .body("al.find { it.aid == 1461 }.pc", is("122003"));
于 2018-03-25T13:20:20.733 に答える