Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test script passes in Postman but fails in Newman with Numbers in double quotes #1100

Closed
biplabpramanik007 opened this issue Jul 3, 2017 · 12 comments
Assignees

Comments

@biplabpramanik007
Copy link

newman -3.7.4

-->OS: Windows 10
--> CLI
-->Expected Behaviour: The test should pass in newman with numbers in double quotes. Numbers without quotes in response are working but when numbers are coming in double quotes its not working.

Test Scripts:
var jsonData = JSON.parse(responseBody);
tests["Last4Digit of Car Passed"] = jsonData.vehicles[0].last4VinDigits===data.last;
console.log(responseBody);

Data File:
plate,cust,manufacturerYear,product,last
AMT210,45156841,1987,FORD,"7747"

Command:
newman -run Testrunner.json -e environment.json -d data.csv
Result:
newman

NewRunner

→ CheckRego
GET https://api-it1.testservicensw.net/v1/me/registrations/roads/reports/eligibility?plateNumber=AMT210 [200 OK, 967B, 611ms]

│ '{"vehicles":[{"vehicleID":"66027145","vehicleModel":{
│ "manufacturer":{"code":"FORD","description":"FORD"},"m
│ anufactureYear":1987,"manufactureMonth":1,"model":{"co
│ de":"MONDEO","description":"MONDEO"},"bodyShape":{"cod
│ e":"SED","description":"SEDAN"}},"last4VinDigits":"774
│ 7","primaryColour":{"code":"20","description":"BLACK"}
│ ,"plate":{"plateNumber":"AMT210","plateType":"O"}}],"c
│ ustomer":{"customerName":{"givenName":"SNSW","familyNa
│ me":"DATA","customerNameText":"Snsw DATA"}},"messages"
│ :[{"code":"SUCCESS","message":"Success","severity":"SU
│ CCESS","category":"BUSINESS"}]}'

√ Body matches vehicleID
√ Status code is 200
√ vehicle id value
√ Plate Number matches
√ Manufaturer Passed

  1. Last4Digit of Car Passed

┌─────────────────────────┬──────────┬──────────┐
│ │ executed │ failed │
├─────────────────────────┼──────────┼──────────┤
│ iterations │ 1 │ 0 │
├─────────────────────────┼──────────┼──────────┤
│ requests │ 1 │ 0 │
├─────────────────────────┼──────────┼──────────┤
│ test-scripts │ 1 │ 0 │
├─────────────────────────┼──────────┼──────────┤
│ prerequest-scripts │ 0 │ 0 │
├─────────────────────────┼──────────┼──────────┤
│ assertions │ 6 │ 1 │
├─────────────────────────┴──────────┴──────────┤
│ total run duration: 751ms │
├───────────────────────────────────────────────┤
│ total data received: 326B (approx) │
├───────────────────────────────────────────────┤
│ average response time: 611ms │
└───────────────────────────────────────────────┘

failure detail

  1. AssertionFailure Last4Digit of Car Passed
    at assertion:6 in test-script
    inside "CheckRego"
@biplabpramanik007
Copy link
Author

Body Response: Where ever numbers are coming with double quotes are failing.
{
"vehicles": [
{
"vehicleID": "66027145",
"vehicleModel": {
"manufacturer": {
"code": "FORD",
"description": "FORD"
},
"manufactureYear": 1987,
"manufactureMonth": 1,
"model": {
"code": "MONDEO",
"description": "MONDEO"
},
"bodyShape": {
"code": "SED",
"description": "SEDAN"
}
},
"last4VinDigits": "7747",
"primaryColour": {
"code": "20",
"description": "BLACK"
},
"plate": {
"plateNumber": "AMT210",
"plateType": "O"
}
}

@biplabpramanik007
Copy link
Author

@kunagpal : Is there any progress on this?

@kunagpal
Copy link
Member

This isn't being worked on right now, but I'll update this thread once work starts. 😄

@TheCoderGuyVlad
Copy link

TheCoderGuyVlad commented Oct 2, 2017

Hi Newman Team,
I am seeing a similar behavior in Newman CLI version 3.8.0. Here is a simplified example:

If I load a CSV data file like this:

ValueA,ValueB
05,"05"

I expect the ValueA to be treated as a number and give 5, and ValueB to be treated as a string and give 05. Instead, they are both treated as numbers and return 5. This works correctly in Postman itself, and I believe this bug was introduced by the fix for issue #1054.

Please help us to resolve this. We are building an automation suite based on Postman/Newman and much of our data uses IDs that start with leading zeros.

Thank you

@TheCoderGuyVlad
Copy link

TheCoderGuyVlad commented Oct 13, 2017

Hi Team,
Could you please help us resolve this? Our company is moving to automated API testing through Postman. A big corner stone of this is being able to automate the tests using Newman scripts, but currently this is being blocked because our data has many fields which are stored as numeric strings (digits in double quotes) and a large number of these begin with 0 as the first digit. When we load this data via CSV, all quoted numeric strings get cast into numbers and loose their leading zeros.

For example, we are seeing that all three of these IDs are treated as the same number in Newman:

"0000123"
"0123"
"123"

This is causing the wrong data to be retrieved by the API.

The difficulty for us is that it's impossible to check for the issue pragmatically and correct it in the code because it occurs during the CSV load, so the data is lost even before it even gets to our JS code.

Thank you for you help!

@davefreireich
Copy link

Hi Team,

Is there any movement on this issue? Like some of the users above, my company uses a lot of numeric strings. As mentioned before, these work fine in collection runner but fail in Newman.

@vijaygroovey
Copy link

Hi Team
I am also facing the same issue. Is here any update on this issue?

@TheCoderGuyVlad
Copy link

TheCoderGuyVlad commented Feb 23, 2018

@vijaygroovey I have not heared anything. But as a work around, I added a tilde (~) in front of each number in my csv. This way, Newman reads it as a string and I wrote a function to strip the ~ from it and store it into an environment variable with different name, so there's no chance of using the wrong value.

Example:

    // Column name=employeeId
    // Column value="~00108251"
    var temp=data.employeeId;
    if(temp.substring(0,1)==="~") // Checks if string begins with tilde
        temp=temp.replace("~",""); // Replaces only first occurrence
    postman.setEnvironmentVariable("employeeId_parced", temp); // Set to a new variable

@saswatds
Copy link
Contributor

saswatds commented Mar 19, 2018

This issue is with the underlying csv-parse library with newman uses to parse csv files. So we have gone ahead and raised an issue here: adaltas/node-csv-parse#182

@biplabpramanik007 @TheCoderGuyVlad @davefreireich @vijaygroovey as a temporary fix you can quote the numbers within single quotes ('7747') instead of double quotes to preserve the number as String.

@TheCoderGuyVlad
Copy link

Thanks @saswatds ! And thanks for the single quote suggestion!

@codenirvana
Copy link
Member

@biplabpramanik007 @TheCoderGuyVlad @davefreireich @vijaygroovey a fix has been added in #1609 which will be rolled out with the v4 release.

You can test this using v4.0.0-beta.2.

@codenirvana
Copy link
Member

@biplabpramanik007 @TheCoderGuyVlad @davefreireich @vijaygroovey This has been fixed in Newman v4.0.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants