Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle file download request from Newman #413

Closed
swapnilpatne opened this issue Jun 3, 2016 · 15 comments
Closed

handle file download request from Newman #413

swapnilpatne opened this issue Jun 3, 2016 · 15 comments

Comments

@swapnilpatne
Copy link

How to handle file download request from Newman? Can someone please answer?

@czardoz
Copy link
Contributor

czardoz commented Jun 7, 2016

@swapnilpatne You mean saving the request to a file?

@swapnilpatne
Copy link
Author

I mean when a response of a request is file e.g. pdf or zip or xml file etc

@czardoz
Copy link
Contributor

czardoz commented Jun 7, 2016

Hmm, Newman will expose the responseBody as the responseBody parameter in your tests, but there's currently no way to save responses to a file.

@swapnilpatne
Copy link
Author

Is there a way by which from "tests" tab in Postman I can read the filename returned in response header and then write a javascript code to get that response written in file? And then can run those requests from newman?

@kunagpal
Copy link
Member

@swapnilpatne Well, writing to a file will require using one of the write methods from fs, which is currently not included within the Postman Sandbox.

@shikhartanwar
Copy link

Is this being targeted for the next release? As a newman user I feel that this is a very important feature and blocks of lot of API operations that are centered around files or storage.

@kiranwilson
Copy link

Do we have any update regarding this feature?

@kunagpal
Copy link
Member

kunagpal commented Jul 6, 2017

@kiranwilson This isn't in the works presently, but we'll update this thread when any progress is made.

@kiranwilson
Copy link

@kunagpal Thanks for the response

@kunagpal
Copy link
Member

kunagpal commented Jul 18, 2017

@swapnilpatne @kiranwilson @shikhartanwar As a workaround, you can have the following snippet in a file, say newman-run.js:

var i = 0,
    fs = require('fs'),
    newman = require('newman'); // ensure that you have run "npm i newman" in the same directory as this file

newman.run({
  // run options go here
}, function (err, summary) {
  // handle collection run err, process the run summary here
}).on('request', function (err, execution) { // This is triggered when a response has been recieved
   if (err) { return console.error(err); }

   fs.writeFile(`response${i++}.txt`, execution.response.stream, function (error) {
      if (error) { console.error(error); }
   });
});

You can then run the script above with node newman-run.js, which will save responses to any file of your choice.

@chitzinwin
Copy link

I run as node newman-run.js collection.json but no file was created. do I have to change in the script?

@kunagpal
Copy link
Member

@chitzinwin You'll have to specify the collection as an option in the first argument to newman.run. See https://github.com/postmanlabs/newman#newmanrunevents for a working example.

@chitzinwin
Copy link

Perfect! It's working now. @kunagpal Thank for prompt response!

@shamasis
Copy link
Member

shamasis commented Jun 5, 2018

Closing issue. Also on another note, someone can create a newman reporter that saves all responses to file :-p

@shamasis shamasis closed this as completed Jun 5, 2018
@RSUIAutomation
Copy link

So the send and download feature is not available in newman?

Postman always relies on third party code to handle its upload data?

You cant actually fully automate sending files using newman? You always have to add some third party code to get files completely separately?

Every time you want to share a postman collection with other developers you also have to send them dependencies of the postman tests completely separately?

Newman can't manage files it needs for its tests on its own?

Why isn't this being worked on?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants