Search code examples
automated-testspostmannewmanhttp-response-codes

Capturing Postman requests in a report


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 an assertion but is there a way wherein 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 gave 200 for first call 201 for the second and 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.


Solution

  • 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