Here I run into a concern about using newman on a test campaign I created in postman. Indeed in some of my test scenarios I test the upload of a pdf file. The POST requests that handle upload all return status 201 in Postman as I see fit.
In newman, however, some of these requests return a 415, as if the format was not supported by the API.
I tried to run a newman run mycollection.json --verbose to try to see the contents of the headers, but it did not give anything. Impossible to visualize the headers.
My environment and my collection are up to date. My OS is ubuntu 20.04.
I don’t understand why the API returns the correct status (201) in Postman and not in newman
Thank you so much, you put me on the path.
Indeed the paths of my files were incorrect in my json collection file.
I don’t understand how this is possible. I was careful to update the export of my collection. I had to change the path by hand in the collection file (22,000 lines…). I didn’t find any other way. But it works now.
Indeed I used ctrl+f to find each “src”, then I pasted the right path. Otherwise I’m interested in the second option you describe. But how do I create a variable with file names? For now I will search for the files in my working directory, then add them to the body of the request.
You can run a bash script to do find and replace after exporting your collection. This will hopefully add the correct location of your needed files.
There is another option as well though… You can use the working Directory. The working directory is also used by Newman, so any test needing a file upload should work the same if your file is located there.
It has been a bit since I have ran this but if you leave the source blank then you can do this. The script/exported collection and file need to be in the same file as it is setup here. This will also replace ALL instances where there is not a file specified in the collection used.
#!/bin/bash
sed -i 's/"src": ""/"src": "filename.pdf"/g' mycollection.json
Thanks for the replies ! Indeed I tried the method used by @vdespa and it’s work well.
But actually I don’t see how to create a variable on the path especially since the body of the request offers a location using the file manager and not a written path.
For @whersh, I’ve already set up the working directory like this:
I’m going to try your method with the bash script. Do you have the source of your bash script or a tutorial where this is explained? The next challenge will be to share this collection with the rest of my team.
Sorry I do not have a source or a tutorial as I wrote this myself. I am sure looking a bit of sed documentation will help with the explanation. Example tutorial
Shareing the collection can either be done a few different ways but a few are described here in the sharing section of Postman documentation