Reputation: 1755
I'd like to know if there is a way of logging all the calls and responses (url + payload) processed by restassured.
THe finality would be to have a "debug" test log with all the calls and traffic logged.
Of course I could issue calls to the logger in my own code, but I'd prefear to set this behavour globally and not to add logger calls in all my test methods.
Thanks for any pointers
Upvotes: 16
Views: 17472
Reputation: 1
Here are the steps to log to a log file and configure globally to log both request and response details for all the tests
create static printstream object
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();
}
In beforeall static method, apply the default implemented request and response logging filters and enable them to use print stream
RestAssured.filters(new RequestLoggingFilter(logps), new ResponseLoggingFilter(logps));
Now we need not specify log() method individually for requests and responses and also the logs will be sent to the log file
Upvotes: 0
Reputation: 3753
I am posting an example:
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();
Upvotes: 19
Reputation: 1755
Sorry dumb question (or issue with my vision), everything is documented under:
Upvotes: 1