Frisby as a REST API Automation Framework

For writing your REST API automation test cases there are many tools available like Runscope, Fit Selenium, PyRestTest, REST-assured and many such more. Before selecting the right tool for REST automation some important aspects to consider are:

The framework components need to be loosely coupled to each other and there should be a generic way to invoke test cases and retrieving results. The framework design should be such that, any changes in REST API should least impact the automation scripts.

Data structures
The framework should support all the data formats supported by REST APIs like XML, JSON, Multi-Part data, plain text etc.

Most of your REST API testing will revolve around validations. A good framework should provide out of the box support for such validations/comparisons. Some validation examples: verifying API response code, response headers, verifying the response body.

A testing framework is of no use if it lacks the ability to generate reports. Reports give you a clear visibility of your time and efforts invested in automation. There should be reporting mechanism implemented that should define the output in user readable format. This kind of report will help us to design the failures/success rate in REST API automation.

After considering all the above points, I decided to stick with Frisby. Frisby is a REST API testing framework built on node.js and Jasmine that makes testing API endpoints easy, fast, and fun. Its as simple as tossing a frisby.

Jasmine is a behavior-driven development framework for testing JavaScript code. It does not depend on any other JavaScript frameworks and most importantly, it does not require a DOM. It has a clean, obvious syntax so that you can easily automate your tests. 

Sample GET request in Frisby:

var frisby = require('frisby');
var URL = '';

frisby.globalSetup({ // globalSetup is for ALL requests
 request: {
   'Accept': 'application/json', 
   'Content-Type': 'application/json',
   'Authorization': 'Basic YWRtaW46YWRtaW4='
timeout: (60 * 1000)

    .afterJSON(function(json) {
    .expectHeaderContains('content-type', 'application/json')

Sample POST request in Frisby:

var frisby = require('frisby');
var URL = '';

frisby.globalSetup({ // globalSetup is for ALL requests
 request: {
   'Accept': 'application/json', 
   'Content-Type': 'application/json',
   'Authorization': 'Basic YWRtaW46YWRtaW4='
var postData = {

    .post(URL, postData, {json: true})
    .afterJSON(function(json) {
Frisby is exceptionally good at checking the values in a JSON response against the specified values (see the "expect" statements in above examples). Frisby also allows you to perform type checking, useful for making sure you’re getting the types that really should be there, like a number rather than a string representation of a number.

A list of expectations that can be chained:


Since Frisby is JavaScript, you can write some additional JS functions to make your automation more strict and powerful. Frisby can be used with a "Continuous Integration" system or run with each build to perform some of your Build Verification Tests (BVT)
Link to documentation: Frisby.js API Documentation

Note: Frisby is built on top of the Jasmine BDD (Behaviour-Driven Development)  framework, and uses the jasmine-node test runner to run spec tests.

Some of the build-in validation statements:

var a = true;

var b = false;

//Works for simple literals and variables
var a = 12;

//The 'toMatch' matcher is for regular expressions or strings
var message = "foo bar baz";

//The 'toBeDefined' matcher compares against `undefined`
var a = { foo: "foo" };

//The 'toBeLessThan' matcher is for mathematical comparisons
 var a = 12.5,
     b = 2.5;


For a full list of supported validation statements see the Jasmine Api Documentation.

Next Reading:  How to Install Frisby on Linux

1 comment: Leave Your Comments

  1. How do you handle database access if you either want to inject test data and/or pull out db values for response verifications?