2
votes

I have a Postman collection that I am trying to get working with newman, but my environment variables aren't being used.

The request URL is simply {{url}} and then I have an environment variable of the same name. I am running my test with this command:

newman run <path to collection> -e <path to env file> -r json --reporter-json-export <report path>

I can see in the report that the environment file is being read correctly and contains the variable I want to use, but the request fails and the report shows that the request was "url": "https://{{url}}" instead of what I actually wanted.

Of course the request fails because "https://{{url}}" isn't a valid URL, and then all of my tests fail because the request failed. This all works fine when I run the collection directly from Postman - my request goes to the server I intended and my tests pass as expected.

1

1 Answers

2
votes

My environment variables for URL initially were each using the format subdomain1.domain.com. Just for the heck of it I changed the URL in my request to https://{{url}}.domain.com and changed the environment variables to use just the subdomain. Then I exported everything again and ran newman, and it worked.

Not sure if I stumbled onto a bug with newman or the environment variable usage in URLs is not correctly documented, but at least I got my setup working.