Newman run with relative file paths in form-data for file upload

Hi !

I am running postman tests in travis-ci with newman. Every time I modify my tests from the postman client, I export the JSON and the tests are ran from travis when pushed.

The problem is I want to test my file upload route but when I export the Collection, a Absolute path is exported for the file in form data !

Even though I have the working directory set. How can I overcome those issues without to have to edit the JSON manually every time ?

Ideally, Postman would export the files as a relative path that I can then do something with on travis, like creating the required folders etc…

Thanks !

1 Like

You can use either the Public link or the Postman API to run the collection. It will save you from exporting the file each time a change is made.

How / Where are you setting the working directory? In the app or with the newman flag?

--working-dir <path>
Set the path of the working directory to use while reading files with relative paths. Default to current directory.

1 Like

Thanks for the reply !

I like to export the collection so it can be source controlled with git, so we avoid having problems when multiple PRs are running in CI and they try to run a request on a route that isn’t on this PR. Unless you have another solution ? :smiley:

For the working directory, I set it in Postman’s desktop client. The problem is still that the collection looks for an absolute path (in my case /Users/seluj78/Postman/files/logo.png) on my macbook which obviously isn’t an existing directory in travis and alike CI runners. How can I work around that and pass files that are inside the repository so that the collections will work when exported and when on the desktop client ?

Have you tried setting a specific location using the Newman flag? Setting this in the app isn’t the same thing as setting these for the newman run.

--working-dir <path>
Set the path of the working directory to use while reading files with relative paths. Default to current directory.

1 Like

I’ll try it now. Thing is, in the postman collection, exported as JSON, the path isn’t relative !

Check it out here: https://github.com/Seluj78/PyMatcha/blob/41fafd7feb0f6361c4531a99cc821463bf65b5f4/PyMatcha.postman_collection.json#L3797

I would recommend replacing that path with a Postman variable.

This allows you to have control over it both from Postman and when doing CI/CD.

@vdespa I have seen the replacement of path with an env variable in several places in forums. But I do not understand how to do that without the need of editing the exported json file manually and enter like {{pathVariable}} anyway every time you want to push your json to be used by for ex Jenkins. Because in Postman application, in the body of the POST request, you specify a file using a select file button, not with a path or env variable in written text. Or there is something I do not know about.

Last time I have checked the only way is to do this by exporting the collection, editing it and re-importing it. But once you have this running, you don’t need to worry about this anymore.

Yes, of course. Did not think about that. It will be a one time effort. Thank you @vdespa , I will do this in my scripts from now on.

Hi, please is it possible to use this approach for different folders? I mean if sufficient when the higher level is used only.
image
On the screen, I have more folders where the data are stored. Let´ say that level above is called “data”. Would it be possible to use path e. g. …/…/data at the necessary data will be uploaded during requests or I need to specify more in variable like …/…/data/Sprint4.

Thanks