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.
Install insomnia-plugin-response-validator
plugin from Preferences > Plugins.
Add a header INSOMNIA-RESPONSE-VALIDATOR
with a json comparising of jsonpath and expected values to assert individual response
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 __
.
"$.data[*].id" : "__.hasItem(7)"
"$.data[*].id" : "__.hasItem(__.greaterThan(8))"
"$.data[*].id" : "__.hasItem(__.lessThan(3))"
"$.data[*].employee_name" : "__.hasSize(5)"
"$.data[*].employee_name" : "__.hasSize(__.lessThan(3))"
"$.data[*].employee_name" : "__.hasSize(__.greaterThan(8))"
"$.data[*].employee_name" : "__.isEmpty()"
"$.data[*].id" : "__.contains(5, 7, 10)"
"$.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
INSOMNIA-RESPONSE-VALIDATOR:{"INSA-ResponseCode":"200", "$.status" : "success", "$.data[10].employee_name" : "Jena Gaines"}
INSOMNIA-RESPONSE-VALIDATOR: {"INSA-ResponseCode":"200", "$.status" : "__.hasItem('success')", "$.data[10].employee_name" : "__.hasItem('Jena Gaines')"}
Test Execution result will be appended at the top of the response as follows
View-->Toggle DevTools-->Console
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