Reputation: 17498
I'm using newman and postman to run a suite of postman request and associated test scripts.
I have an environment variable that is a sensitive piece of information that I cannot store on disk (therefore I can't declare it inside of the JSON test file). I need to have some simple way for it to be passed into the tests.
I would like to assign a value to the environment variable on the command line as an argument when I run the tests.
I run the tests like so:
newman run c:\path\to\test.json
I want to do something like this:
newman run c:\path\to\test.json passwordEnvVariable=mypassword
Is such a thing possible?
Upvotes: 3
Views: 8162
Reputation: 3831
I was running my collection
through postman's APIs with an environment
in the also from the APIs and then overriding just one variable locally. I used this answer to find my uids. and then ran something like this after adding POSTMAN_API_KEY
into my .zshrc
file
newman run "https://api.getpostman.com/collections/$uid?apikey=$POSTMAN_API_KEY" \
--env-var "password=mypassword" \
# environment file needs to be after local values
--environment "https://api.getpostman.com/environments/$uid?apikey=$POSTMAN_API_KEY"
Upvotes: 1
Reputation: 473
For environment variable use:
newman run c:\path\to\test.json --env-var passwordEnvVariable=mypassword
According to newman documentation: https://www.npmjs.com/package/newman
Upvotes: 4
Reputation: 1
You can use newman run collection.json --global-var "<global-variable-name>=<global-variable-value>"
Upvotes: 0
Reputation: 179
Try this key:
--global-var <value> Allows the specification of global variables via the command line, in a key=value format
Upvotes: 1
Reputation: 16226
According to newman's document, there is no such option. Right now, the only way to pass environment variable is passing a file path or URL.
However, @michaelajr raised a feature request 8 days ago (May 4th), which is exactly what you want: Pass environment variables on the command line. As newman team has acknowledged this feature and no workaround is posted in the thread, it is unlikely to find a workaround either.
Wish newman will add this feature soon.
Upvotes: 1