HttpWatch is a powerful web analytics tool that captures HTTP and HTTPS data without changing browser and network settings. View the underlying HTTP data, including headers, cookies, caches, etc., while counting the time of sending and receiving requests and providing a complete logging system. At the same time, the tool has a complete COM interface for users to manipulate HttpWatch programmatically.
HttpWatch Automation Object Description:
Controller class: Always the starting point of control, it is used to create HttpWatch plug-in interface or read log file, through the IE properties and Firefox properties of the new () method or the Attach () method to return the plugin instance object.
Plugin class: Is the interface that HttpWatch interacts with the browser. Provides methods for starting and stopping HTTP traffic records, as well as many methods and properties to manage HttpWatch log files and configuration Automation records.
Log class: The Log property of the plugin object is the entry for the log object. Contains a series of logs that are recorded through HttpWatch. The log object has many important classes, such as pages, the entries class.
Entry class: Each Log object contains a set of Entry objects that represent the details of a single HTTP transaction (such as an HTTP request)
Automated testing through the combination of Watin and HttpWatch can greatly extend the scope of automated testing, such as verifying link connectivity during automated testing, page transfer rates and time, viewing Web page details, and more.
C # Operation HttpWatch
- Add the HttpWatch Automation class library to the project
- Create a link to the HttpWatch tool
Create a new IE interface: Top add reference using HttpWatch;
1 New Controller (); 2 Plugin Plugin = control. Fea New ();
View Code
To create a new Firefox interface:
1 New Controller (); 2 Plugin Plugin = control. Firefox.new ();
View Code
Attach an existing IE window:
1 New shdocvw.internetexplorer (); 2 true; // Required to see new window 3 New Controller (); 4 Plugin Plugin = control. Ie. Attach (Iebrowser);
View Code
Attach a Firefox window that already exists:
1 New Controller (); 2 Plugin Plugin = control. Firefox.attach (Firefoxbrowser);
View Code
3. Read HTTP details via interface
Example:
1 Public StaticHttpwatchinfo Runhttpwatch (stringURL)2 {3Controller control =NewController ();4Plugin Plugin =control. Fea New ();5 6Plugin. Log.enablefilter (false);7 plugin. Record ();8 plugin. Gotourl (URL);9Control. Wait (Plugin,-1);Ten plugin. Stop (); One AHttpwatchinfo httpwatchsummary =Newhttpwatchinfo (); - if(plugin. Log.Pages.Count! =0) - { theSummary Summary = plugin. log.pages[0]. Entries.summary; -Httpwatchsummary.url =URL; -Httpwatchsummary.time =Summary. Time; -Httpwatchsummary.roundtrips =Summary. roundtrips; +httpwatchsummary.bytesreceived =Summary. bytesreceived; -Httpwatchsummary.bytessent =Summary. BytesSent; +Httpwatchsummary.compressionsavedbytes =summary.compressionsavedbytes; A atilist<string> codes =Newlist<string>(); - for(inti =0; I < summary. Statuscodes.count; i++) - codes. ADD (summary. Statuscodes[i]. Result); -Httpwatchsummary.statuscode =codes; - -IlistNewList(); in for(inti =0; I < plugin. Log.Entries.Count; i++) - { toHttpwatchdetail detail =NewHttpwatchdetail (); +Detail. URL =plugin. Log.entries[i]. URL; -Detail. Result =plugin. Log.entries[i]. Result; theDetail. Time =plugin. Log.entries[i]. Time.tostring (); *Detail. Error =plugin. Log.entries[i]. Error; $ TryPanax Notoginseng { -Detail. Content =plugin. Log.entries[i]. Content.data; the } + Catch A { theDetail. Content =NULL; + } - httpwatchdetail.add (detail); $ } $Httpwatchsummary.details =Httpwatchdetail; - } - plugin. CloseBrowser (); the returnhttpwatchsummary; -}
View Code
Introduction to Watin and HttpWatch interactions