So I'm using Watir WebDriver with both Firefox and Chrome. Chrome is much faster but seems to have a number of eccentricities. First, in Firefox when I use something like:
ff.link(:text, "Click Here").exists?
It works fine. However, in Chrome it often seems to stall and then exit with a timeout exception. So what I've had to do is narrow the search in Chrome like this:
linkDiv = ch.div(:class, "mydiv")
linkDiv.link(:text, "Click Here").exists?
Typically this type of page reduction down to just the div tag of interest works just fine.
However, there is one other eccentricity I've noticed in Chrome that I haven't noticed in Firefox. In Chrome, I occasionally get an Error 15 - something like no response on socket but since it is intermittent I can't reproduce the error at will and haven't copied the exact text down yet. I haven't seen this in Firefox - at least not yet - but perhaps Chrome is giving me an error where Firefox hides it.
So I'd liked to be able to log when this error occurs and the best idea I've had so far is to use HTTP Codes - i.e. 200, 404, 500, etc. If the code is not 200 then record the code and try again.
Is there a way in Watir to get the HTTP code? Having come to Ruby from PHP/CURL I assumed there would be an easy way to get the HTTP code - something like browser.http_code
(where browser = Watir::Browser.new :chrome, browser.goto(...)) but I haven't found it yet and I haven't had any luck finding a way online. The "solutions" I've found so far all entail other gems making a call to the page to get the returned code. However, since these pages work fine 10 times or more for every time I get this error making another call with another gem doesn't help.
Thanks
My workaround...
The title of the intermittent page with nothing on it includes "is not available" at the end of the browser.title
string. So I use a browser.title.include? "is not available"
check to see if the page never loaded.
This is less than ideal for a lot of reasons like that title may change from site to site or may change when Chrome gets upgraded. Where as a status code of 200 will always tell my code there is a problem...
I guess it's something to suggest to the developers.
Thanks again