Newman Report for beginner: how to access the attributes of a run collection: URL, Methode, Error Message

Hi everybody,
i’m have working with postman for a couple of months but still completely new in the filed of newman report. I’m trying to modify the .hbs template to create my own newman report. The report should be in the following format:

image

here is the content of my custom_template.hbs:

<html>
	<head>
		<title>My awesome Template</title>
	<style>
	table, th, td {
		border: 1px solid black;
		border-collapse: collapse;
	}
	</style>
	</head>
	<body>
		<table style="width:50%">
			<tr>
				<th>Substring of url</th>
				<th>Test Name</th>
				<th>Error Message</th>
			</tr>
			{{#each summary.failures}}
			<tr>
				<th>{{request.url}}</th>
				<th>{{error.test}}</th>
				<th>{{error.name}}</th>
			</tr>
			{{/each}}
		</table>
	</body>
</html>

But what i got in the report is just:

  • The first column is just empty. What am I doing wrong ?

  • How can I extract just a substring of the request url in handelbars ?

  • where can i find out the structure of the json data , which will be used to create the report ? I just one to know which object and its attributes i can use for the report: for example: request, error, and failures object

Best regards

Hey @leanh1188,

Welcome to the community! :wave:

The request URL is part of a different array so that’s why it wouldn’t be populated in the table.

It would be under the aggregations array, you would need to loop through that array and then through the executions array to expose the data you want to access.

I’ve changed your template code slightly to output something that might help.

<html>
	<head>
		<title>My awesome Template</title>
	<style>
	table, th, td {
		border: 1px solid black;
		border-collapse: collapse;
	}
	</style>
	</head>
	<body>
        {{#each aggregations}}
        {{#each executions}}
        <h3>Substring of url: {{request.url}}</h3>
        <table style="width:50%">
            <tr>
                <th>Test Name</th>
				<th>Error Message</th>
			</tr>
            {{#each assertions}}
			<tr>
                <td>{{testFailure.test}}</td>
				<td>{{testFailure.message}}</th>
            </tr>
            {{/each}}
		</table>
        {{/each}}
        {{/each}}
	</body>
</html>  

This will not be exactly as you need but it will be close and you should be able to change it to what you need.

I ran this template through the htmlextra reporter. :smiley:

Hi @dannydainton,
wow, thanks you very much for your edit. It helped me alot. I have another questions and i think you can answer it quickly.

  • Let say the URL is: https://postman-echo.com/post. How can get only just a part of it, for example only the “/post” part ?
  • in your template version you used <<#each aggreations>>, <<#each executions>>, {{testFailure}} and so on. How do you know this object ? How can I find the structure of the result data, just to know which varialbes, object are available for me to use ?

You’re welcome! :smiley:

This would get you the path:

<h3>Substring of url: /{{request.url.path}}</h3> 

Knowing what’s in the object has come from creating the templates for the reporter and a lot of trial and error :smiley:

I added a basic example of the summary object, to a blog post I wrote, this will hopefully help you to see what’s in there:

I coudn’t find the aggreations array and {{testFailure}} in your .json File ?? ^^

While using your template i got this:

.
Do you know why i got the multi-line in the result ?

I don’t really know anything about your Collection or the template you used to created the HTML file so i’m not sure why it would do that :slight_smile:

Which reporter are you using with your template?

Is there something in the htmlextra reporter output that missing or do you just want to output the data is a certain way? It can always be added in there :slight_smile:

Are you running this from the command line or part of a node script?

The file wasn’t the exact output from the run, it was just a basic file structure so you could see where request.url.path would be coming from. The HTML and htmlextra reporters convert the data coming from Newman and structure it in a certain way, that’s where aggregations come from.

This is the default template used for the htmlextra reporter - It contains a bunch of things that are not really going to be what you want but all the different ways that I have converted the data from Newman, is in here:

Hi,
i used exactly the template from your post without any modification. I’m using the htmlextra reporter, which was run from the command line :slight_smile: