使用RestAssured的响应不包括所有四个键值对,它在Postman中可以正常工作并返回所有四个值。
右下方是我的帖子CREATE USER查询https://reqres.in/的响应。左上方我试图编写一个代码,使用RestAssured运行相同的查询。左下方显示日志。
UserTests类别//创建用户请求编号7(发布请求)System.out.println(“ test_get_single_user_by_ID_returns_http_404()-用户案例7创建”);
Response createUser = (Response) given().queryParam("Content-Type", "application/json")
.body(au)
.when().log().all().post("/api/users")
.then().log().all().assertThat().statusCode(201).extract().response();
String createUserResponse = createUser.asString();
System.out.println(createUserResponse);
JsonPath js = ReUseableMethods.rawToJson(createUserResponse);
System.out.println(au.getCreatedAt());
au.getJob();
System.out.println(js);
控制台响应
{“ id”:“ 117”,“ createdAt”:“ 2020-07-05T11:17:26.597Z”}
必需的响应{“名称”:“ RAK”,“作业”:“自动化测试”,“ id”:“ 683”,“ createdAt”:“ 2020-06-26T07:36:28.264Z”}
问题出在您的内容类型设置上。内容类型必须作为标头而不是queryParam传递。
这将返回完整的对象:
Response createUser = (Response) given().header("Content-Type", "application/json")
.body(au)
.when().log().all().post("https://reqres.in/api/users")
.then().log().all().assertThat().statusCode(201).extract().response();
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句