question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Variables set with pm.collectionVariables.set get converted from numbers to strings

See original GitHub issue

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.

  1. Newman Version (can be found via newman -v): 4.5.7
  2. OS details (type, version, and architecture): OS X High Sierra 10.13.6 (although also manifests in Jenkins)
  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: No idea!
  5. Expected behaviour: When comparing against collection variables, preserve type.
  6. Command / script used to run Newman: newman run https://www.getpostman.com/collections/a66a2b24bf49a0126bdc
  7. Sample collection, and auxiliary files (minus the sensitive details): https://www.getpostman.com/collections/a66a2b24bf49a0126bdc
  8. Screenshots (if applicable): See below

Reproducing the problem:

  1. Open Postman app.
  2. Create a new request, doesn’t matter what kind. (I used GET http://example.org)
  3. Set up a numeric collection variable in the Pre-request Script tab:
pm.collectionVariables.set('aNumber', 137);

image

  1. 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");
});

image

  1. Execute request in Postman app, and watch them succeed.

  2. 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"

image

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
pavellishincommented, Feb 7, 2020

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.

2reactions
carolmirakovecommented, Feb 6, 2020

@pavellishin I encountered this problem too and am getting around it with this workaround: https://stackoverflow.com/a/57172160/3903984

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found