validate 400 and 500 statuscode

183 views
Skip to first unread message

Jogindra Chhantyal

unread,
Nov 10, 2021, 4:08:48 PM11/10/21
to robotframework-users
Is there anyway to validate 400 and 500 status code using get on session on webservice testing. It can be validate using Get request , but give depreciation warning in each test cases.

Craig Despeaux

unread,
Nov 10, 2021, 6:17:28 PM11/10/21
to robotframework-users
Absolutely.  Get On Session supports an expected_status parameter.  If you set that to any, you can execute the request and then validate the status code and the json response afterwards.  Without expected_status=any the test will fail on the Get On Session call if a 400 or 500 is returned.  

Craig



Jogindra Chhantyal

unread,
Nov 12, 2021, 6:01:40 PM11/12/21
to robotframework-users
Thank you, it helps a lot and save my time. 

vedashree paranjape

unread,
Dec 1, 2022, 8:12:28 AM12/1/22
to robotframework-users
With this method the status code can be validated but unable to access the body of the response. The GET request's response body is logged in the INFO in the log file, but when trying to fetch ${response.json()} it throws error as  "Resolving variable '${response.content}' failed: AttributeError: 'tuple' object has no attribute 'content'". But same  ${response.json()} returns the body when the GET request has 200 status code.
Please suggest a method to access the body of the GET request with 400 response.

~Vedashree

Craig Despeaux

unread,
Dec 1, 2022, 10:20:41 AM12/1/22
to vedash...@gmail.com, robotframework-users
You can pass expected_status=any and then evaluate the status code yourself with ${resp.status_code}.

Craig

--
You received this message because you are subscribed to a topic in the Google Groups "robotframework-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/robotframework-users/TwtVXMSa2C4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to robotframework-u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/robotframework-users/8e00b62f-2eb6-4a3b-bdc9-b95566fa510fn%40googlegroups.com.

vedashree

unread,
Dec 1, 2022, 10:50:39 AM12/1/22
to robotframework-users
@Craig, I dont need to evaluate the status code but I want the body of the response. 
I am able to get the body with ${response.json()} when the status code is 200 but when the status code is 400  i am not able to get the body of the response. Need help fetching the body of response.

~Vedashree

Craig Despeaux

unread,
Dec 1, 2022, 11:25:08 AM12/1/22
to vedash...@gmail.com, robotframework-users
I'm guess I'm not sure what the problem is.  Maybe I need to see what you're doing specifically and what happens or what the error is.   I assume you see the response when you run this request from Postman or curl.

Craig

Reply all
Reply to author
Forward
0 new messages