0

I was checking on Postman and newman and how to automate the api testing. I have checked on assertions and the report generations that show results of assertion failures and pass status. We can check the status code by writing a an assertion. But is there a way where in we can capture the request and response directly for an api and generate a report that shows (say) 3 apis were tested and the requests agve 200 for first call 201 fro second an d then 400 for third without writing any assertions. The overall result will show request url and corresponding response code for the api.

This will be helpful in a way when we run a collection and then can see a html report stating the response code corresponding to the request url.

Thank you all in advance for your patience reading and extremely helpful insight to the problem. Thank You.

Saurav Rath
  • 91
  • 1
  • 3
  • 11

1 Answers1

1

this already exists in Postman, through its command line interface Newman.

Have a look here and here as well. You'll be able to set options, depending on the kind of reports you want. Personaly I can use newman in TFS and get JUnit style reports that fit for my continuous integration purpose. You can generate also HTML reports.

Check the different options.

To handle response data, have a look here : This takes place in the Tests tab of the Postman request, though You can obtain informations about HTTP code (responseCode.code), description (responseCode.detail), etc. You can also parse the JSON body to get more information

var jsonData = JSON.parse(responseBody);

You can output this data in the console

A.Joly
  • 2,317
  • 2
  • 20
  • 25
  • 1
    Hi Joly, thanks for the comment. But can we capture the response without writing any assertions ? It would be graet if you can throw some light on capturing the response code from postman directly. – Saurav Rath Nov 02 '17 at 12:13
  • well, not so sure, you mean generating a report without having assertions in the test ? maybe outputing some information from the Tests tab, I add information for this point. – A.Joly Nov 02 '17 at 12:50
  • Yes. It is like I have a collection of test which does not contain any tests. If I run they give me response of 0 passed and 0 failed which is expected as I didn't write any tests. But each api call gave response like 200, 201,401. I can see those for each api call But I want the report to mention like 2 passed and 1 failed. ( 200,201 passed and 401 as failed). Instead of test results if this is mentioned then it will be great. Thanks – Saurav Rath Nov 02 '17 at 14:12
  • you make your task complex ! :) but you can do it, by handling globals. You increase their value in the Tests tab by testing the responseCode and finally, in the latest request's post-request script, you can build your summary and do a console.log on it ... beware though as globals handle strings, so you'll have to do conversions in order to increment the value. – A.Joly Nov 02 '17 at 14:19
  • Thanks Joly for your solution. Can you add a code snippet for the same. I am actually not getting the last part of what you said "in the latest request's post-request script, you can build your summary and do a console.log on it". Thanks – Saurav Rath Nov 06 '17 at 10:25