如何使用放心将响应日志保存在变量中?

时间:2018-09-25 04:17:41

标签: java rest-assured

以下是我的要求,在控制台中,我能够看到要存储在变量中的日志。

RestAssured.baseURI =“ https://www.dummy.com//services”;

            RestAssured.given().
            headers("data",crypto). 
        when().
            post("//auth.svc/auth").
        then().contentType(ContentType.JSON).log().all();

1 个答案:

答案 0 :(得分:2)

Response response = RestAssured.given().
             headers("data",crypto). 
             when().
             post("//auth.svc/auth").
             then().contentType(ContentType.JSON).
             extract().response();

然后,您可以使用response.asString()将响应另存为字符串,或者使用JsonPath对象检查json。例如:

JsonPath jsonPathEvaluator = response.jsonPath();
jsonPathEvaluator.get("xyz");