Newman: Scripts run in Postman but throws error in Newman

Created on 29 Aug 2018  路  11Comments  路  Source: postmanlabs/newman

  1. Newman Version:4.0.2,Postman Version:6.2.5
  2. OS details (type, version, and architecture): Windows 7,64 bit production Imagev1.16.00.AO.B19
  3. Newman via the CLI
  4. Did you encounter this recently, or has this bug always been there: Recently started using
  5. Expected behaviour: Scripts run through Postman passed and Newman should also have passed
  6. Command / script used to run Newman: "newman run Collection1"
  7. Sample collection, and auxiliary files (minus the sensitive details): https://www.getpostman.com/collections/e20dc7daa589e7dd2a22
    Screen shot:
    image

Steps to reproduce the problem:

  1. Have written scripts in Postman
  2. Generated link for the collection
  3. Ran command newman run https://www.getpostman.com/collections/e20dc7daa589e7dd2a22
    4.Throws error in newman(unexpected token u in json in position0,self signed certificate) but these errors do not appear in postman
    5.Another issue is if i use a global variable in the postman endpoint,newman doesn't detect it and throws another error saying Invalid url"
question

Most helpful comment

@debjchak you can disable SSL verification check and allow self-signed SSL certificate by using --insecure flag.

  • JSONError is because of pm.response.json() in test script tries to JSON parse response body but the request is failed because of SSL verification first.

  • To use global variables you need to specify them like --global-var "url=http://localhost".

Check all the available Newman options here.

All 11 comments

@debjchak you can disable SSL verification check and allow self-signed SSL certificate by using --insecure flag.

  • JSONError is because of pm.response.json() in test script tries to JSON parse response body but the request is failed because of SSL verification first.

  • To use global variables you need to specify them like --global-var "url=http://localhost".

Check all the available Newman options here.

Hi Udit,

Since I am completely new to Postman and Newman, I really do not know how
to execute the solutions you provided.Could you please elaborate a bit to
explain how to I run the command to allow self signed SSL certificate by
using the insecure flag?
Also, i need to know how to use --global-var "url=http://localhost"?Should
I just type this in before running my collection in Command Prompt ?

@debjchak you can use the above mentioned options like this:

newman run https://www.getpostman.com/collections/e20dc7daa589e7dd2a22 --insecure --global-var "url=http://localhost"

You can know more about using Postman and Newman from the following documentations:

Hi Udit,

Thanks for your quick response. The issue I am facing now is with global
variables. Everything works as expected if I do not use Global variables
in my url. but the moment I use them, i get the following error. Please
suggest.

@debjchak Can you specify the error and Newman command used?

Hi,
The errors I receive are

  1. "connect ECONNREFUSED 127.0.0.1:80"
    2.Unexpected token u in JSON at position 0 at assertion :0 in test script

@debjchak I see that you updated the request URL to {{url}}/applyUPUI.
Now using --global-var "<global-variable-name>=<global-variable-value>" option, you can replace the {{url}}(global-variable-name) with the required requesl URL(global-variable-value).

The above error is because you used --global-var "url=http://localhost" directly from my previous example, here you need to change http://localhost with your request URL https://10.144.3.... (as seen in the screenshot above).

Below is my command for which I still receive error stating "Invalid URI".
newman run https://www.getpostman.com/collections/e20dc7daa589e7dd2a22 --insecure --global-var
newman run https://www.getpostman.com/collections/e20dc7daa589e7dd2a22 --insecure --global-var
image

@debjchak You are missing global-variable-name i.e url in you case. It should be:

newman run https://www.getpostman.com/collections/e20dc7daa589e7dd2a22 --insecure --global-var "url=https://10.144.31.156/apic-dev/sb/primaryrepository/api/productmovements"

The Global variable name got hidden some how. Rectified now.All work as expected. Thank you so much for the quick responses and resolution.

image

Newman version 4.5.6
Postman-win64-7.10.0
node version 6.10.0
Created Collection
AuthLogin - Pre-request Script with json stored in variable and set the variable in environment to use it in body, wrote two test test in test.

Then exported collection v2.1 and saved this file as postman collection
image
and also saved environment variables
and ran newman on cmd - newman run AutomationScript.postman_collection -e STG.postman_environment.json

Was this page helpful?
0 / 5 - 0 ratings