[英]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.