JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3
  • Score
    100M100P100Q65162F
  • License MIT

Test framework for automating rest api & typescript!

Package Exports

  • @krisinc/node-rest-assured

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@krisinc/node-rest-assured) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Node-Rest-Assured

Highlights

  • This API automation tool designed to support API automation like other tools RestAssured and Karate
  • It supports cucumberJS , es6 and typeScript
  • This tool helps integration testing with web , mobile and other applications
  • It helps API integration (example : to automate combination of promo, tax and price services) testing as well.
  • Best feature, Chai asserts are supported implicitly for json response validations
  • Easy to find json paths and node values like https://jsonpath.com/
  • Can send json request body as file and string
  • Include or exclude parameters from the request body for the negative testing
  • Dynamic parameters can be applied on json objects
  • Can send full json response as file for complete json schema validations
  • Https API
  • Promise API
  • Handled exceptions internally
  • It supports cucumber , mocha and other frameworks
  • Easy to use Request API's with basic knowledge of javascript and typescript
  • Going to add more utils for json validation to meet API's functionality
  • it supports fixtures similar to https://www.npmjs.com/package/fixtures
  • Actively maintained

Extra features: Chai asserts supported implicitly for json response validations Passing request body as json file , full json response validation as file for complete schema validations. It supports json path validations

|json path|value| |username| myname| using exact path : example: |json path|value| |data[*].username| myname|

Easy way of automation

making request of api end point Same method can be used for GET(Default), PUT,POST, PATCH, DELETE

const { prettyPrintJSON } = require("@krisinc/node-rest-assured");

(async () => {
        const inputbody = `{"username: "firstname", "lastname" : "lst" }`;
        const headerOptions: string = JSON.stringify({"Authorization": authToken});
        const response = makeHttpRequest(url, JSON.parse(headerOptions), "POST", inputbody);
        console.log(${jsonValidationUtils.prettyPrintJSON(response.body)});
        //=> '<!doctype html> ...'
})();

uploading file

const { prettyPrintJSON } = require("@krisinc/node-rest-assured");
import * as fs from "fs";

(async () => {
        const url: string = baseapiurl.toString() + urlParams;
             const headerOptions: string = JSON.stringify({"Authorization": authToken});
             const formDataMap: Map<string, any> = new Map<string, any> ();
             formDataMap.set(key, fs.createReadStream(value));
             response = await makeHttpRequestWithFormData(url, JSON.parse(headerOptions), "POST", formDataMap);
             const responseBody = JSON.parse(response.body);
             logger.info(() => `File Upload Response: ${jsonValidationUtils.prettyPrintJSON(responseBody)}`);
})();

one more method "makeHttpRequestWithProxy" to send request with proxy

/**
 * This method used to making http request
 * @param {string} url - form full url including path parameters if applicable
 * @param {object} headerOptions - pass header values
 * @param {string} HttpMethod - GET, POST , PUT, PATCH , DELETE etc , GET is default
 * @param {string} inputBody - json string
 * @param {boolean} formFlag - default false
 */

method
export async function makeHttpRequest(url: string, headerOptions?: object,
                                      HttpMethod?: string, inputBody?: string, formFlag?: boolean): Promise<object> {
                                      }
/**
 * This method used to make http request for FormData
 * @param {string} url - form full url including path parameters if applicable
 * @param {object} headerOptions - pass header values
 * @param {string} HttpMethod - GET, POST , PUT, PATCH , DELETE etc , GET is default
 * @param {Map<string, any>} formDataMap - json string
 * @returns {Promise<object>}
 */

export async function makeHttpRequestWithFormData(url: string, headerOptions?: object,
                                                  HttpMethod?: string,
                                                  formDataMap?: Map<string, any>): Promise<object> { }
/**
 * This method used to making http request
 * @param {string} url - form full url including path parameters if applicable
 * @param {string} _localHost - proxy server
 * @param {number} _port - port number
 * @param {object} headerOptions - pass header values
 * @param {string} HttpMethod - GET, POST , PUT, PATCH , DELETE etc , GET is default
 * @param {string} inputBody - json string
 * @param {boolean} formFlag - default false
 */

export async function makeHttpRequestWithProxy(url: string, _localHost: string, _port: number, _headerOptions?: object,
                                      HttpMethod?: string, inputBody?: string, formFlag?: boolean): Promise<object> { }

findNodeByName

(async) findNodeByName(jsonData, nodename) This method used to find the parent node by name , it returns json paths associated with json key. This helps to find json path for given node.

const { prettyPrintJSON, jsonValidationUtils } = require("@krisinc/node-rest-assured");

  const jsonfilepath = "./userresponse.json";
  const jsonfileobject = await jsonValidationUtils.readJsonToObject(jsonfilepath);
  const jsonpaths: string[] = await jsonValidationUtils.findNodeByName(jsonfileobject, "username");

Find Node Value

(async) findNodeValue(jsonData, nodename) This method used to find the parent node value by node name

 response = await makeHttpRequest(url, JSON.parse(headerOptions), "POST", resultString);
    world.responseBody = JSON.parse(response.body);
    logger.info(() => `Post Response is: ${jsonValidationUtils.prettyPrintJSON(world.responseBody)}`);
    const userid = await jsonValidationUtils.findNodeValue(world.responseBody, "id"); // it returns string array
//sometimes will be having multiple id's(with same node name) for user , security roles and external id's
// Better to give exact path, users[*].id or if index is fixed users[0].id

Fixtures

/*
Ex: users.json
{
    "my_own_user": {
      "name": "Charles",
      "type": "M"
    },
    "female": {
      "name": "Susana",
      "type": "F"
    }
  } */
const userdata = await jsonValidationUtils.readJson("./users.json");
const username: string[] = await jsonValidationUtils.findNodeValue(userdata,
    "my_own_user.name");
logger.info(username[0]);

Publishing changes

https://www.npmjs.com/package/cucumberjs-rest-assured

More documentation will be added Please refer github links for code snippets , these methods can be used for mocha and other frameworks as well contact letautomate@gmail.com , let.automate@gmail.com

License

Please see LICENSE.md.