postmanlabs / newman

Newman is a command-line collection runner for Postman
https://www.postman.com
Apache License 2.0
6.88k stars 1.17k forks source link

`--export-collection` does not output updated collection variables #2680

Open codenirvana opened 3 years ago

codenirvana commented 3 years ago

Refer: https://community.postman.com/t/using-export-collection-does-not-output-updated-collection-variables/21777

adityaofficial10 commented 3 years ago

@codenirvana Is there an option like 'keep values' that can be passed to the runner?

dgard1981 commented 3 years ago

@adityaofficial10, that is the purpose of --export-collection, according to the documentation. Otherwise all you'd output is the exact same collection that was used for the run.

The --export-globals|environment options do output updated variables.

adityaofficial10 commented 3 years ago

@dgard1981 Yeah that is correct. But I read on the forum link , that runner does update the values when used with keep values. So I was just asking if there's an option like that or that means something else...

dgard1981 commented 3 years ago

@adityaofficial10, there is no similar option as far as I can see from the documentation.

I suspect that checking "Keep values" in the Postman runner applies the --export-collection|environment|globals options, and my guess is that it's not using the latest version of the newman CLI which is why it works as expected. That is just speculation though.

adityaofficial10 commented 3 years ago

@dgard1981 Seems interesting to me.. I also tried searching for something in the runtime module but didn't found anything. But I think if runtime is fine, then how can newman have this error?

shamasis commented 3 years ago

Newman always keeps the values. The export options are meant to get access to that.

Collection variables are by design not updated during the run and synchronised at the same time - this avoids mutating the collection while its being run. For example, pre-request script can mutate the request to be run, but it's an execution just-in-time change and hence does not actually change the Collection. Same applies for collection variables.

Having said that, getting hold of the updated variables post run is a valid use. For now, you can have a collection level test script that copies entire collection variables into one json inside environment variable and get this data out. Other option is to use newman programmatically and not as CLI and get this out. Another option is to write a simple reporter (see reporter examples in repo) and save the collection variables on run end to a file.

Meanwhile, I will let @codenirvana comment on if we should by default export "current values" in Newman and how will it impact integration with Postman.

dgard1981 commented 3 years ago

@shamasis, thanks for the reply.

For now I have moved to environment variables. It's not ideal as it means we have extra variables in every environment, but it works and that's the main thing.

I will look in to reporters and see how easy it is to do what I need to do.

adrwh commented 2 years ago

Variables in Collections AND Environments are also NOT export when using Postman app on MacOs. The exported postman v2.1 json file contains {{variableName}} instead of the actual values.

hurrycaner commented 2 years ago

Variables in Collections AND Environments are also NOT export when using Postman app on MacOs. The exported postman v2.1 json file contains {{variableName}} instead of the actual values.

that's because you have to "persist" values before exporting, newman does that automatically for you