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 response header and also validates JSON using JSON Schema.
Here is the sample test case
*** Settings ***
Library String
Library REST http://echo.jsontest.com ssl_verify=falseSet 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