Make Selenium Easy

REST Assured Tutorial 4 – Let’s Write First GET REST Assured Test

Last updated on December 10th, 2019 at 02:21 pm

As a part of End to End REST Assured Tutorial , in this post We will write first GET request in REST assured.

I will strongly recommended you to learn basics of API testing from here.

We will automate a GET request named “GetBookingIds” from Restful Booker. We will verify status code and line of request.

I will not start with BDD pattern or builder pattern as of now. I will go step by step so that you do not confuse with the flow.

Let’s start with some basic points about Rest Assured:-

  1. RestAssured is a class which consists many static fields and methods.
    It supports POST, GET, PUT, DELETE, HEAD, PATCH and OPTIONS requests and to verify the response of these requests.
  2. RestAssured has a static overloaded method named get() which returns a reference of Response interface. In fact return type of all http methods in RestAssured class is of type Response. This response contains every details returned by hitting request i.e. response body, response headers, status code, status lines, cookies etc.
  3. To validate response like status code or value , we need to get reference of type ValidatableResponse. ValidatableResponse is an interface. Response interface has a method named “then()” which returns ValidatableResponse. In fact there is an interface called “Validatable” which has “then()” method. Response interface extends
    Validatable Interface. The implemented class of Response interface is
    RestAssuredResponseImpl. We will see hierarchy of classes and interfaces later.
  4. Once we get ValidatableResponse reference, we can do many assertions. In this post, we will verify status code and status line. It consists of many validation methods.

REST Assured code example:-

Non-BDD Style Code:-

BDD Style Code:-

BDD with static import style code:-

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

3 thoughts on “REST Assured Tutorial 4 – Let’s Write First GET REST Assured Test

  1. java.lang.SecurityException: Signers of ‘org.hamcrest.Matchers’ do not match signers of other classes in package

    getting this error, cn you please help?

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 4 – Let’s Write First GET REST Assured Test

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