When using the
newman CLI (version 5.2.2), there is a requirement to save updated collection variables after a run. To achieve this,
-export-collection <path> is being used but variables in the collection at
<path> do not contain updated values after a run.
To set a variable value during the run,
pm.collectionVariables.set() is being used in a request test.
let jsonResponse = pm.response.json(); pm.collectionVariables.set("myVariable", jsonResponse.value);
When testing the request in Postman, the updated variable value persists in the collection. The same is true if the runner is used with Keep variable values checked.
However, when using the
newman CLI the collection variables are not updated after the run.
newman run collection.json --environment environment.json --export-collection collection.json
According to the documentation,
--export-collection|globals|environment <path> is -
The path to the file where Newman will output the final collection / global variables / environment variables file before completing a run.
Testing shows that setting a global/environment variable in the request and using
--export-globals|environment <path> works, with the output file containing the updated variable value.
Is this a bug with the
newman CLI, or is there something that can be done to fix this behaviour?
This question is also on Stack Overflow.