Restful API Automation with RestAssured

aditya goel
3 min readNov 26, 2022

--

In this blog, we shall be building the Automated Tests for set of APIs.

Question #1.) How to log the response of a CREATE API ?

Answer.) Here, we are creating a product, by hitting the Restful API through the help of RestAssured.

Question #2.) Can we supply the Object of Product, while hitting to the CREATE API ?

Answer.) Here, we are creating a product, by hitting the Restful API through the help of RestAssured and we are passing the Object of Product class.

Question #3.) Since GET API usually returns lot of data along with it, can we also verify and assert on the data returned by the GET API ?

Answer.) Yes, for sure. We can assert on the various response-fields. Note here that :-

  • Since, we have lots of products being returned by the GET API, at line #156, we are verifying that total records-count is coming as greater than ZERO.
  • At line #157, we are verifying that, in each of the record being received in the response, we are verifying that, for each record the Id is not null.
  • At line #158, We are verifying that, for each record the Name is not null.
  • And So on..

Question #4.) Can we directly compare the Objects, as returned by the API ?

Answer.) Yes absolutely possible. We can verify on the objects too.

Question #5.) How to perform check on GET API, in case a single object is being queried against ?

Answer.) Here, we are fetching a single product, by supplying the query-parameter in request through RestAssured.

Question #6.) Again In case a single object being queried against, How to perform check on GET API’s response object ?

Answer.) Here, we are fetching a single product, by supplying the query-parameter in request through RestAssured.

  • At line # 201, We are verifying that, whether the id of the object being returned is matching.
  • At line # 203, We are asserting that, whether the description of the object being returned is matching to the expected desc or not ?

That’s all in this blog. We would see you soon again. Till then, do clap on thsis page. :)

--

--