I've encountered an odd problem that doesn't manifest in postman, but does in Newman. When I set collection variables in the pre-request script tab, they appear to be converted into strings.
newman -v): 4.5.7newman run https://www.getpostman.com/collections/a66a2b24bf49a0126bdcGET http://example.org)pm.collectionVariables.set('aNumber', 137);

pm.test("Is this a number?", () => {
const aNumber = pm.variables.get("aNumber");
pm.expect(aNumber).to.equal(137);
pm.expect(typeof aNumber).to.equal("number");
});

Execute request in Postman app, and watch them succeed.
Execute request in newman CLI, and watch them fail:
# newman run https://www.getpostman.com/collections/a66a2b24bf49a0126bdc
newman: Newman v4 deprecates support for the v1 collection format
Use the Postman Native app to export collections in the v2 format
newman
Newman Bug 20191209
β Bug demo
GET http://example.org/ [200 OK, 1014B, 97ms]
1. Is this a number?
βββββββββββββββββββββββββββ¬βββββββββββββββββββ¬βββββββββββββββββββ
β β executed β failed β
βββββββββββββββββββββββββββΌβββββββββββββββββββΌβββββββββββββββββββ€
β iterations β 1 β 0 β
βββββββββββββββββββββββββββΌβββββββββββββββββββΌβββββββββββββββββββ€
β requests β 1 β 0 β
βββββββββββββββββββββββββββΌβββββββββββββββββββΌβββββββββββββββββββ€
β test-scripts β 1 β 0 β
βββββββββββββββββββββββββββΌβββββββββββββββββββΌβββββββββββββββββββ€
β prerequest-scripts β 1 β 0 β
βββββββββββββββββββββββββββΌβββββββββββββββββββΌβββββββββββββββββββ€
β assertions β 1 β 1 β
βββββββββββββββββββββββββββ΄βββββββββββββββββββ΄βββββββββββββββββββ€
β total run duration: 174ms β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β total data received: 648B (approx) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β average response time: 97ms [min: 97ms, max: 97ms, s.d.: 0Β΅s] β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# failure detail
1. AssertionError Is this a number?
expected '137' to equal 137
at assertion:0 in test-script
inside "Bug demo"

@pavellishin I encountered this problem too and am getting around it with this workaround:
https://stackoverflow.com/a/57172160/3903984
Yup, I'm using something similar, but I'd rather see this fixed. Right now, we don't care about the string-vs-number distinction, but in the future the type may matter.
@pavellishin It's not that pm.collectionVariables.set is converting the int into a string but when you initialized the aNumber in the variable key of your collection you gave it a value "" which is a string.
In sort, you initialized your variable with a string value and therefore the pm.collectionVariables.set is treating it as a string.
If you initialize your variable with 0 instead of "". your test should work fine.
.
.
.
"variables": [
{
"key": "aNumber",
- "value": "",
+ "value": 0,
"disabled": false
}
],
.
.
.
In sort, you initialized your variable with a string value and therefore the
pm.collectionVariables.setis treating it as a string.
But I didn't do that. I'm not sure how those lines get generated by Postman itself, but I didn't take any explicit steps to initialize that data. Plus, those tests work fine in Postman, but fail in Newman.
To me this suggests that whatever is generating that JSON has a bug in it; it shouldn't be initializing a variable to any value at all.
Also not sure why it magically casts my explicit value of 137 into a string...
Hi. Giving some context to the issue here so that we can decide how to proceed. All Postman variables are supposed to be strings. Though we internally support a number of types, it is not yet completely baked into the product (both app and newman needs to build this in tandem in order to ensure it works seamlessly.)
As such, a number of issues manifest due to JavaScript quirks as we try to cast non string get/set into strings. There have also been cases where we missed putting casting logic in certain flows and instead handled it by mistake in app UI flows (as such creating disparity between how app and newman works.) There have also been cases where it was very surprising to users, who did not know about the string type aspect, to suddenly see their numbers become string and such.
Hope this helps.
All Postman variables are supposed to be strings.
Oof, I didn't know that. I assumed they could be anything, since the GUI app supports this.
Does this mean that variables can only be simple scalar values, and not objects?
True. Variables can be scalar values and even Postman GUI supports only scalar values.
But if youβre using the variables programmatically, you can apply casting shenanigans to convert objects to string and vice versa.
Most helpful comment
Yup, I'm using something similar, but I'd rather see this fixed. Right now, we don't care about the string-vs-number distinction, but in the future the type may matter.