Make Selenium Easy

REST Assured Tutorial 13 – Writing Response in a Text File

Last updated on December 12th, 2019 at 02:59 pm

As a part of End to End REST Assured Tutorial , in this post We will learn to write response to an external text file in Rest Assured.

You may required to save API response in to an external file like text or JSON etc file for future reference or as a proof. In this post, we will concentrate on saving response in a text file.

Rest Assured provides below methods to get response as:-

  1. As byte array :- asByteArray()
  2. As input stream :- asInputStream()
  3. As string :- asString()

All above methods output can be used to write in to text file.

Rest Assured Code:-


Refresh the project folder if you are using Eclipse. You should see three files as below:-

Open a file you should see it has stored response as below:-

You may be thinking which way is more optimal if you want to write in to a file. If you notice when we get response as String or inputStream , we must need to convert them to Byte array before writing in to a file. In third way we are directly getting Byte Array. So third way is more optimal.

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.

Table of Contents

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

1 thought on “REST Assured Tutorial 13 – Writing Response in a Text File

  1. This is the best thing about your tutorial, you tell concepts like books that too in a noticeably short and precise manner.

    Thanks, keep up the excellent work. Will use asByteArray always

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 13 – Writing Response in a Text File

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