Improve Newman Documention for Custom Reports

as this post is mostly viewed and counting
Posting here, So that it may reach to more who needs…

Have to edit template-default.hbs and index.js you will need to access the folder node_modules/newman/lib/reporters/html

In template-default.hbs

inside block {{#*inline “aggregations”}} {{#each executions}} and after the {{#with request}} block, add a ‘div’ with ‘{{response.body}}’ this will make handlebars iterate over each executions in json result and print the response.body data inside a div.

Using {{response.body}} outside the {{#with request}} helps to get a response in the report.

when collection is run with iteration, HTML report only shows results for first Iteration

This problem occurs because in template it creates a div.panel-group for each execution, and the id attribute of this div is ‘collapse-request-{{item.id}}’. This way, for each iteration it will create n new div’s with same id, because item.id is the same in each iteration… this causes javascript to not work properly. When you click in a div it navigates throw DOM to find the first panel that must expand/collapse with the target id, as div’s has same id it always will use only first div. (https://getbootstrap.com/docs/3.3/javascript/#collapse)

To fix this, we should increment the id attribute with index of iteration… handlebars has a builtin helper that brings the index to us.

On template in block:

{{#*inline “aggregations”}}
{{#each executions}}

you must find each ‘{{item.id}}’ and replace then with ‘{{item.id}}-{{@index}}’, this way we guarantee that each div has a unique id, and javascript could work properly.

To that, you need to modify index.js file…

you will need to access the folder node_modules/newman/lib/reporters/html in this folder there’s an index.js file, you need to edit this file to make it works properly on iterations.

The problem occurs because it considers only ‘currentExecution.id’ when aggregating data, we need it to consider currentExecution.id and currentExecution.response.id… cause our execution.id is the same but response is not. In order to do this you will need to replace multiple lines in file as follows:

line ~65:
executionId = currentExecution.id;
replace with:
executionId = currentExecution.id + currentExecution.response.id;

line ~92:
items[reducedExecution.item.id] = reducedExecution;
replace with:
items[reducedExecution.item.id + reducedExecution.response.id] = reducedExecution;

line ~126 and ~127:
current = _.merge(items[execution.item.id], {
assertions: _.values(assertions[execution.item.id]),
replace with:
current = _.merge(items[execution.item.id + execution.response.id], {
assertions: _.values(assertions[execution.item.id + execution.response.id]),

line ~132:
cumulativeTests: netTestCounts[execution.item.id]
replace with:
cumulativeTests: netTestCounts[execution.item.id + execution.response.id]

this will make it works with iterations, you can try this modifications in your own risk, in any case just restore the original index.js file.

Credits: @rmlira

Original Post:
How to capture response body data in Newman result report

Still some more improvisations are needed, any help is much appreciated :grinning: