How to export/download Response Body into an external file from Postman Collection Runner Results?

前端 未结 5 1322
无人共我
无人共我 2020-12-17 17:15

I am working on a project where I have to hit a web service multiple times with different values of a variable

For example, http://mywebservice.com?variable1={{valu

5条回答
  •  醉话见心
    2020-12-17 17:48

    I faced this situation and solved it by using the CLI tool newman

    First you need to export your collection and the environment as JSON files. Then install newman using the command:

    sudo npm install -g newman
    

    Then if you want a neat looking HTML report for the results, then first install the external reported newman-reporter-html with the below command

    sudo npm install -g newman-reporter-html
    

    You can generate the report now by running the following command:

    newman run  -e  -r cli,html
    

    By default, the HTML file will not contain the request and response body. In order to render that, first download the default handlebars template and then tweak it a little bit. You can find the default handlebars template here. Download the file and save it as template.hbs. Then open it in any editor and look for the code where it is rendering the Status Code. It might look like this:

     

    Status code
    {{response.code}}

    Below this part, add the following lines:

     

    Request body

     

    Response body

    Now you can run the following command to render the HTML with request and response body:

    newman run  -e  -r cli,html --reporter-html-template template.hbs
    

    Hope this helps!

提交回复
热议问题