Hello All,
I am created and API request in Postman and i am iterating the same for 30 iterations with different values such as passing different username everytime.
Now i have kept certain test in test scripts.
now in result i want to save request/response created/ downloaded in each iteration .
do we have any solution for that.
basically i want to create a report like postman does when i execute test using runner.
but i am unable to export the exact report from generated by runner in HTML or some other format.
any suggestions will be really help me.
Thanks in anticipation
This collection might help you in writing the response data to a file:
You can take the idea from it on how you can use pm.sendRequest feature of postman and build upon the nodejs server code and the script to make your own reporter etc.
@sivcan This is great. Very much appreciated. Is there a way to write results from multiple iterations? For instance, if I use collection runner to run a request 100 times, Iβm currently only getting one response and not all 100 written to the file.
@singhsivcan Thanks for the response. I ended up doing something similar by adding Date.now() to the file name so it will give me a unique file name for each iteration.
Thanks again for this. Helped me quite a bit to accomplish some testing at work.
I am using the Collection runner and pulling the request body in from an external file. Any idea how I could pull the name of that external file into the name of the file created for the response body?
Turns out the name of the external file used to populate the request body cannot be grabbed. My workaround was to use a unique identifier in the request body (also had to scrub this string for invalid filename characters):
I am very happy to have found this. Ive read the docu and setup local server. However when sending request via postman, local server is throwing error:
TypeError [ERR_INVALID_ARG_TYPE]: The βdataβ argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received undefined
any ideas? thank you so much (this will be a massive help to my project)
@alxpeace Try using the following script in the collection instead of the existing one.
To update the script go to the βWrite to responseβ collection > Click on the three dots > βEditβ > Tests tab.
Replace the tab with the following script:
// The opts for the server, also includes the data to be written to file
let opts = {
requestName: request.name || request.url,
fileExtension: 'json',
mode: 'writeFile', // Change this to any function of the fs library of node to use it.
uniqueIdentifier: false,
responseData: pm.response.text()
};
pm.sendRequest({
url: 'http://localhost:3000/write',
method: 'POST',
header: 'Content-Type:application/json',
body: {
mode: 'raw',
raw: JSON.stringify(opts)
}
}, function (err, res) {
console.log(res);
});