Make Selenium Easy

REST Assured Tutorial 17 – Setting a Default RequestSpecification in Rest Assured

As a part of End to End REST Assured Tutorial , in this post We will learn about “How to set a default RequestSpecification which will be set to each request in Rest Assured?“.

This is an interview question as well. Let’s understand the meaning of this first. We know well now that we can create multiple Request Specification as per our need. Rest Assured provides a way to set a default Request Specification so that it can be sent to each request if no other Request Specification is set. In Java, default value of an int data type is zero. Similar to that we can set a Request Specification as default in Rest Assured.

To set a default Request Specification, we need to use static property “requestSpecification“of RestAssured class. When no other RequestSpecification is set to request, default RequestSpecification will be sent. If we set another request specification to the request, default request specification will be overridden by new one.

Rest Assured Code:-

Output:-

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.

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

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 17 – Setting a Default RequestSpecification in Rest Assured

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