Automate REST API testing with ROBOT framework

Robot Framework is language-agnostic open-source test automation framework for test automation and robotic process automation (RPA).
It is operating system and application independent. Several standard libraries are bundled with the framework, and there are separately developed external libraries galore that can be installed based on your needs. Libraries provide the actual automation and testing capabilities to framework by providing keywords. Test cases are written using a keyword-testing methodology written in a tabular format. You get more information about it here

Why ROBOT Framework ?

Might be thinking there are already quite a number of Rest API testing frameworks like Postman, SoapUI, JMeter, Rest-Assured and several others.
How is wrting test cases using Robot Framework different from others. Robot framework is language-agnostic, you need not learn any language or scripting for write test cases. ROBOT framework is not only for REST APIs testing, it can be used for testing GUI (using selenium library ), verify database (using database library) and there are many more libraries which can be leveraged.

For example if you have test case with steps, perform REST API POST operation, check in DB to see object is created and fianlly verify POST response is valid. All the above steps can be verified in one test case written with ROBOT framework

Using RestInstance Library

Here we will see how to use RESTinstace library that is part of the Robot framework to test RESTful APIs. The Keywords provided in the library are simple to use, supports all the methods (GET, PUT, POST, PATCH, DELETE) , supports sending custom the headers, keywords for validating the reasponse header and also validates JSON using JSON Schema.

Here is the sample test case

*** Settings ***
Library String
Library REST ssl_verify=false
Set expectations
Expect response { "status": { "enum": [200, 201, 204, 400] } }
Expect response { "seconds": { "maximum": 2} }
*** Test Cases ***Get Employee
GET employee/1001
Output response body
String response body employee 1001

Above test case sends GET request to <url>/employee/1001 , and then verifies the following output API out in JSON format

{"employee": "1001"}

You can get more sample test cases from author of this library from here

Running the Test cases

I have created Docker Image for Robot Framework and then installed RESTinstace library, so we can run tests isolated from the application.
This kind of setup will be helpful for running smoke and regression tests after deploying the application and without distrubing the application. You can find scripts to build Docker image here.

To build image run the script Once the Docker image is create and available, you can use to run test cases placed in tests folder

Test case to test REST API

In test case i am using to test REST API . Run the test case placed in tests folder using , it launches a docker, copies the test cases and executes them.

The Robot Framework output files are put in the same directory under results/. In the console you can see it has created log.html (detailed report) and report.html (execution summary)

Image for post

Test Execution Results

Robot Framework genrates nice test report for all the test-case executed with detailed steps and execution status.

Image for post


Robot Framework can be used to write smoke and regression test cases and test the application in isolation and RestInstance is a powerful library in terms of JSON schema checking and validations. You can get more information about RESTInstance here

Written by

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store