insomnia-plugin-response-validator

3.0.0 • Public • Published

insomnia-plugin-response-validator

This is a plugin for Insomnia API client that can validate the response based upon expected result for collection requests. We can also run all requests in a given folder in parallel using this and share with you execution results.

Installation

Install insomnia-plugin-response-validator plugin from Preferences > Plugins.

Usage

Add a header INSOMNIA-RESPONSE-VALIDATOR with a json comparising of jsonpath and expected values to assert individual response

Setup the Header

image

Validator

Key: JSONPATH Value: Expected Value

Note: To validate the response code of the request add "INSA-ResponseCode":"200".

The plugin is integrated with Hamjest, provides significant matcher functionality. Since JSONPATH outputs arrays, we must use array-related matchers. Some of the examples are as follows.

All hamjest to be available as __.

hasItems

"$.data[*].id" : "__.hasItem(7)"
"$.data[*].id" : "__.hasItem(__.greaterThan(8))"
"$.data[*].id" : "__.hasItem(__.lessThan(3))"

hasSize()

"$.data[*].employee_name" : "__.hasSize(5)"
"$.data[*].employee_name" : "__.hasSize(__.lessThan(3))"
"$.data[*].employee_name" : "__.hasSize(__.greaterThan(8))"

isEmpty()

"$.data[*].employee_name" : "__.isEmpty()"

contains

"$.data[*].id" : "__.contains(5, 7, 10)"

hasProperty

"$.data[0]":"__.hasItems(__.hasProperties({'id': 7,'email': 'michael.lawson@reqres.in','first_name': 'Michael','last_name': 'Lawson','avatar':'https://reqres.in/img/faces/7-image.jpg'}))"

Refer https://github.com/rluba/hamjest/wiki/Matcher-documentation for more details on matchers

INSOMNIA-RESPONSE-VALIDATOR: { "INSA-ResponseCode":"200", "$.page":"__.hasItem(2)", "$.total_pages":"__.hasItems(__.lessThan(4))" "$.status" :"__.hasItem('success')", "$.data[0].first_name":"__.hasItems('Michael')", "$.data[10].avatar" :"__.hasItems('https://reqres.in/img/faces/9-image.jpg')" }

Note: use single quote as shown above for string

Old Header Format (No longer supported)

INSOMNIA-RESPONSE-VALIDATOR:{"INSA-ResponseCode":"200", "$.status" : "success", "$.data[10].employee_name" : "Jena Gaines"}

New Header

INSOMNIA-RESPONSE-VALIDATOR: {"INSA-ResponseCode":"200", "$.status" : "__.hasItem('success')", "$.data[10].employee_name" : "__.hasItem('Jena Gaines')"}

Test Execution Result

Test Execution result will be appended at the top of the response as follows image

More info for Debug

View-->Toggle DevTools-->Console

consoleResult

Run All Requests: Parallel or Sequential

Right click on the target folder on the context menu --> click Run All Requests-Parallel, it will trigger all requests in parallel.

Run All Requests

Right click on the target folder on the context menu --> click Run All Requests-Sequential, it will trigger requests present in the folder sequentially. It's beneficial when requests have interconnected dependencies.

Once all the requests processed, it will open up the execution dialog window which will give the execution result.

image

During execution, it will evalutes the assert that setup as header against the response, based upon the assert, it will pass or fail the result. In the absence of an assert setup, a status code will be returned.

Before running all request, setup the Request timeout to desired value otherwise requets will continue run, till timeout.

Insomania-->Settings...-->Insomania Preferences

image

You need to have NodeJS installed in your system to use this plugin

Package Sidebar

Install

npm i insomnia-plugin-response-validator

Weekly Downloads

218

Version

3.0.0

License

MIT

Unpacked Size

28.9 kB

Total Files

7

Last publish

Collaborators

  • gsumit1