justifier
v1.1.3
Published
Justifier is a developer friendly javascript framework to automate REST API endpoints.
Downloads
16
Readme
Justifier
Justifier is a developer friendly javascript framework to automate REST API endpoints.
It pulls together stable, mature existing libraries and builds a simple, light weight wrapper around it to make api automation easier
Features
- Allows making Http get, post requests
- Inbuild support for multipart post request
- Global parameters support
- Debugging support
- BDD style test design with before, after hooks support
Getting Started
Getting started guide will help you through setting up of simple justifier project to automate api end pioints
Installation
- Writing tests in Justifier require NodeJs environment. If node environment is not already set up then ollow these steps. Open the terminal and just type
brew install node
. Alternatively you can download package from official NodJs website and install. Check your installation by running below commands
node -v
npm -v
Project Set up
Create a sample folder, lets say
api_tests
, run commandnpm init
inside the folder. This will ask you bunch of questions either you can just keep entering or give proper names. After that it will create apackage.json
file for youRun below commands
npm install --save justifier
npm install --save mocha
npm install --save chai
- Now create a configuration file
config.js
under root folder and add the below peice of code and then modify the configuration as per your project needs.
module.exports = {
baseUrl : 'http://xxx.visenze.com',
queryParams : {'app_key' : 'xxx'},
debug : 'true',
// basic authentication
authentication : {
type : 'basic',
username : 'access_key',
password : 'secure_key'
}
};
NOTE
parameters defined in config.js file are appended to every request. Make sure to remove the params if not necessary
- Create a folder
specs
which holds the test cases your write - Create a data folder, which holds the test data
- Additionally, you can create a
validator
folder where you can hold common response validator logic - This is how your folder structure should look like now.
├── specs <- contains tests
├── data <- holds test data.
├── validator <- Custom Response validators
├── config.js <- global config file
├── package.json <- npm package manager, dependency management
Examples
making get request
var justifier = require('justifier');
var assert = require('chai').assert;
var get = justifier.get;
describe('Justifier GET Request', function () {
it('Should make a HTTP GET request', function () {
var params = {
im_name : 'XXXX'
};
return get('/search',params).then(function (response) {
assert.equal(response.status,'OK','response is ok')
})
})
});
making post request
var justifier = require('justifier');
var assert = require('chai').assert;
var post = justifier.post;
it('Should make a HTTP Post request', function () {
var params = {
im_url : 'XXXXXX'
};
return post('/uploadsearch',params).then(function (response) {
assert.equal(response.status,'OK','response is not OK');
})
});
data driven
var justifier = require('justifier');
var assert = require('chai').assert;
var get = justifier.get;
var given = justifier.given;
describe('Justifier data driven tests', function () {
given([{im_name:XXX},{im_name:XX}],function (input) {
it ('Should perform search by image name', function () {
return get('/search',input).then(function (response) {
assert.equal(response.status,'OK','response is ok')
})
})
})
});
chained requests
var justifier = require('justifier');
var assert = require('chai').assert;
var get = justifier.get;
var post = justifier.post;
describe('chained request', function () {
it('should support chained requests', function () {
var params = {
im_url: "XXXX"
};
return post('/uploadsearch',params).then(function (response) {
return get('/search',{im_name:response.result[0].im_name});
}).then(function (response) {
assert(response.result.length > 0, "empty result");
})
})
});