简体   繁体   English

如何从这个休息端点获得 userId 的最大值? 我必须使用带有 Gpath 语法的 RestAssured

[英]How can i get a max value for userId from this rest endpoint? I have to use RestAssured with Gpath syntax

I have to get a max value for userId using RestAssured and Gpath syntax.我必须使用 RestAssured 和 Gpath 语法获得 userId 的最大值。 I dont know what i should type in body after then.我不知道在那之后我应该在正文中输入什么。

I have tried so many ways but it does not work.我尝试了很多方法,但它不起作用。

@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();
}

You can use like this.你可以这样使用。 i tried and i got 10 as max value.我试过了,我得到了 10 作为最大值。

public static void maxUserId() {

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 JSON 对象上使用 gpath sum() 获取值的总和 - How to get the summation of values using gpath sum() in restassured on JSON Object 在使用 POJO 类时,如何将 then() 块与 RestAssured 一起使用? - How can I use then() block with RestAssured while using POJO classes? 使用 GPath 和 Rest Assured 从响应元素获取值 - Getting the value from the response element using GPath and Rest Assured 如何在 RestAssured 中获取响应值 - How to get response value in RestAssured 如果我想提取 JSON 响应值并避免在开头使用 static 变量,如何在 RestAssured 中使用 HashMaps? - How to use HashMaps in RestAssured if I want to extract the JSON response value and avoid using static variables at the beginning? 如何将RestAssured中的值发布到JSon并从中获取值? - How to post values from RestAssured to JSon and get a value from it? 如何在我的 RestAssured 规范生成器中使用 Basic Auth class - How can I use Basic Auth in my RestAssured spec builder class RestAssured:发送请求后如何获取RequestSpecification字段或参数? - RestAssured: How can I get the RequestSpecification fields or parameters after sending a request? 我想从 RestAssured 的响应中断言“Total”,有人可以建议我怎么做吗 - I want to assert “Total” from the response in RestAssured can someone suggest me how to do that 属性的RestAssured和GPath表达式不一致 - RestAssured and GPath expression for attribute not consistent
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM