Make Selenium Easy

REST Assured Tutorial 26 – 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:-

Output:-

In BDD Style:-

Output:-

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.
#ThanksForReading
#HappyLearning

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

My name is Amod Mahajan and I am an IT employee with 6+ years of experience in Software testing and staying in Bengaluru. My area of interest is Automation testing. I started from basics and went through so many selenium tutorials. Thanks to Mukesh Otwani as his tutorials are easy and cover basics to advance. I have habit of exploring concepts by deep diving. I used to make notes. I thought of sharing my knowledge through posts and now I am here. #KeepLearning #ShareLearning

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 26 – Response Logging In Rest Assured

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