如何使用 RestAssured for CreateUser Post 请求获取所有四个键值对

How do I get all four keyValue pairs using RestAssured for CreateUser Post request

使用 RestAssured 的响应不包括所有四个键值对,它在 Postman 和 returns 所有四个值中工作正常。

UserTests Class
// Create user request number 7 (post request)
    System.out.println("test_get_single_user_by_ID_returns_http_404() - User Story 7  CREATE");
    
    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"}

required response
{
    "name": "RAK",
    "job": "Automation testing",
    "id": "683",
    "createdAt": "2020-06-26T07:36:28.264Z"
}

问题出在您的内容类型设置上。内容类型必须作为 header 而不是 queryParam.

传递

这将 return 完整 object:

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