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

前端 未结 5 1315
无人共我
无人共我 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:42

    Here is a simple workaround if you're OK with storing the final data in an Environment Variable & just copying it to a .JSON file in a text editor after Collection Runner completes.

    First you'll need to create an environment (great tutorial in this blog post on Postman), and define a variable called responseData, with the value [].

    Then, add the following code under 'Tests' in Builder & save your collection. Postman environment variables are intended to be used as string, so we will parse the object then push the JSON responses from the API into the object array.

    var jsonData = JSON.parse(responseBody);
    var old = pm.environment.get("responseData");
    old = JSON.parse(old);
    // filter jsonData if needed
    
    old.push(jsonData);
    old = JSON.stringify(old);
    pm.environment.set("responseData", old);
    console.log(pm.environment.get("responseData"));
    

    Now you can retrieve a nested JSON object with all the response data included by viewing the environment variables value (see example below).

    Warning: you must reset the responseData value as [] after every use of Collection Runner in order to avoid keeping data from previous runs.

提交回复
热议问题