Make Selenium Easy

REST Assured Tutorial 69 – Response Logging In Rest Assured

As a part of End to End REST Assured Tutorial , in this post We will learn :- How to log response specification in Rest Assured?

In last post, we have already learnt Logging request in Rest Assured. Let’s learn Logging Response in Rest Assured.

We can log response specification using log() method provided by ValidatableResponse interface. In fact ValidatableResponse extends ValidatableResponseOptions<ValidatableResponse,Response> interface. log() method returns  ValidatableResponseLogSpec interface reference that allows you to log different parts of the Response.

We have below methods for logging:-

  1. all() – Logs everything in the response, including e.g. headers, cookies, body. Pretty-prints the body if content-type is either either XML, JSON or HTML.
  2. all(boolean shouldPrettyPrint) – Logs everything in the response, including e.g. headers, cookies, body with the option to pretty-print the body if the content-type is either XML, JSON or HTML.
  3. everything() or everything(boolean shouldPrettyPrint) – Same as all() and all(boolean shouldPrettyPrint).
  4. headers() – Logs only the headers.
  5. cookies() – Logs only the cookies.
  6. ifValidationFails() – Logs everything if a test validation fails.
  7. ifValidationFails(LogDetail logDetail) – Logs with the supplied log detail only if the validation fails.
  8. ifValidationFails(LogDetail logDetail,boolean shouldPrettyPrint) – Logs all parameters only if the validations fail.

Rest Assured Code:-


In BDD Style:-


Note:- There is a same method named “log()” to log request and response. Whether it will give you next method to log request or response, depends on where you are using. You can observe that while logging Request , I used log() method before calling HTTP method but while logging Response, I used log() method after calling HTTP method.

You can clone/download example repo here.

If you have any doubt, feel free to comment below.
If you like my posts, please like, comment, share and subscribe.

You can find all Selenium related post here.
You can find all API manual and automation related posts here.
You can find frequently asked Java Programs here.

Author: Amod Mahajan

A software Tester who is paid to judge products developed by others. Currently getting paid in American Dollars. Writing technical posts and creating YouTube videos are my hobbies.

Leave a Reply

Please wait...

Subscribe to new posts to become automation expert

Want to be notified when my new post is published? Get my posts in your inbox.

REST Assured Tutorial 69 – Response Logging In Rest Assured

by Amod Mahajan time to read: 4 min
%d bloggers like this: