views:

3070

answers:

6

Is it possible? I'm looking around the Selenium docs and don't see any straightforward way to do it.

All help appreciated!

A: 

What I did to handle this using Selenium (not Selenium RC) was to convert the HTML tests into JSP and then utilize Java where needed to read headers or do whatever stuff that JavaScript (selenium is just Javascript) couldn't do.

Perhaps you could give a few details about how you plan to use Selenium?

Eric Wendelin
I am using the Ruby driver for Selenium RC. I'm not sure I follow what you mean about converting the HTML tests into JSP. The site I'm testing is written in .Net, though I can't imagine that'd make a difference in the approach.So there's a way to intercept the headers is what you're saying?
globulus
+1  A: 

I would not use Selenium for this type of test and suggest that you solve a variety of testing issues with different tools. what we do is:

  • Use unit tests to test code: methods and classes

  • Integration tests to test how application components hang together

  • A Simple functional test framework like Canoo WebTest (or some equivalent) to assert things like Http cache headers, basic page structure, simple redirection and cookie setting / values

  • Bespoke tests to ensure validity of pages to W3C standards

  • JSunit to test Javascript classes and methods we created

  • Selenium to test UI functionality/behaviour and the integration of Javascript into those pages

Its worth spending time breaking out the responsibility of testing different aspects of the system using these different tools since using only Selenium can cause issues:

  • The bigger the suite, the slower they run. Indeed Selenium is inherently slower compared to the other tools mentioned
  • It handles behaviour/functional testing well but nevertheless XPaths can be brittle and may require increasing amounts of time and effort to maintain
  • Usually requires you setup 'as-if-real-life' data with your app to step through user scenarios (which can be messy and take a lot of time)

There are also some techniques - which you may or may not have come across - which you can use to make your Selenium tests more resilient.

j pimmel
+5  A: 

I've answered this question a couple times on StackOverflow. Search my previous answers to dig it up. The key that you have to write some custom Java code that extends ProxyHandler and SeleniumServer. You also need to use a release AFTER 1.0 beta 2.

As to the people who ask why you'd want to do this: there are a lot of reasons. In my case, we're testing an AJAX heavy app and when things go wrong, one of the first things we debug is the network wire. That helps us see if the AJAX call happened and, if so, what the response was. We're actually automated the collection of this info and capture it (along with a screenshot) with every Selenium test.

Patrick Lightbody
I'm marking this answer as the one I like since it actually solves my problem. :)We have reasons for wanting to inspect headers as well. I agree with the above posts, but it is very useful for us to get at the headers.
globulus
Well since it's Mr. Selenium himself, can't argue ;). I knew you could also extend the Java classes in the server.
Eric Wendelin
I've searched through your answers and can't seem to find the one you refer to. Which answer was it? Do you have some examples of extending those two Java classes?
nzpcmad
@nzpcmad Sorry it wasn't clear. Things have changed a bit with the plans for Selenium + inspecting HTTP traffic. Pretty much we're all focussing now on using one of the too open source tools my company, BrowserMob, has built. Check out http://browsermob.com/tools to learn more about browsermob-proxy (good for Se 1 + all browsers) and browsermob-page-perf (good for Se 2 + Firefox - uses Firebug). Good luck!
Patrick Lightbody
+1  A: 

captureNetworkTraffic() API in DefaultSelenium captures http request/response headers and you can access them in html/xml/plain format.

Here is sample code:

Selenium s = new DefaultSelenium(...);
s.start("captureNetworkTraffic=true");
s.open("http://www.google.com");
String xml = s.captureNetworkTraffic("xml"); // html, plain
s.stop();
+1  A: 

It seems to me that it can be very useful to test HTTP response headers from selenium. Not in 100% of the cases, perhaps ... but there certainly are some. If you are checking out a sequence of pages, it seems like it would be useful to test some response headers as part of that testing (Content-Type and Pragma leap to mind).

Gary
A: 

but response for every request made is not captured .assume i have clicked the link and done some thing .only .css,.gif & referel url shown. am i missing something

sasikumar