keerthi
keerthi

Reputation: 11

Newman unable to read property and throws error but postman collection runner works fine

I was trying to run my test cases through runner class in postman and it works fine but the same implementation if I run in newman. The first API since I am setting environment variables, newman is not able to read the variable.

As per my observation my json response in postman like below example

[
    {
        "SECURITY_QUESTION": "SQ10",
        "PTN_STATUS": "A",      
        "PTN": "52115456335",
        "SYS_CREATION_DATE": "2019-06-20T07:36:23.000+0000",
        "ENCR_SECURITY_ANS": "!L[>",
        "BAN": 278030106,
        "ENCR_PIN_NUMBER": ">aR)"
    }
]

In newman-- It reads property with "" but the BAN with no double quotes is not able to read

Newman Error:

01.  TypeError                                     Cannot read property 'BAN' of undefined
                                                    at test-script

AS my first test case is integrated with environment variables this is blocking my testing. However, I tried in postman and it can read the BAN value which is shown in the json response tend to read but the only problem is in newman, it cannot read the BAN property.

Expected : Should run in newman cmd and take the value even if it is not double quoted

Upvotes: 1

Views: 964

Answers (2)

VJPPaz
VJPPaz

Reputation: 1015

check if the object you are trying to access is not undefined.

Upvotes: 0

Nurullah Aktas
Nurullah Aktas

Reputation: 1

I had the same issue: I had a postman collection which was perfectly running in the postman runner without any issue in my local. I wanted to run my collection in three ways: CLI, GitHub Actions and Azure DevOps. My collection has two folders. When I execute my collection in CLI, GitHub Actions and Azure, the first test cases in each folder were failing. In order to solve this issue, I deleted and re-created these tests. It did not work for me. I was using some collection variables such as query parameter. Newman could not get these collection variables in these first test cases, that's why it was failing. So I decided to set my collection variables in the 'Pre-Request Script' of these test cases in Postman. Then I exported my collection again. It worked. Newman may have some timing issue to read the variables and use it. It executes first test cases of the folders in my collection so quickly without having enough time to read them in collection variables.

Upvotes: 0

Related Questions