How to capture response body data in Newman result report


#21

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?


#22

@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?


#23

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.


#24

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


#25

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


#26

@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?


#27

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)


#28

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!


#29

Hi I need your help to generate report in html


#30

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?


#31

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?


#32

Hi Rmlira,

Please share files for custom reports…


#33

Hi @gopikrishna4595 please send the custom reports of Iterations


#34

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:


#35

Hello @dannydainton

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:


#36

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.


#37

Hello @dannydainton

Thank You so much … once done report template … please share it


#38

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.


#39

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?


#40

Hi @dannydainton,

Thank you Bro,

Please share files or send me link of shared drive.