Newman: is there any way to display pass percentage in terminal/html report ?

Created on 20 Feb 2018  路  6Comments  路  Source: postmanlabs/newman

Postman for Windows
Version 5.3.2
Win 7 / x64
Newman 3.9.3

My request is to display the pass percentage in the console log - Much easier for management people.
Additionally adding percentage of passed Test cases . 79 passed out of 93 means = 84.94%..

Something like that.

question reporters

All 6 comments

While this isn't possible in the default reporter, setting percentage reports up using a custom reporter is quite straightforward, as can be seen below.

  1. You can start off by checking out our docs for custom Newman reporters here: https://www.getpostman.com/docs/postman/collection_runs/command_line_integration_with_newman#custom-reporters
  2. Next, you can build on top of the existing HTML reporter to add your own helper for percentage calculations. This can be done by including the following snippet in your custom reporter code:
handlebars.registerHelper('percent', function (passed, failed) {
  return (passed * 100 / (passed + failed)).toFixed(2);
});
  1. Now, you can use compute percent values anywhere in your report by including the following statement in the handlebars template:
{{percent cumulativeTests.passed cumulativeTests.failed}}
  1. Note that the javascript code for your custom reporter will have to reference the path to your modified handlebars template.

Feel free to revert if you have any questions 馃槃

I am getting the following error .

\helper-missing.js:19
throw new _exception2'default';
^
Error: Missing helper: "percent"

Here's my main code,




Newman Report



{{#with summary}}
Collection
{{collection.name}}

{{#if collection.description}}
Description
{{collection.description}} 
{{/if}}
{{/with}}
Time
{{timestamp}}

Exported with
Newman v{{version}}

 

 
Total

Failed

Passed Percentage

{{#with summary}}
{{#with stats}}
Iterations
{{iterations.total}}
{{iterations.failed}}

Requests
{{requests.total}}
{{requests.failed}}

Prerequest Scripts
{{prerequestScripts.total}}
{{prerequestScripts.failed}}

Test Scripts
{{testScripts.total}}
{{testScripts.failed}}

Assertions
{{assertions.total}}

{{assertions.failed}}

{{percent assertions.total assertions.failed}}

{{/with}}

    <div class="col-md-12">&nbsp;</div>
    <div class="col-md-6">Total run duration</div><div class="col-md-6">{{duration}}</div>
    <div class="col-md-6">Total data received</div><div class="col-md-6">{{responseTotal}} (approx)</div>
    <div class="col-md-6">Average response time</div><div class="col-md-6">{{responseAverage}}</div>

    <div class="col-md-12">&nbsp;</div>
    <div class="col-md-3"><strong>Total Failures</strong></div><div class="col-md-6"><strong>{{failures}}</strong></div>
  {{/with}}
</div>

<br/><h4>Requests</h4>

{{#each aggregations}}
    {{#if parent.name}}
    <div class="panel-group" id="collapse-folder-{{parent.id}}" 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}}" ><strong>{{parent.name}}</strong></a></h4>
        </div>
        <br/>
        <div id="folderData-{{parent.id}}" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="folderHead-{{parent.id}}">
        {{> aggregations}}
        </div>
    </div>
    {{else}}
    {{> aggregations}}
    {{/if}}
{{/each}}



{{#*inline "aggregations"}}
{{#each executions}}





Response body
{{response.body}}

                    {{#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><td>{{this.failed}}</td></tr>{{/each}}</tbody>
                            </table>
                        </div>
                    {{/if}}
                </div>
            </div>
        </div>
{{/each}}

{{/inline}}

Or If you share me your personal mail, i ll share my custom template.

Hi Kunagpal,

I am not much aware of handlebars, i have only one .hbs file. do i need to change in hbs file or need to write separate js file.

Thanks,
Jayanth

@jayanthktn The .hbs file will contain just the template content (of the form {{...}}). The actual logic to will have to go into a separate JS file. A starter template can be picked up from https://github.com/postmanlabs/newman/blob/develop/lib/reporters/html/index.js. Once you've added the handlebars.registerHelper snippet in this file, you can publish these files as a custom reporter, which can then be used within Newman.

Thanks kunagpal. It's worked.

Was this page helpful?
0 / 5 - 0 ratings