Variables set with pm.collectionVariables.set get converted from numbers to strings
See original GitHub issueIβ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 Version (can be found via
newman -v
): 4.5.7 - OS details (type, version, and architecture): OS X High Sierra 10.13.6 (although also manifests in Jenkins)
- Are you using Newman as a library, or via the CLI? CLI
- Did you encounter this recently, or has this bug always been there: No idea!
- Expected behaviour: When comparing against collection variables, preserve type.
- Command / script used to run Newman:
newman run https://www.getpostman.com/collections/a66a2b24bf49a0126bdc
- Sample collection, and auxiliary files (minus the sensitive details): https://www.getpostman.com/collections/a66a2b24bf49a0126bdc
- Screenshots (if applicable): See below
Reproducing the problem:
- Open Postman app.
- Create a new request, doesnβt matter what kind. (I used
GET http://example.org
) - Set up a numeric collection variable in the Pre-request Script tab:
pm.collectionVariables.set('aNumber', 137);
- Add tests verifying that the variable is a number:
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"
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Collection variable how to set from tests - Help - Postman
hello, I'm new to this and trying to do a flow where 1 send request will create a variable called orgID from the...
Read more >Postman Get Current Collection Variable Value - Stack Overflow
I need to get current exact collection variable valueΒ ...
Read more >How to Use Variables in Postman - YouTube
Variables allow you to store and reuse values in your requests and ... Postman Beginner Tutorial 8 | Get and Set Variables with...
Read more >Postman Cheatsheet
All variables can be manually set using the Postman GUI and are scoped. ... Setting. pm.collectionVariables.set('myVariable', MY_VALUE);. Getting. pm.
Read more >Understanding Variable Scopes And Environment Files In ...
For Example, a variable can have a global scope i.e. any class/method can ... What are Collection Variables and when should they be...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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 I encountered this problem too and am getting around it with this workaround: https://stackoverflow.com/a/57172160/3903984