我如何从此其余端点获取userId的最大值?我必须将RestAssured与Gpath语法一起使用

时间:2019-09-18 09:03:46

标签: rest-assured jsonpath gpath

我必须使用RestAssured和Gpath语法获取userId的最大值。在那之后我不知道该输入什么内容。

我尝试了很多方法,但是没有用。

@BeforeClass
public void setUp() {
    endpoint = "https://jsonplaceholder.typicode.com/posts/";
}


public static Response getJsonPath(String endpoint) {
    return
            when().
                    get(endpoint).
                    then().
                    statusCode(200).
                    contentType(ContentType.JSON).extract().response();
}


@Test
public void maxUserId() {

    Response response = getJsonPath(endpoint)
            .then()
            .assertThat()
            .body();
}

1 个答案:

答案 0 :(得分:0)

您可以像这样使用。我尝试过,我得到了10作为最大价值。如果可以,请接受答案

public static void maxUserId() {

    int maxValue = getJsonPath(endpoint).jsonPath().get("userId.max()");
    System.out.println(maxValue);
}