我想知道是否有一种方法可以记录 restassured 处理的所有调用和响应(url + payload)。
最终目的是拥有一个“调试”测试日志,其中包含所有调用和流量日志。
当然,我可以在自己的代码中发出对记录器的调用,但我更希望全局设置此行为,而不是在所有测试方法中添加记录器调用。
感谢任何提示
我想知道是否有一种方法可以记录 restassured 处理的所有调用和响应(url + payload)。
最终目的是拥有一个“调试”测试日志,其中包含所有调用和流量日志。
当然,我可以在自己的代码中发出对记录器的调用,但我更希望全局设置此行为,而不是在所有测试方法中添加记录器调用。
感谢任何提示
我正在发布一个示例:
Response response = given().
queryParam("apiKey", "abc123").
queryParam("code", code).
queryParam("type", type).
contentType("application/json").
log().all().
when().
get(url).
then().
contentType("application/json").
statusCode(200).
extract().response();
将log().all()设置为您的响应,就可以了。
对不起,这可能是一个愚蠢的问题(或者是我视力的问题),但所有的文档都在这里:
private static PrintStream logps;
try {
// fileoutputstream can be opened in append mode to append the logs every time
// we run
// printstream is enabled for autoflush
logps = new PrintStream(new FileOutputStream("src/test/resources/logfile.txt", true), true);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
RestAssured.filters(new RequestLoggingFilter(logps), new ResponseLoggingFilter(logps));
then()
后面添加log().all()
。 - koppor