postmanlabs / newman

Newman is a command-line collection runner for Postman
https://www.postman.com
Apache License 2.0
6.88k stars 1.16k forks source link

"ReferenceError in test-script" while running newman #595

Closed DivyaKalyanakrishnan closed 8 years ago

DivyaKalyanakrishnan commented 8 years ago

Hi, I have a postman collection which runs fine from postman. In the script, i have some tests that do some basic validations on the responseData. But when launching it with newman in my machine, i get error as: "ReferenceError in test-script". In detail:

  1. Error - Invalid Protocol
  2. ReferenceErr - responseBody is not defined at test-script:5:31

-The same script works fine from other machine, using same newman version (3.1.0). -I have tried re-installing newman package but it has not helped. Kindly give a solution. Thanks,Divya

Error Snapshot: errorsnapshot

Updating ticket: Postman version: 4.7.0 ; win / x86-32; Chrome 52.0.2743.116. My system is a Windows 7, 64-bit OS. Newman version : 3.1.0

My url uses http & doesnot work in https mode. The snapshot attached is the one obtained while running newman command in cmd prompt, to launch the same collection. newman run AssetModel_CountValidations.postman_collection -n 1 -r junit --reporter-junit-export CountValidations.xml

Below is the snippet of test written for the microservice validation: var data = JSON.parse(responseBody);

//Classsifications var expectedCount=5; var actualCount=data.classifications.length; if(actualCount==expectedCount) tests["Classifications count matching!"] = true; else tests["Classifications count matching! Expected Count is "+expectedCount +"Actual count is "+ actualCount] = false;

Hope this helps.

kunagpal commented 8 years ago

@DivyaKalyanakrishnan Could you provide details on your Postman version, type (Chrome app or native app) and operating system, please?

jwilkey commented 8 years ago

I was seeing this as well and it turned out be an SSL error. In postman I was seeing "Could not get any response" which went away when I used http instead of https (even thought he server was properly completing the request at https). Anyway, changed to http and newman worked. Don't know if this is your issue, but either way the error output for me was misleading and not helpful.

DivyaKalyanakrishnan commented 8 years ago

@kunagpal : Postman version: 4.7.0 ; win / x86-32; Chrome 52.0.2743.116. My system is a Windows 7, 64-bit OS. Newman version : 3.1.0

@jwilkey : My url uses http & does not work in https mode. the snapshot attached is the one obtained while running newman command in cmd prompt, to launch the same collection. newman run AssetModel_CountValidations.postman_collection -n 1 -r junit --reporter-junit-export CountValidations.xml

Below is the snippet of test written for the microservice validation: var data = JSON.parse(responseBody);

//Classsifications var expectedCount=5; var actualCount=data.classifications.length; if(actualCount==expectedCount) tests["Classifications count matching!"] = true; else tests["Classifications count matching! Expected Count is "+expectedCount +"Actual count is "+ actualCount] = false;

Hope this helps.

kunagpal commented 8 years ago

@czardoz :point_up_2:

czardoz commented 8 years ago

Hi Divya, can you run newman with these commands and paste the output here?

If you are on Linux/OSX:

$ NODE_DEBUG=http newman run  <newman options>

If you are on Windows:

> set NODE_DEBUG=http
> newman run  <newman options>
DivyaKalyanakrishnan commented 8 years ago

@czardoz : I get the same error still. complete snapshot attached. errorsnapshot2

shamasis commented 8 years ago

If it helps: from the report it seems that the request itself has errored out (error 1). Error 2 is simply a side effect of that. I did an initial googling of the error "invalid protocol". Seems like this usually happens if there's an issue with proxy settings. Is that machine of yours using proxy?

rapidroamer commented 8 years ago

I too had a similar issue, with only a high level information..

My case

POST http://myendpoint [errored] 2⠄ ReferenceError in test-script

And reporter failed with below message. /postman/node_modules/newman/node_modules/pretty-ms/index.js:8 throw new TypeError('Expected a finite number');

After analysis: It turned out I had set a --requestTimeout value and my url didn't respond by that time.. Instead of ReferenceError in test-script it should have been Timeout error..

It look few hours to find out my issue was related to timeout..

Your case

Invalid Protocol seems to be more valid error with which you can debug your case..

Kriz1881 commented 8 years ago

We are facing the same issue as the reporter of the issue. Here are the details of our case: We have a collection of 20+ HTTP (not httpS) requests with a few tests for each one of them. From time to time we get the error reported here, but only on the first request in the collection.

We have isolated that request in a separate collection and we executed it separately during different times of the day for a few days.

We re-encountered the issue again - 3 times with the ETIMEDOUT Socket Error:

\HTTP 8568: SOCKET ERROR: connect ETIMEDOUT ((server IP)):((port)) Error: connect ETIMEDOUT at Object.exports._errnoException (util.js:907:11) at exports._exceptionWithHostPort (util.js:930:20) at TCPConnectWrap.afterConnect as oncomplete [errored] HTTP 8568: CLIENT socket onClose HTTP 8568: removeSocket ((server IP)):((port)): destroyed: true HTTP 8568: HTTP socket close 2? ReferenceError in test-script

The last time, however, we got an ECONNRESET socket error:

/HTTP 2672: SOCKET ERROR: read ECONNRESET Error: read ECONNRESET at exports._errnoException (util.js:907:11) at TCP.onread (net.js:557:26) [errored] HTTP 2672: CLIENT socket onClose HTTP 2672: removeSocket ((server IP)):((port)): destroyed: true HTTP 2672: HTTP socket close 2? ReferenceError in test-script

I am attaching the full debug logs from each occurrence. In all of them we are using a request timeout of 1 minute, but as you can see, the errors appear after ~30 seconds.

Newman version: 3.1.2 Postman version: 4.7.2 (Windows app) NodeJS version(s):

{ http_parser: '2.7.0',
  node: '4.6.0',
  v8: '4.5.103.37',
  uv: '1.9.1',
  zlib: '1.2.8',
  ares: '1.10.1-DEV',
  icu: '56.1',
  modules: '46',
  openssl: '1.0.2j' } 

Client machine OS: Windows 7 SP1, 64bit Server machine OS: Windows Server 2012 R2, 64bit

PS: We have tokenized the server IP, port and URL path in the logs for confidentiality reasons

newman-debug-log-Reference-error-in-test-script-ECONNRESET.txt newman-debug-log-Reference-error-in-test-script-3-ETIMEDOUT.txt newman-debug-log-Reference-error-in-test-script-2-ETIMEDOUT.txt newman-debug-log-Reference-error-in-test-script-1-ETIMEDOUT.txt

shamasis commented 8 years ago

@Kriz1881 could you open a new issue? The original issue has been addressed here. Would help to keep better track of things.

sudharsan81 commented 7 years ago

If you wish Disables SSL validations, please use "-k" option like this:

newman run your_collections.json -k