insomnia-plugin-response-validator
v3.0.0
Published
A plugin to perform validation on the response & run all requests of folder
Downloads
1,101
Maintainers
Readme
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
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': '[email protected]','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
More info for Debug
View-->Toggle DevTools-->Console
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.
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.
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