Home > Agile, C#, Performance Testing, Test Automation > HttpWatch Automation using C# and NUnit

HttpWatch Automation using C# and NUnit

In web application development, web pages require the use of multiple HTTP requests to download HTML, graphics and JavaScript. I came across a tool named HttpWatch that shows what HTTP traffic is triggered when a webpage is accessed. This tool integrates with Internet Explorer and Firefox browsers.  I used to run my tests using this tool manually for every iterations of my testing.

In Agile, the number of test increases with the story points and this indeed increased my test efforts for upcoming iterations. So, I felt that there is a need for automation. This tool supports test automation using C# and Ruby. As I was working on a .Net project, I had to use C# as a programming language for setting up the automation framework.


  • Microsoft Visual Studio 2010 as IDE
  • NUnit as Unit Testing Tool
  • HttpWatch Installed


Referencing the HttpWatch Automation Library:
  • Create a new Project with C# Class Library and save it (‘HttpWatchPerformance’ my example).
  • Rename the class as DriverScript.cs.
  • In Visual Studio, Go to the Project -> Add Reference menu item.
  • When the Add Reference dialog appears, click on the COM tab. Find the ‘HttpWatch Automation Library’ in the list and select it as shown in the figure:
Referencing the NUnit Library:
  • Download the latest NUnit framework from the site: http://www.nunit.org
  • Install the NUnit software on your machine.
  • In Visual Studio, Go to the Project -> Add Reference menu item.
  • When the Add Reference dialog appears, click on ‘Browse’ and navigate to C:\Program Files (x86)\NUnit 2.5.10\bin\net-2.0\framework and select nunit.framework.dll.
  • Finally, the solution Explorer should look like this:

Now, it’s the time to write tests. Let me explain with a sample test scenario:

As an end user,
I would like to visit the google home page 
And then I would like to click on the 'Sign in' button
so that I can login to Google account


  • Define the browser on which the tests needs to be executed in [TestFixtureSetUp] attribute.
  • In the [Test] attribute, clear the log for deleting the old test results and then start recording.
  • In the [Test] attribute, pass the URLs of ‘Google home page’ and ‘ Google Sign In page’ using the 2 variables myURL1 and myURL2 respectively.
  • Specify the location for saving the HttpWatch log file.
  • Refer the APIs available for HttpWatch by visiting the URL link: http://apihelp.httpwatch.com/#Automation Overview.html


  • Copy and paste the code snippet below into your Visual Studio 2010.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit;
using NUnit.Framework;
using HttpWatch;
using SHDocVw;

namespace HttpWatchPerformance

 public class PerformanceTests
  private HttpWatch.Controller controller;
  private HttpWatch.Plugin plugin;

  public void Setup()
  controller = new HttpWatch.Controller();
  //Creating the HttpWatch plug-in for IE
  plugin = controller.IE.New();
  //Creating the HttpWatch plug-in for Firefox
  //plugin = controller.Firefox.New("");

  public void init()

  public void Test1()
  //Turn Off filtering

  //Clear the HttpWatch Log

  //Start Recording

  //Loading a Page using HttpWatch
  string myURL1 = "http://www.google.com.au/";
  //Validate that Step 1 is executed
  Console.WriteLine("Step 1 executed");
  //Don't return until the page loads
  string myURL2 = "https://accounts.google.com/ServiceLogin?hl=en&continue=http://www.google.com.au/";
  //Validate that Step 2 is executed
  Console.WriteLine("Step 2 executed");
  //Don't return until the page loads
  controller.Wait(plugin, -1);
  //Save an HttpWatch Log (.hwl) file
Running the tests using NUnit:
  • In Visual Studio, Go to Projects -> Project Properties (‘HttpWatchPerformance Properties’ in my example).
  • Click on the ‘Debug’ tab.
  • Set the ‘Start external program’ to the location of NUnit exe file (C:\Program Files (x86)\NUnit 2.5.10\bin\net-2.0\nunit-x86.exe) as shown in the snapshot below.
  • Build the solution, Go to ‘Build -> Build Solution’ (hit the F6 key) in Visual Studio.
  • Execute the test, Go to ‘Debug -> Start Debugging’ (hit the F5 key) in Visual Studio. Visual Studio invokes the NUnit application.
  • In NUnit, click on ‘File -> Open Project’ and choose the location of the HttpWatchPerformance.dll file.
  • In NUnit, click on the ‘Run’ button to run the tests. Test will be executed and the results will be saved in the log file, Test1.hwl in the specified location. Refer the log file for the test results as shown in the snapshot below:
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: