Log restassured traffic

devlearn picture devlearn · Oct 30, 2013 · Viewed 13.9k times · Source

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

Answer

Mircea Stanciu picture Mircea Stanciu · Jul 8, 2016

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