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.
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
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.
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.
In the Next blog we would be looking into, how to work with PUT and POST API using Rest Assured.
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