GithubHelp home page GithubHelp logo

shashikumarraja / api_automation_boilerplate-javascript Goto Github PK

View Code? Open in Web Editor NEW
18.0 3.0 11.0 15 KB

JavaScript 100.00%
javascript mocha chai api-testing-framework api-testing boilerplate test-automation

api_automation_boilerplate-javascript's Introduction

API Automation


Project to create automation tests of APIs with Mocha bringing BDD to JavaScript.

Requirements

  • Node version 7 or higher

Although this project works fine with NPM we recommend to use Yarn (>= 0.20.0) instead, due to its speed & solid dependency locking mechanism. To keep things simple we use yarn in this guide, but feel free to replace this with NPM if that is what you are using.

Quick start

Choose one of the following options:

  1. Download the latest stable release or clone the git repo โ€” git clone repoName

  2. Then:

  • Copy the files to your project into a directory like /api_automation_boilerplate-javascript
  1. Install the dependencies (yarn install) or (npm install)

Now you are ready to write your own tests.

How to write a test

Tests are written in Mocha BDD syntax

myFirstTest.js

describe('My First test', () => {
    let app = 'My first test';
    it('should pass', () => {
      app.should.equal('My first test')
    });
});

How to run the test

Traverse to the project directory

$ cd api_automation_boilerplate-javascript

On one tab run faker api(Using the json-server module we are creating fake api for testing purpose) :

$ npm run fakeApi

In another tab execute the test run using :

$ npm test

Configurations

To configure your tests, checkout the [setup.js] file in your test directory.

Environment-specific configurations

You can setup multiple configs for specific environments. Let's say you want to have a different baseUrl for your local and pre-deploy tests. Use the setup to set all general configs (in mochaOpts) that don't change. They act as default values. For each different environment you can create a new setup with the following name scheme:

setup.<ENVIRONMENT>.js

and then accordingly require it in your mocha.opts file using

--require ./test/setup.js

Running single test

Sometimes its useful to only execute a single test file, to do so use the following command:

$ npm test --grep nameOfSuite (nameOfSuite is the name of describe or it block)

Skip test

If you have failing or unimplemented tests you can mark them as "skip" so they will get skipped.

describe.skip();
it.skip();

Assertions

To assert values this project comes with a Chai integration.

Logger

Winston is used as logger in the project. Use the below command to get logs on console while running tests-

logLevel='debug' npm test

Supported log levels are-

{ error: 0, warn: 1, info: 2, verbose: 3, debug: 4, silly: 5 }

To use logger, use any of the below format with respective logLevels-

// Default logger
winston.log('info', "127.0.0.1 - there's no place like home");
winston.info("127.0.0.1 - there's no place like home");

To use winston's inbuilt logger module(project uses winston directly), make the configuration as -

var winston = require('winston');
var logger = new (winston.Logger)({
  levels: {
    trace: 9,
    input: 8,
    verbose: 7,
    prompt: 6,
    debug: 5,
    info: 4,
    data: 3,
    help: 2,
    warn: 1,
    error: 0
  },
  colors: {
    trace: 'magenta',
    input: 'grey',
    verbose: 'cyan',
    prompt: 'grey',
    debug: 'blue',
    info: 'green',
    data: 'grey',
    help: 'cyan',
    warn: 'yellow',
    error: 'red'
  }
});

logger.add(winston.transports.Console, {
  level: 'trace',
  prettyPrint: true,
  colorize: true,
  silent: false,
  timestamp: false
});

logger.add(winston.transports.File, {
  prettyPrint: false,
  level: 'info',
  silent: false,
  colorize: true,
  timestamp: true,
  filename: './nKindler.log',
  maxsize: 40000,
  maxFiles: 10,
  json: false
});

Reporter

The project uses two reporters-

  1. mocha-allure-reporter - It generates report and runs a server to display all the reports. To see the allure report-
npm run report
  1. spec reporter- It is the default mocha reporter to display report on the terminal.

Use of more than one reporter has been made possible by using mocha-multi

Api Documentation

The project uses apiDoc to document the Apis. To generate and see the api documentation use-

npm run generateDocument

api_automation_boilerplate-javascript's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.