3

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.

Megan Barton
  • 51
  • 1
  • 6

2 Answers2

2

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.

Megan Barton
  • 51
  • 1
  • 6
0

Had a similar issue with an error message like

DELETE /my-api/some-endpoint
  DELETE {{apiRoot}}/my-api/some-endpoint [errored]
     getaddrinfo ENOTFOUND {{apiroot}}

Which was a bit weird as a had the environment variable in my JSON but I assumed that the environment json format is just key/value pairs but it should actually be in postman format like:

{
    "id": "12345678-1234-1234-1234-123456789012",
    "name": "Environment X",
    "values": [
        {
            "key": "apiRoot",
            "value": "localhost",
            "enabled": true
        }
    ],
    "_postman_variable_scope": "environment",
    "_postman_exported_at": "2021-01-01T00:00:00.000Z",
    "_postman_exported_using": "Postman/9.0.2"
}
Aleksi
  • 520
  • 4
  • 10