I have a cucumber project in Ruby using Selenium Webdriver and Chromedriver and I would like to know if a page I access is up or in maintenance. To do this, I would like to access the response-headers of the HTTP Get request.

Is there a way to do this?

  • Selenium is not best suited to verify HTTP response headers or, in general, to work on HTTP protocol level. I have no expertise in Ruby, but quick search in Google returned two Ruby HTTP clients, gem and Net::HTTP. Here's a way to check response status with the latter: stackoverflow.com/questions/12023231/… – dzieciou May 26 '15 at 17:04
  • Thanks for your answer. Yes, Selenium is not suited to do this. Anyways, I have all my other tests made in Selenium and I wanted to know if there was an error on the requested page (like, the page is under maintenance and there's a redirect) at the beginning of each scenario, and I was hoping I could use Selenium. :) – Tiago May 26 '15 at 17:31
  • You can mix Selenium tests with tests using other technologies. If you really want to use only Selenium, you could verify pages for custom error descriptions or page title: that's the thing you're able to get from HTML document. But they always will be custom to the specific page or app, in contrast to HTTP protocol. – dzieciou May 26 '15 at 17:45

It may be easier to just openAndWait() the URL and do some conditional logic to see if the page displays a maintenance message or not. Incorporating a proxy (as mentioned in other responses) for this one use case sounds like a rather expensive operation.

In the past I have setup a proxy to ensure that a tracking pixel (Google Analytics or Omniture, for example) fires and it's values are asserted. For that I have used the Fiddler core, but not in combination with Selenium (I was using Telerik Test Studio which has it built in).

|improve this answer|||||

As mentioned, Webdriver explicitly decided not to include the ability to inspect HTTP traffic in their project. The recommended technique is to use a proxy to capture the browser traffic by specifying the proxy address in your desired capabilities. Then, you can inspect traffic from the proxy. A common proxy is Browsermob Proxy - it was forked from Selenium years ago, and it has a ruby gem that allows you to inspect & modify requests and responses, including response headers.

But, for your purpose it does sound like it may be enough to check it with a ruby HTTP client instead.

|improve this answer|||||

Your Answer

