Newman: Integer environment variables resolve to null

Created on 9 Mar 2018  路  7Comments  路  Source: postmanlabs/newman

  1. Newman Version: 3.9.3
  2. OS details (type, version, and architecture): macOS
  3. Are you using Newman as a library, or via the CLI? CLI
  4. Did you encounter this recently, or has this bug always been there: It used to work once :)

When setting an environment variable in the pre-request script:

pm.environment.set("foo", 0);

It is not sent in the request body:

{
    "x": {{foo}}
}

Steps to reproduce the problem:

  1. Import the collection in Postman: https://www.getpostman.com/collections/ce1ec4ed4a3c117a7448
  2. Run the tests, all is green
  3. Run with newman: newman run https://www.getpostman.com/collections/ce1ec4ed4a3c117a7448
  4. Test fails

Kind of similar with #1431

bug

All 7 comments

I've noticed something similar but with the false boolean. Using a boolean variable that is set to false (via postman.setEnvironmentVariable) in a query string (e.g. param={{paramVar}}) results in an empty parameter in a query string that uses the variable. The query parameter is resolved as param= instead of param=false

I have the same problem, that some variables are not resolved correct in the request body when executing the tests in Newman.. I am using Newman 3.9.3.
Is there any workaround for this problem? I would really appreciate any help since this issue blocks us to run Postmantests in a CI-CD-pipeline.

You can try the following workaround, while waiting for the solution of this issue. I know, it does not solve the real problem. But it makes the tests work for now.

There is a general problem with the variable handling in Postman and Newman.
Sometimes the variables aren't stored correcty, especially if there are not of type String. You can try to convert them toString manually with
```javascript
obj.toString() //for basic variables

or
```javascript 
JSON.stringify(obj) //for JSON objects

The example pre-request script of @vdespa

pm.environment.set("foo", 0);

will not fail anymore, if its written like this

var bar = 0;
pm.environment.set("foo", bar.toString());

I am also blocked by this bug :-(
For me query parameters defined by an environment variable (a number) set in my post scripts are not appearing in the URL when my collection is run through newman on the CLI.
I have no issues when running the collection with Runner (or manually step-by-step in Postman).

URL defined in Postman:
https://{{host}}/users/{{user_login.user_id}}?org={{user_login.org}}
Newman:
https://XXX:8080/users/10605?org=

I added hard-coded string parameters either side of org query parameter, but it made no difference

URL defined in Postman:
https://{{host}}/users/{{user_login.user_id}}?alpha="alpha"&org={{user_login.org}}&beta="beta"
Newman:
https://XXX:8080/users/10606?alpha="alpha"&org=&beta="beta"

Wrapping the numeric environment variable in single quotes didn't help:
Postman:
https://{{host}}/users/{{user_login.user_id}}?org='{{user_login.org}}'
Newman:
https://XXX:8080/users/10608?org=''

Newman 9.3.9
Postman latest, Linux CentOS 7.5 (1804)

@MarkSonghurst Thanks for chipping in, this bug will be fixed with the next release.

@MarkSonghurst @vdespa @DieGraueEminenz @BarbaraGoeller-AIT @etspaceman Could you try this with Newman v3.9.4 and confirm that it works correctly?

It works!! Many thanks.

Was this page helpful?
0 / 5 - 0 ratings