How to capture response body data in Newman result report

I add some code to javascript as follows:

	<script type="text/javascript">
    "use strict";

window.onload = function () {

  // hides all blocks of response
  var allItems = document.querySelectorAll('[class*=iteration-]');
  allItems.forEach(function(elem){
    elem.style.display = 'none';
  });

  {{#with summary}} {{#with stats}}
  let totalIterations = {{iterations.total}};
  {{/with}} {{/with}}

  let menu = document.querySelector('#execution-menu .nav');

  for(var i = 0; i < totalIterations; i++)
  {
    let li = document.createElement('li');
    li.appendChild(document.createTextNode('Iteration - ' + i));
    li.setAttribute('id', 'iteration-' + i);
    li.classList.add("custom-tab");

    li.addEventListener('click', function() {

      let allItems = document.querySelectorAll('[class*=iteration-]');
      allItems.forEach(function(elem) {
        elem.style.display = 'none';
      })

      let allMenus = document.querySelectorAll('[id*=iteration-');
      allMenus.forEach(function(elem){
        elem.style.borderBottom = 'none';
      })

      this.style.borderBottom = 'solid 1px #032a33';

      let items = document.querySelectorAll("." + this.id);
      items.forEach(function(elem) {
        elem.style.display = elem.style.display == 'block' ? 'none' : 'block';
      })
    });

    menu.appendChild(li);
  }

    //shows first tab data
  document.getElementById('iteration-0').click();
}</script>

and add this css code:

.custom-tab {
            padding: 10px 15px;
            margin-right: 3px;
            border: solid 1px #fff;
            border-bottom: none;
            cursor:pointer;
        }
        .custom-tab .active {
            border-bottom:solid 1px #032a33;
        }
        #execution-data {
            padding: 10px;
            border: solid 1px #fff;
            border-top: none;
        }

Now it looks like this:

I upload the files to youā€¦ can you test again please?

@rmlira ā€¦Hi I have been trying to generate custom report for my project. I am using same hbs file as gopal above. I am getting all layout as is except the color grading (styles). What I am missing here?

hi Renan,

Could you please upload the latest .hbs file and index.js file or send to my email. It would be appreciated if you could help me implement the your custom reports. It looks great and precise.

Hi,
your reports looks perfect could you please help me with customise template your index file

Hi @rmlira
your reports looks perfect.
could you please help me with customise template . i want if {{cumulativeTests.failed}} >0 then parent panel-heading color should be in red if {{cumulativeTests.failed}} = 0 panel-heading color should be green.
please see attached image.

my Costomized template.hbs code below.


Requests

{{#each aggregations}}
    {{#if parent.name}}
    <div class="panel-heading tego-bg-green" id="collapse-folder-{{parent.id}}-{{parent.iteration}}" role="tablist" aria-multiselectable="true">
       
		<div role="tab" id="folderHead-{{parent.id}}">
            <h4 style="font-size: 18px;" class="panel-title"><a data-toggle="collapse" data-parent="#accordion" href="#folderData-{{parent.id}}-{{parent.iteration}}" aria-controls="collapseOne"><strong>{{parent.name}}</strong></a></h4>
        </div>
        <br/>
        <div id="folderData-{{parent.id}}-{{parent.iteration}}" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="folderHead-{{parent.id}}-{{parent.iteration}}">
        {{> aggregations}}
        </div>
    </div>
    {{else}}
    {{> aggregations}}
    {{/if}}
{{/each}}

{{#*inline ā€œaggregationsā€}}
{{#each executions}}



            <div id="requestData-{{item.id}}-{{cursor.iteration}}" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="requestHead-{{item.id}}-{{cursor.iteration}}">
                <div class="panel-body">
                    {{#with request}}
                        {{#if description.content}}
                            <div class="col-md-4">Description</div><div class="col-md-8" style="white-space: pre-wrap;">{{description.content}}</div>
                            <div class="col-md-12">&nbsp;</div>
                        {{/if}}

                        <div class="col-md-4">Method</div><div class="col-md-8">{{method}}</div>
                        <div class="col-md-4">URL</div><div class="col-md-8"><a href="{{url}}" target="_blank">{{url}}</a></div>
                    {{/with}}						
					<div class="col-md-4">Response Body</div><div class="col-md-8">{{response.body}} </div>
					<div {word-wrap: break-word;}</div>
                    <div class="col-md-12">&nbsp;</div>
                    <div class="col-md-4">Mean time per request</div><div class="col-md-8">{{mean.time}}</div><br/>
                    <div class="col-md-4">Mean size per request</div><div class="col-md-8">{{mean.size}}</div><br/>

                    <div class="col-md-12">&nbsp;</div>
                    <br/><div class="col-md-4">Total passed tests</div><div class="col-md-8">{{cumulativeTests.passed}}</div>
                    <div class="col-md-4">Total failed tests</div><div class="col-md-8">{{cumulativeTests.failed}}</div><br/>

                    <div class="col-md-12">&nbsp;</div>
                    <br/><div class="col-md-4">Status code</div><div class="col-md-8">{{response.code}}</div><br/>

                    {{#if assertions.length}}
                        <div class="col-md-12">&nbsp;</div>
                        <div class="col-md-4">Tests</div>

                        <div class="col-md-8">
                            <table class="table table-responsive table-condensed">
                                <thead><tr><th>Name</th><th>Pass count</th><th>Fail count</th></tr></thead>									
                                <tbody>{{#each assertions}}<tr><td>{{this.name}}</td><td>{{this.passed}} <td>{{this.failed}}</td> </tr>{{/each}}</tbody>
                            </table>
                        </div>
                    {{/if}}
					
                </div>
            </div>
        </div>
    </div>
{{/each}}

{{/inline}}

please help me.
Thanks,
Vipin

@rmlira: i have tried with these changes but each iteration has same result.
Expectation:
iteration tab1
test1
test2
iteration tab2
test1
test2

Actual:
iteration tab1
test1
test2
test1
test2
iteration tab2
test1
test2
test1
test2

i have upadated index.js, hbs file. Could you please help me?

Hi there
I have tested this one with your latest index.js and jsonreportPrettyWithTabChanges.hbs which are available in gDrive but its throwing an error like below.
Could you please take a look?

cmd line: >newman run C:\Users\kkaku\Documents\Fulfillment\Framework\z_SetNextRequest.postman_collection.json --folder ā€œfolder1ā€ -r html,cli,junit -g C:\Users\kkaku\Documents\Fulfillment\Framework\MyWorkspace.postman_globals -e C:\Users\kkaku\Documents\Fulfillment\Framework\Cert.postman_environment.json --reporter-html-template C:\Users\kkaku\Documents\Fulfillment\Framework\jsonreportPrettyWithTabChanges.hbs

Error:
C:\Users\kkaku\node_modules\handlebars\dist\cjs\handlebars\compiler\parser.js:268
throw new Error(str);
^

Error: Parse error on line 506:
};
----------------------^
Expecting ā€˜OPEN_INVERSE_CHAINā€™, ā€˜INVERSEā€™, ā€˜OPEN_ENDBLOCKā€™, got ā€˜EOFā€™
at Parser.parseError (C:\Users\kkaku\node_modules\handlebars\dist\cjs\handlebars\compiler\parser.js:268:19)
at Parser.parse (C:\Users\kkaku\node_modules\handlebars\dist\cjs\handlebars\compiler\parser.js:337:30)
at HandlebarsEnvironment.parse (C:\Users\kkaku\node_modules\handlebars\dist\cjs\handlebars\compiler\base.js:46:43)
at compileInput (C:\Users\kkaku\node_modules\handlebars\dist\cjs\handlebars\compiler\compiler.js:515:19)
at ret (C:\Users\kkaku\node_modules\handlebars\dist\cjs\handlebars\compiler\compiler.js:524:18)
at EventEmitter. (C:\Users\kkaku\node_modules\newman\lib\reporters\html\index.js:157:22)
at EventEmitter.emit (C:\Users\kkaku\node_modules\eventemitter3\index.js:203:33)
at done (C:\Users\kkaku\node_modules\newman\lib\run\index.js:260:29)
at C:\Users\kkaku\node_modules\postman-runtime\lib\backpack\index.js:56:34
at PostmanCollectionRun._process (C:\Users\kkaku\node_modules\postman-runtime\lib\runner\run.js:161:13)
at PostmanCollectionRun. (C:\Users\kkaku\node_modules\postman-runtime\lib\runner\run.js:166:76)
at ontimeout (timers.js:482:11)
at tryOnTimeout (timers.js:317:5)
at Timer.listOnTimeout (timers.js:277:5)

Hi Gopi,

I was trying to use your gDrive files and modified ones by @rmlira to customize the newman report, but it was throwing some errors on cmd prompt(i mentioned error log to @rmilra in this post, i dont know what was causing issue. Could you or @rmilra please help on this.

Thank you!

Hi I need your help to generate report in html

Hi,

I am using newman 4.2.2. version and have tried this modification of template to include every iteration request in different ā€œcollapse-request-item-indexā€. As far as I have understood the indications from this thread the different requests should appear in the report when modifying the template. In my case, I can see the response body only. I donā€™t see different request for every iteration. It remains on the last call this time.

I havenā€™t change the index.html. My installation path to html-reporter is: C:\Users[user]\AppData\Roaming\npm\node_modules\newman-reporter-html\lib

Part of the template that I have modified:
{{#*inline ā€œaggregationsā€}}
{{#each executions}}



            <div id="requestData-{{item.id}}-{{@index}}" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="requestHead-{{item.id}}-{{@index}}">
                <div class="panel-body">
                    {{#with request}}
                        {{#if description.content}}
                            <div class="col-md-4">Description</div><div class="col-md-8" style="white-space: pre-wrap;">{{description.content}}</div>
                            <div class="col-md-12">&nbsp;</div>
                        {{/if}}

                        <div class="col-md-4">Method</div><div class="col-md-8">{{method}}</div>
                        <div class="col-md-4">URL</div><div class="col-md-8"><a href="{{url}}" target="_blank">{{url}}</a></div>
                    {{/with}}
                    <div class="col-md-4">Response Body</div><div class="col-md-8">{{response.body}}</div>
                    <div class="col-md-12">&nbsp;</div>

Can you please help me understand if I am doing anything wrong?

I have done these same steps and I donā€™t see each iteration request. Just the last one.
@rmlira can you please tell me if there is something else that I need to add or change?

Hi Rmlira,

Please share files for custom reportsā€¦

Hi @gopikrishna4595 please send the custom reports of Iterations

Iā€™ve created this reporter that will show non aggregated results, skipped tests and so more things if thatā€™s of interest to people.

No need to manually change youā€™re files etc.

If anyone needs anything else adding to the reporter, I can look at doing this for peopleā€¦As long as itā€™s possible. :grin:

Hello @danny-dainton

Thank a lot for your supportā€¦ I need to capture request body of each request and each Iterationā€¦please help on thisā€¦

Thank you again buddyā€¦:slight_smile:

Hey,

Thanks for the support. The information is there in the overall summary object but I just didnā€™t actively expose it on the report templates.

You can add this to the template yourself for now:

{{#with request}} 
{{#if body.raw}}
 <pre>{{body.raw}}</pre>
 {{/if}} 
{{/with}}

It would be something like that, placed in the relevant area of the template. That will show the request body, if the request has one.

I will update my template later today to add this section in but if you want to experiment now and not wait, you could manually update it from your side.

Itā€™s difficult to create a generic template that covers everyones individual usecase with their own context.

I would absolutely recommend trying to create your own personal template to use with the reporter and then you have full control over which pieces of data you either expose or donā€™t expose.

Hello @danny-dainton

Thank You so much ā€¦ once done report template ā€¦ please share it

Create a temporary template yourself, itā€™s so much quicker. :grin:

Waiting for me to add something is just a waste of your time if you require something now.

Iā€™ve added the request body, if the request has one, to the default template and the dashboard style template.

These changes can be found on version 1.2.3 of the NPM package or you could also just grab the file from Github.

Is this what you required on the report or something else?

1 Like

Hi @danny-dainton,

Thank you Bro,

Please share files or send me link of shared drive.