4

I'm trying to set up a test where I make a POST request but getting a 500 Server Error​ (Response Body that I'm seeing is Unexpected 'T' [JSON]; Tests reporting "There was an error in evaluating the test script: SyntaxError: Unexpected token T in JSON at position 0") and so Tests should show Failed for all 5 of my tests. What can i do?

One of my tests isn't even run it looks like: tests["Status code is 201 Created"] = responseCode.code === 201;

Thanks in advance for your help. Tien.

Tien
  • 159
  • 1
  • 3
  • 10
  • Can you post the actual response received from the server i.e the headers and the raw response? – Pratik Mandrekar Apr 12 '17 at 06:04
  • here you go, @PratikMandrekar: Raw response Body: "Internal Server Error", Headers: APPDYNAMICS_GUID →e87746c4-6e6c-4615-9eb9-5582af5c17d5 Connection →close Content-Length →21 Date →Wed, 12 Apr 2017 23:18:41 GMT Violation →Violation-Internal X-API-Handshake → X-RateLimit-Limit →1000 X-RateLimit-Remaining →1000 X-RateLimit-Reset →0 – Tien Apr 12 '17 at 23:42

2 Answers2

3

You can check that HTTP code is not 500 with following:

tests["Status code is not 500"] = responseCode.code != 500;

Is this what you're looking for?

grinderX19
  • 564
  • 5
  • 13
  • thank you @grinderX19 very much for your prompt assistance. Unfortunately, that didn't work either. I'm seeing the following for Body: Pretty Text: Internal Server Error Pretty JSON: Unexpected 'I' When I click on the Tests tab from the Response section, I'm seeing "There was an error in evaluating the test script: SyntaxError: Unexpected token I in JSON at position 0" Btw, development now supported a scenario that failed earlier resulting in Unexpected 'T' [JSON] as I mentioned in the question title so I had to induce 500 response again by mucking with the request payload. – Tien Apr 12 '17 at 23:26
  • 1
    This!! How do you know this "responseCode" variable exists? I have been trying to find a list of this postman "default variables" and I cant find them. – Dzyann May 21 '20 at 19:39
  • I've found it in Postman's [Test examples](https://learning.postman.com/docs/postman/scripts/test-examples/) (also can be seen in the Postman app, Tests tab, Snippets sidebar). – grinderX19 May 25 '20 at 06:59
1

Error 500 means either you are sending some invalid JSON in your request body or some issue with your server. Could tell more by looking at the request and response body.

Do you have your test under any if condition? I don't any reason why the test didn't run except if you have any syntax error in test section.

Dinesh Kumar
  • 1,694
  • 15
  • 22
  • thank you @Pandit81 very much ... I was sending a serial number for a serialnumber key that development wasn't supporting yet till today. I would think their API would return a Bad Request instead ... Now, I'm tricking the API with another bad request I think by sending i.e. "key1": "a" instead of an integer and getting another 500. I tried responseCode.code != 500 test but it didn't run this test either. Body: Pretty Text: Internal Server Error Pretty JSON: Unexpected 'I'... – Tien Apr 12 '17 at 23:41
  • (continued) When I click on the Tests tab from the Response section, I'm seeing "There was an error in evaluating the test script: SyntaxError: Unexpected token I in JSON at position 0". – Tien Apr 12 '17 at 23:41