Automating GET and DELETE Request Using Rest Assured Testing


Automating GET and DELETE Request Using Rest Assured Testing

In the previous blog, we already have understood the basic terminology that we will be using during rest assured testing. We also have seen that how to setup Rest Assured JAR or maven dependency in our project.


In this blog, we will try to automate two very simple basic API (GET and Delete) to get some hands-on experience. 

For this purpose, I would be using https://reqres.in/ which provides a few sample API for testing.

Please note in order to use Rest Assured effectively we need to do some static import manually in our eclipse IDE.

import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;

Let’s first start with One Simple Get Request on https://reqres.in/




As shown in the below screenshot once we fire the Get Request to Server. The server will respond back with status Code 200 which means the response is a success along with body.




In this case, our Base URI is: https://reqres.in/ 
and successive URI for passing Get request is "/api/users?page=2".

Before Moving Further to Coding part let's fire the same request in Postman and see the response.



As we can see in the above screenshot we are getting the same response along with some additional details in the form of Cookies and headers which will ultimately help us to validate different scenarios while doing API Testing.



Below is the first test for getting the list of the user. As you might observe in the below code we have written all the code in BDD Format using Given, When, Then and extract the response in the form of String.


Now you might be wondering it out how I have asserted i.e validated different values from the server which I am not getting while seeing the response

For that purpose Postman Will help us a lot.




As shown in the above screenshot for validating the Header response we need to use the header in the code and similarly need to use body for validating any specific response from JSON Body.

Below is the output for Code execution.




Similarly, we can use below Delete request which will respond back with status code 204 Means No content on Server.




Code for Delete Response is

In the Next blog we would be looking into, how to work with PUT and POST API using Rest Assured.




SHARE THIS

Author:

My Name is Ankur Jain and I am currently working as Automation Test Architect.I am ISTQB Certified Test Manager,Certified UI Path RPA Developer as well as Certified Scrum Master with total 12 years of working experience with lot of big banking clients around the globe.I love to Design Automation Testing Frameworks with Selenium,Appium,Protractor,Cucumber,Rest-Assured, Katalon Studio and currently exploring lot in Dev-OPS as well. I am currently staying in Mumbai, Maharashtra. Please Connect with me through Contact Us page of this website.

Previous Post
Next Post
June 29, 2020 at 10:47 PM

Excellent Tutorial on Rest Assured API Testing services. This is awesome content I have seen so far. Hoping many more such good articles and latest updates on testing is awaited.

Reply
avatar