Posts

Showing posts with the label rest client

Automating POST Request using Rest Assured - Part 2

Image
In the previous post, we learned about automating a POST request by sending a string in the body method. In this post, we will focus on automating a POST request by sending an object in the body method instead of string. The reason behind sending an object in body method is that sending a string with large number of parameter can become tedious and updating a string having n number of parameters may become time consuming. Hence, it is always recommended to send an object in body method. Now lets look at an example of automating POST request using Rest Assured. public class Posts { public String id ; public String title ; public String author ; public void setId ( String id ) { this . id = id ; } public void setTitle ( String title ) { this . title = title ; } public void setAuthor ( String author ) { this . author = author ; } public String getId () { return id ; } public...

Automating DELETE request using Rest Assured

Image
In the previous post, we have learned about automating PATCH request using Rest Assured . In this Rest Assured tutorial, we will study about sending DELETE request using Rest Assured. I would highly recommend reading previous posts before proceeding with this one. A DELETE request will delete a resource on the server. Like PUT, this method is rarely permitted on the server for obvious reasons. The db.json file before sending the DELETE request is a follows: Now lets look at example of sending of DELETE request import org.testng.annotations.BeforeClass ; import org.testng.annotations.Test ; import static io. restassured . RestAssured .*; import io.restassured.RestAssured ; import io.restassured.http.ContentType ; public class DeleteRequestTest { @BeforeClass public void setBaseUri () { RestAssured. baseURI = "https://localhost:3000" ; } @Test public void deleteTest () { given() . when () . contentTyp...

To Check Response Time using Rest Assured

Image
In the previous post, we studied about automating delete request using Rest Assured. In this post, we will learn about checking the response time of REST API. I would highly recommend to read previous tutorials before reading this one. Response Time  is nothing but the total time taken to get REST API response. Let's look at the example to check the response time of API installed on our local system using Rest Assured. import org.testng.annotations.BeforeClass ; import org.testng.annotations.Test ; import io.restassured.RestAssured ; import static io. restassured . RestAssured .*; import static org. hamcrest . Matchers . lessThan ; public class VerifyResponseTime { @BeforeClass public void setBaseUri () { RestAssured. baseURI = "http://localhost:3000" ; } @Test public void responseTime () { given() . when () . get ( "/posts" ) . then () . time (lessThan ( 10 l)); } } In the setBaseUri ...

Using ResponseSpecBuilder of Rest Assured ( Code Reuse )

Image
In the previous post, we learned about Using RequestSpecBuilder of Rest Assured . In this post, we will learn about using ResponseSpecBuilder of Rest Assured.  You can use the builder to construct a response specification. ResponseSpecBuilder is usually used when we have some common things to check across multiple tests. For e.g. the status code returned once the API is hit is 200, the contentType of the response returned is JSON, etc.  Let's look at an example without ResponseSpecBuilder. Here we are making use of Google Search API that we studied in  Testing GET Requests and their Responses using Rest Assured . import org.testng.annotations.BeforeClass ; import org.testng.annotations.Test ; import io.restassured.RestAssured ; import io.restassured.http.ContentType ; import static io. restassured . RestAssured .*; public class GetStatusCodeTest { @BeforeClass public void requestSpec () { RestAssured. baseURI = "https://maps.go...

Logging in Rest Assured ( Request Logging ) - Part 1

Image
In the previous post, we learned about Using RequestSpecBuilder in Rest Assured . In this Rest Assured tutorial, we will learn about logging feature provided by Rest Assured. Logging is very useful when you want to know what is send in the request and what you have received in response so that you can  create the correct expectations and send the correct requests. After the release of version 1.5, Rest Assured has started supporting logging of details which are sent in the request. Log method of rest assured supports various logging functions. Let us look at them one by one. log().all() : By adding log().all() to the request you’ll receive detailed information what the client sends to the server i.e. all the request specification details like parameters, header and body. log().params() : By adding log().params() to the request you'll receive information about what the client sends in the request parameters. log().body() : By adding log().body() to the r...

Popular posts from this blog

Extracting an XML Response with Rest-Assured