Posts

Showing posts with the label java test

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...

Using RequestSpecBuilder in Rest Assured ( Code Reuse )

Image
In the previous post, we studied about how to check response time using Rest Assured. In this post, we would learn about using RequestSpecBuilder in Rest Assured.  You can use the builder to construct a request specification. RequestSpecBuilder is normally used when we have common parameters, Base URI, Base Path between different tests. Let's look at an example without RequestSpecBuilder. 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 setBaseUri () { RestAssured. baseURI = "https://maps.googleapis.com" ; } @Test public void test01 () { given(). param ( "query" , ...

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...

Popular posts from this blog

Using RequestSpecBuilder in Rest Assured ( Code Reuse )