As we know when user run individual request from workspace directly, User can save response in text file through “save to a file” from “Save Response” dropdown.
But When we run request(s) from collection runner, How we can save the response?
I can see 2 options which are not feasible as per my opinion.
A. Open the collection runner, Select the required collection and request, select the “save responses” checkbox and run it.
click on individual request, select the response body and manually copy the response and paste it to locally which is not feasibly because we can’t do manually one by one for 100 requests.
B. Click on “export Result” button in the Run Result tab where results are showing but saved file contain the status(pass/fail) rather then response.
By locally do you mean that you are running Postman remotely?
The only thing I can think of to achieve this, without using newman, is to save the request and response as environment variables, to which then you can export that environment and get the values out from there. Aside from that you can also send the response to a special / custom web server for recording purposes, using pm.sendRequest and putting the response in the request payload.
At the moment, I cant think of any other ideas on how to achieve this. Hope one of the options above are viable!
When the collection is has completed, you will have every response from every request in that collection run in the collectionResponses collection variable.
I have the same problem. I want to run many get requests at with the runner but can’t save the response body from each in a file at the end.
I tried your code to write it in a global variable but in the new postman version there is no such a function:
“There was an error in evaluating the test script: TypeError: responses.push is not a function”
I had the same problem and found that Postman saves variables as strings. You need to JSON.parse() the variable to get it back into an array so that you can push into it.
@allenheltondev thanks for the tip and @jannieo9
Sorry new to this, but once all the variables are stored in the variable, how can i export that? and any way to save that as a csv? (without newman).
Hello @allenheltondev, I am new to Postman, scripting, and collection variables (and forum participation in general so I am a certified newbie!!). In the test script you provided, is that attached to the body of the get request and is it coded in javascript? I’m not sure how to make use of it in Postman/Collection Runner. I am looking at documentation and trying to figure it out, however if you could give me some pointers that would be great!
Hope this thread is still active and hope it is appropriate question for this thread.
Firstly, welcome to the Postman community and congrats on your first post!
Test scripts can be a part of specific requests, folders and also, in this situation, a collection itself. You can read more about using them here.
For the test script provided by Allen, you would attach that to your collection by clicking on the collection item and then under the “Tests” tab. These tests are written in Javascript and using ChaiJS BDD syntax.
The collection runner will then run all tests attached to requests, folders and collections that you set to run in the run order.
Kevin, thank you for your response! There’s just so much info to go through you just saved me probably hours of searching. I browsed through the link you gave me and it looks like exactly the area of help that I need.
When I added a test as you instructed using Allen’s script it gave me the error: “responses.push is not a function”. I’ll go through the link and see if I can figure it out. Thanks again!!!
The difference here is parsing the value from the collectionResponses environment variable instead of using it as is. Likely what was happening was the variable content was a string instead of an array (which very much is what it was since we’re using JSON.stringify to set the value in the first place!)
Thank you Allen! I actually found another response you had posted where you modified for Pranavdavar and I was able to put that in without errors. Still figuring a lot of things out but slowly getting there thanks to the community support. Much appreciated!
@allenheltondev How would you go about saving the original request with the response (from above code). Thank you!
Used this, but the URL is on a separate line
let responses = pm.collectionVariables.get(‘collectionResponses’)
back to the collection end edit. Click on Variables. One variable named collectionResponses has all the results and it is cool (thanks Allen)! Copy the content of collectionResponses into the clipboard and save into a file.
The next problem is that the responses are in a file of one long line!
To split the line you can make usage of the sed command.
Example:
cat results.json | sed ‘s/}}}/\n/g’ > result_f.txt
the string ‘}}}’ is replaced by ‘\n’, end of line.
This procedure is not easy…
Code to add to the test
Execute the test
Extracting the result from the collection
Copy/paste
Saving into a file
Split the file
I think Postman as a product lacks this func. My opinion.