2

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?

James Wierzba
  • 16,176
  • 14
  • 79
  • 120

5 Answers5

4

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

Victor SDK
  • 353
  • 3
  • 13
1

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.

shaochuancs
  • 15,342
  • 3
  • 54
  • 62
1

Try this key:

--global-var <value>            Allows the specification of global variables via the command line, in a key=value format
uBaH
  • 169
  • 1
  • 12
0

You can use newman run collection.json --global-var "<global-variable-name>=<global-variable-value>"

0

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"
mvndaai
  • 3,453
  • 3
  • 30
  • 34