Automating the API Testing has never been an easy task. Right from the initial API Testing setup, sequencing API calls to testing parameter combinations, API Testing as a whole has several challenges. Don’t worry! I have shared an overview of REST API, the REST Assured framework and how the framework will help simplifying API Testing using automation.

What is API?

API stands for Application Programming Interface. It acts as an interface between different software systems and establishes their interaction and data exchange.

What is REST API?

REST means REpresentational State Transfer. REST is an alternative to SOAP (Simple Object Access Protocol) and instead of using XML for request REST uses simple URL.

REST API supports both XML and JSON format. It is usually preferred for Mobile and web apps as it makes app work faster and smoother and the supported HTTP methods are GET, POST, PUT, DELETE.

What is REST Assured?

REST-Assured is a Java-based library that is used to test RESTful Web Services.REST Assured is a Java domain-specific language (DSL) for testing REST services. Supports Response parsing and assertions.

Steps to automate the REST API Get Request

  • Create a maven project on eclipse
  • Add the below dependencies in POM.xml file

<dependency>
        <groupId>io.rest-assured</groupId>
        <artifactId>rest-assured</artifactId>
        <version>3.0.2</version>
        <scope>test</scope>
</dependency>
<dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>6.9.10</version>
        <scope>test</scope>
</dependency>
</dependencies>

  • Create a package and class file.
  • Within this class file we need to call the required rest assured methods to call the API and obtain the response code and the message.
  • Use the RestAssured class to generate a RequestSpecification for the URL: http://restapi.demoqa.com/utilities/weather/city/Chennai
  • Mention the HTTP Method type and send the Request to the server
  • Get the Response back from the server
  • Display the returned Response’s Body in Console

Sample Code snippet

Output Window

The below response will be displayed in the Eclipse console window for the above request

 

You would have by now understood what a REST Assured Framework is and how to automate the REST API Get Request along with a sample output. API Testing is an ocean by itself and with the automation disrupting everything, it is important for us to know how to align with the changes.

Having said this, I am ready to hear your thoughts about this blog and any additional insights with regards to Rest Assured Framework. Do post what you think in the comments section below!

Reference

https://www.toolsqa.com/rest-assured-tutorial/
https://devops.com/top-6-challenges-api-testing/

 

 

 




Ready to Write an Interesting blog in QA Touch?


If you have an interesting blog post you would want to share with the Testing Community, please forward it to info@qatouch.com along with your picture and a short bio. Our editorial team will review and publish it.

Subscribe to our blog

Kannathasan

Kannathasan

Kannathasan is a Certified Tester (Foundation level ). He loves testing eCommerce applications and ferreting out hidden bugs. Likes solving challenging puzzles during his free time.

Leave a Reply

avatar