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 @danny-dainton,
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:

help me !!!

  1. my postman api response structure is like this. how to print out the value of description?
  2. How to print input from csv file or url?

{
“predictions”: [
{
“description”: “Thời trang D&T 68, 176 Quan Nhân, Nhân Chính, Thanh Xuân, Hà Nội”,
“matched_substrings”: ,
“place_id”: “i3BEJCIfaVroqfk5fR9MbKMtxWt_cJ/TFsBLrH5NsEdMtVq60lhw_vuPH0/HsLJCC_JzCMNUEZBWx1JYjLdv_Q==.ZXhwYW5kMA==”,
“reference”: “5ftQptvmxrQySeGMWuN/pwfV7eolt_yJ3LcpFqtXP9hgb4ulXWKOnxoDwbUH8DCDs8nk4/I1D4ZRzpqo1bayig==.ZXhwYW5kMA==”,
“structured_formatting”: {
“main_text”: “Thời trang D&T 68”,
“secondary_text”: “176 Quan Nhân, Nhân Chính, Thanh Xuân, Hà Nội”
},
“terms”: ,
“has_children”: false,
“display_type”: “expand0”,
“score”: 318.9346,
“plus_code”: {
“compound_code”: “+3P5K Nhân Chính, Thanh Xuân, Hà Nội”,
“global_code”: “LO65+3P5K”
}
},
{
“description”: “Thời trang D&V, 80 Thành Công, Thành Công, Ba Đình, Hà Nội”,
“matched_substrings”: ,
“place_id”: “i3BEJCIfaVroqfk5fR9MbFbr/Bmwn_zYMsDy3/Jlcl9KiRKDdNvs4/ObOteKPFAEqJVq7GJGlIRMAusT3GtMgA==.ZXhwYW5kMA==”,
“reference”: “5ftQptvmxrQySeGMWuN/pxFK5lH2WwDJ5J_n03_oRlR6XpvZJaNCNcClZq/w7DGIErnIZOSYjYGG2PkxWyhD2Q==.ZXhwYW5kMA==”,
“structured_formatting”: {
“main_text”: “Thời trang D&V”,
“secondary_text”: “80 Thành Công, Thành Công, Ba Đình, Hà Nội”
},
“terms”: ,
“has_children”: false,
“display_type”: “expand0”,
“score”: 318.42996,
“plus_code”: {
“compound_code”: “+HCIG Thành Công, Ba Đình, Hà Nội”,
“global_code”: “LNEZ+HCIG”
}
},
{
“description”: “Thời trang D&T, 652B H5 Tân Mai, Tân Mai, Hoàng Mai, Hà Nội”,
“matched_substrings”: ,
“place_id”: “_I8CGA7AtaFeeeh3lG_ild_GC8xTMZ/2KpYA/od/0sb9G_gl9XC6UpTwgtysvt5E3A7fNsRe8xY4HtB6nc7rfw==.ZXhwYW5kMA==”,
“reference”: “d2sQUBdeDaEhXH0J6qDkY3nN5x5hc6Ot73o2f1CKm5ZdHtBFbbGjg//n2F4W0rU7ZHFz17VwCyoTdy7NhIq/XA==.ZXhwYW5kMA==”,
“structured_formatting”: {
“main_text”: “Thời trang D&T”,
“secondary_text”: “652B H5 Tân Mai, Tân Mai, Hoàng Mai, Hà Nội”
},
“terms”: ,
“has_children”: false,
“display_type”: “expand0”,
“score”: 310.94638,
“plus_code”: {
“compound_code”: “+H5AH Tân Mai, Hoàng Mai, Hà Nội”,
“global_code”: “LNXZ+H5AH”
}
},
{
“description”: “Cửa hàng thời trang D&K, 55 Phú Đô, Phú Đô, Nam Từ Liêm, Hà Nội”,
“matched_substrings”: ,
“place_id”: “wO32cyA6MoUEiIAqPPP6Q4Ylnx03i7uoBh2lHtTznNAm_pdOAW5hVWodCl24HUZJP4VrE_wTxTIu1UZ_wZGJTA==.ZXhwYW5kMA==”,
“reference”: “4XHts5VCe3UYoJCGPOVt9yVq0qTgu2R4Q7Mb6wNxyElR2MZ/XD1pJEfYIkCr88gdSeTJyKsTUfQE0o9eBQqqcQ==.ZXhwYW5kMA==”,
“structured_formatting”: {
“main_text”: “Cửa hàng thời trang D&K”,
“secondary_text”: “55 Phú Đô, Phú Đô, Nam Từ Liêm, Hà Nội”
},
“terms”: ,
“has_children”: false,
“display_type”: “expand0”,
“score”: 309.2507,
“plus_code”: {
“compound_code”: “+3P39 Phú Đô, Nam Từ Liêm, Hà Nội”,
“global_code”: “LOYT+3P39”
}
},
{
“description”: “Giầy thời trang D&A, 69 Nguyễn Sơn, Ngọc Lâm, Long Biên, Hà Nội”,
“matched_substrings”: ,
“place_id”: “J9kBMv2IbAEOlvAF9Hs1TneKRmNev3gq7b6uIaPjiLIJE6u6fbeklo4V2gjf11q3GHrg2N_nMZmYPlVBewA/YA==.ZXhwYW5kMA==”,
“reference”: “ZW3ppvtytMeKyAdc5KZHip7Kpw8wpOd5lrJi33Nf4Y5X9PqMI31qOwcnwJxJ9qSVI9HxmO_WZHiOyi5sO2H8hQ==.ZXhwYW5kMA==”,
“structured_formatting”: {
“main_text”: “Giầy thời trang D&A”,
“secondary_text”: “69 Nguyễn Sơn, Ngọc Lâm, Long Biên, Hà Nội”
},
“terms”: ,
“has_children”: false,
“display_type”: “expand0”,
“score”: 305.6965,
“plus_code”: {
“compound_code”: “+3ZJK Ngọc Lâm, Long Biên, Hà Nội”,
“global_code”: “LOEJ+3ZJK”
}
}
],
“executed_time”: 39,
“executed_time_all”: 39,
“status”: “OK”
}