how do i fail a test if postman response status code is 500 server error? - post

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.

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?

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.

Related

ExactOnline: Token is not allowed, because of invalid or empty chainId

We have a java application that connects to ExactOnline for performing the operations.
The connection works fine for almost 9days and then it will start complaining about the below exception:
"Request from start.exactonline.nl returned an error (response code: 400, response: { "error":"invalid_grant","error_description":"Token is not allowed, because of invalid or empty chainId"
After encountering this error we have to force re-authorize the application by the user to get the new accessToken.
Now I am getting the below error as well:
"Request to token endpoint https://start.exactonline.nl/api/oauth2/token"
Any help would be appreciated.
The error message it's background and the solutions are explained at https://forums.invantive.com/t/exact-online-error-token-is-not-allowed-because-of-invalid-or-empty-chainid-on-exact-online/2226

API Negatif Scenario with Rest-Assured and Junit

I want to make an API negative test scenario with Rest-Assured Library. I'm creating a get request for a data that doesn't exist. When I print this response to the console, I want to see the text 'not found' Because postman says this is the request body. But my test failed on get method. I am getting that error
io.restassured.internal.http.HttpResponseException: status code: 404, reason phrase: Not Found
Actually I know the status code is 404. But I can not test about it. How can i write that negative scenario
Response response = given().
when().
get("https://restful-booker.herokuapp.com/booking/1001");

What's the right HTTP error code if parsing the request fails

If you create a web service which receives an processes some data like XML/JSON and the parsing of the data fails because it's incorrect, what do you do?
Send a HTTP 400 error code: After all it was the client who messed up the data (XML/JSON)
Send a HTTP 500 error code: It's the server who wasn't able to complete its task
If data in the request is malformed, then you'll want to return a 400 level error. Generally 500-level errors mean that something is wrong on the server that has nothing to do with the client or the client's request.
422 code.
422 Unprocessable Entity
The 422 (Unprocessable Entity) status code means the server
understands the content type of the request entity (hence a
415(Unsupported Media Type) status code is inappropriate), and the
syntax of the request entity is correct (thus a 400 (Bad Request)
status code is inappropriate) but was unable to process the contained
instructions. For example, this error condition may occur if an XML
request body contains well-formed (i.e., syntactically correct), but
semantically erroneous, XML instructions
https://www.rfc-editor.org/rfc/rfc4918#section-11

405 Method not allowed on Net::HTTP request [ruby on rails]

I'm trying to verify if there is a remote url with following code:
endpoint_uri = URI.parse(#endpoint.url)
endpoint_http = Net::HTTP.new(endpoint_uri.host, endpoint_uri.port)
endpoint_request = Net::HTTP::Head.new(endpoint_uri.request_uri)
endpoint_response = endpoint_http.request(endpoint_request)
I'm still getting 405 Method not allowed. When I use Get instead Head in Net::HTTP::Head.new I'm getting 200 Success but also with whole remote document in response what results in bigger response time (0.3s => 0.9s).
Any ideas why this is happening? Thx
There's a chance that the #endpoint url you're trying to interact with doesn't support HEAD requests (which would be really weird, but still may be the case). Your code works fine for me with a handful of urls (google.com, stackoverflow.com, etc.)
Have you tried a curl request to see what it returns?
curl -I http://www.the_website_you_want_to_test.com

Adobe Flex 3 : Fault Event doesnt return XML Feed sent from Server

I am working on a flex application which communicates with a Rails backened.
When i request for some data, It sends back xml feed.
In some cases, if given parameters are not valid, then rails return an error feed with status code = 422 as following
email is wrong
But I dont get this feed in FaultEvent of Flex, How could i read error feed?
Thanks
Are you getting the result in ResultEvent in such cases? I am not sure for what all HTTP error codes FaultEvent will get invoke(I know only it goes for 404 and 500). May be its still going to ResultEvent as a valid result!
You can use HTTPService instead of URLLoader.
Flex HTTP results will not include the actual underlying HTTP response codes. It just doesn't work. (TM)

Resources