Using HttpWatch with Watir
HttpWatch is a great add-on tool to Internet Explorer that captures your IE HTTP traffic. The best part for me is that it can be driven programaticly from my Watir Tests. The company Simtec has an example of how to do it on their website. So I would recommend you install HttpWatch and run the example for yourself first or just follow along for some other way of looking at the tool.
The complete API documentation is available as a chm file you get with installation, I hope they’ll put it as html online rather than chm so you can google it and link to it.
Here are some of my notes when I investigated the tool for my projects. - It works for me out of the box. (I also use Fiddler2, another great HTTP sniffer). HttpWatch fills my immediate need for Http traffic data which IE natively does not provide and a nice color coding logger makes for a sugar candy for managment and testers alike.
For some of you in the dark about how to use it (I was in the dark when I first encountered the tool) here are some notes and how I understand the usage of the tool so far. (check out the mindmap too. I will update soon.)
So let’s begin investigation. it’s best to run everything from IRB (or just jump to watir-console, see
C:\ruby\lib\ruby\gems\1.8\gems\watir-1.5.3\bin\watir-console)
Open IRB and type some infrastructure code:
require 'watir' # watir requires 'win32ole'
ct = WIN32OLE.new('HttpWatch.Controller')
ie = Watir::IE.new
httpw = ct.Attach(ie.ie)
We just created Controller, then IE instance and made a plugin object httpw by attaching our ie.ie object. In Watir IE class maintains an OLE ie object. This is the object use and not the actual IE from Watir, that’s why to confuse you further we used the same name ie for our main IE object.
Now that you may be confused enough we’ll just plunge in more to see what else we can do.
So far I got a blank IE sitting on the desktop (I am using WinXP and IE6x) and an IRB session open.
Let’s start the Recorder (after clearing the Log)
httpw.Clear
httpw.Record
# generate traffic with watir
ie.goto('http://google.com/')
ie.goto('http://yahoo.com/')
ie.goto('http://blablablaichbinnichtda.com')
ie.goto('http://marekj.com/iwasneverhier.html')
For traffic I just visited two sites I know exist and two pages that do not exist to Log errors.
Now you can stop the recording and save your logs (in case you close IE or crash)
httpw.Stop
httpw.Log.Save('temp.hwl')
Let’s do some fact finding about the http sessions.
#How long did all of this take? httpw.Log.Entries.Summary.Time
Careful: this is the Time it took from the start to the end of the session including all the waiting around and staring at the page, it’s not a true time in how long it took for all the traffic to arrive.
# How many pages did I visit? httpw.Log.Pages.Count #Were there any errors? httpw.Log.Entries.Summary.Errors.Count
For more information just take a look at the API documentation.
The HttpWatch Basic Edition allows you to save as well as load a log file and examine the Entries. That’s very useful. I can log, stop and offload my hwl file for later review or quick audit.
Here is an example of how to create an instance of a log object by loading previously saved log file using Controller.
# load previously saves httpwatch log file
log = ct.OpenLog('temp.hwl')
NBw you can use standalone log object as if it was httpw.Log
I like this feature for gathering statistics on a previously saved test sessions.
That’s about it for the first look.(mindmap to come)
Add New Comment
Thanks. Your comment is awaiting approval by a moderator.
Do you already have an account? Log in and claim this comment.
Add New Comment