status_code is only ever 200 - OK.
See original GitHub issueIssue Description
See attached testcase.
A status_code of 200 seems to be hard-coded since this commit?
https://github.com/cobrateam/splinter/commit/d151c565c1068c6f0ac3f09ff010353b9b1a9de2
import splinter
with splinter.Browser('firefox') as browser:
# should be 200
browser.visit('http://google.com')
print(browser.status_code.code)
print(browser.status_code.is_success())
browser.visit('http://google.com/is_this_a_bug')
print(browser.status_code.code)
print(browser.status_code.is_success())
browser.visit('http://github.com/is_this_a_bug/is_this_a_bug_project')
print(browser.status_code.code)
print(browser.status_code.is_success())
browser.visit('http://this_domain_doesnt_even_exist.coma')
print(browser.status_code.code)
print(browser.status_code.is_success())
Gives this output:
$ python ./testcase.py
200
True
200
True
200
True
200
True
This should be returning 404 for all but the 1st example.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:2
- Comments:15 (8 by maintainers)
Top Results From Across the Web
200 OK - HTTP - MDN Web Docs
The HTTP 200 OK success status response code indicates that the request has succeeded. A 200 response is cacheable by default.
Read more >Returning http 200 OK with error within response body
HTTP 200 means transmission is OK on the HTTP level (i.e request ... But all errors which are covered by HTTP error codes...
Read more >HTTP Status 200 (OK) - REST
The HTTP Status 200 (OK) status code indicates that the request has been processed successfully on the server. The response payload depends ...
Read more >Empty list, HTTP status code 200 vs 204 vs 404 - API Handyman
While 200 OK being a valid and the most common answer, returning a 204 No Content could make sense as there is absolutely...
Read more >200 OK - HTTP Status Code Glossary - WebFX
HTTP Status Code 200: The request has succeeded.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Someone mentioned this bug to me and I was puzzled as to why I hadn’t noticed it myself, and then realised it was because of the way I had structured my test cases: all my status code tests just use plain requests calls, without invoking splinter at all. I then only use splinter for interaction tests in the 200 OK case.
So +1 from me for having
status_code
raiseNotImplementedError("Selenium WebDriver does not report HTTP status codes")
(or some other appropriate message) in cases where the driver can’t set it reliably.Multiple requests is difficult,
POST
requests are likely to not be idempotent, eg. the status code of aPOST /create/user/jamesbond/
request the second time is very likely to be different to the first request. Even multipleGET
requests could have effects so duplicating them probably does more harm than good.Leave duplicated requests up to the application developer.
If there really isn’t a reliable way of getting the status code from the main request, I think
NotImplementedError
is the only sensible solution.