Posts

Showing posts with the label Software Testing Tutorials

Testing GET Requests and their Responses using Rest Assured

Image
What is a GET Request? The GET method is used to retrieve information from the given server using a given URI. Requests using GET should only retrieve data and should have no other effect on the data. Way to send GET Request using Rest Assured and Check Status Code: For this exercise, we will use Google Places API ( Place Search ). You can view the API at below link : Google Place Search API We will learn about the Text Search GET request of Google Places API. A Text Search request is an HTTP URL of the following form: https://maps.googleapis.com/maps/api/place/textsearch/output?parameters where  output  may be either of the following values: json  (recommended) indicates output in JavaScript Object Notation (JSON) xml indicates output as XML Certain parameters are required to initiate a search request. As is standard in URLs, all parameters are separated using the ampersand ( & ) character. Testing HTTP Error Codes We will verify t...

Extracting a JSON Response with Rest-Assured

Image
In the earlier post, we studied about Testing GET Requests and their Responses using Rest Assured , before following this tutorial, I would recommend reading the previous one. In this post, we will learn about extracting JSON Response using Rest Assured. Once the response is extracted we will store it into Response class and later various tests can be performed to check whether extracted response is correct. I would assume that everyone following this tutorial has knowledge of Java and TestNG. If you need help then please follow tutorials on Java and TestNG . Now let's look at an example where we will search for a particular Railway Station in Mumbai City and print the response. import org.testng.annotations.BeforeClass ; import org.testng.annotations.Test ; import io.restassured.RestAssured ; import io.restassured.http.ContentType ; import io.restassured.response.Response ; import static io. restassured . RestAssured .*; public class GetJsonResponseTest { ...

Extracting an XML Response with Rest-Assured

Image
In the earlier post, we studied about  Extracting a JSON Response with Rest-Assured , before following this tutorial, I would recommend reading the previous one. In this post, we will learn about extracting an XML Response using Rest Assured. Once the response is extracted we will store it into Response class and later various tests can be performed to check whether extracted response is correct.  I would assume that everyone following this tutorial has knowledge of Java and TestNG. If you need help then please follow tutorials on  Java  and  TestNG . Now let's look at an example where we will search for a particular Railway Station in Mumbai City and print the response. import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import static io.restassured.RestAssured.*; import io.restassured.RestAssured; import io.restassured.http.ContentType; import io.restassured.response.Response; public class GetJsonResponseTest { ...

Install and Configure REST API for Rest Assured

Image
In the previous post we learned about Extracting a JSON Response with Rest Assured and JSON Path . In this post we will Install and Configure a Fake Rest API on our local system. Below is the REST API that will be Installing on our system: JSON-SERVER First, we will create a db.json file and place it on desktop: { "posts" : [ { "id" : 1 , "title" : "json-server" , "author" : "typicode" } ], "comments" : [ { "id" : 1 , "body" : "some comment" , "postId" : 1 } ], "profile" : { "name" : "typicode" } } Then, we will install a JSON-SERVER on our local system using the following command: $ npm install -g json-server You will see output as following: Now to traverse to Desktop via Terminal and then start JSON-SERVER using following command: json-server --watch db.json You will see outp...

Automating POST Request using Rest Assured - Part 1

Image
In the previous post, we learned about how to install and configure the API Server on our local system. In this post, we learn to automate a POST request to API installed on our local system by sending a string in the body method.  Rest Assured supports all the HTTP methods like GET, POST, PUT and DELETE. Here GET stands for Read operation, POST stands for Write operation, PUT stands for Update operation and DELETE as the name suggests it stands for Delete operation. Now let's look at an example of POST Request 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 PostRequestTest { @BeforeClass public void setBaseUri () { RestAssured. baseURI = "http://localhost:3000" ; } @Test public void postString () { given(). body ( ...

Automating PUT Request using Rest Assured

Image
In the previous post, we learned about Automating POST Request by sending object in the body of the request. I would highly recommend to read the previous tutorials before proceeding with this one. In the current post, we will study about Automating PUT request by using Rest Assured. PUT request puts a file or resource at a precise URI, and exactly at that URI. If there's already a file or resource at that URI, PUT replaces that file or resource. If there is no file or resource there, PUT creates one.  PUT request is used to update the existing records. In the body we can send string as well as Java object. But we always send Java object in body. The db.json file before sending the PUT request is a follows: Now let's see an example of sending PUT Request using Rest Assured. import com.restapiclass.Posts ; import io.restassured.RestAssured ; import io.restassured.http.ContentType ; import static io. restassured . RestAssured .*; import org...

Popular posts from this blog

Extracting an XML Response with Rest-Assured