HttpWatch Automation Reference - Version 11.x
Using HttpWatch Automation with C# / C# - Recording with HttpWatch
In This Topic
    C# - Recording with HttpWatch
    In This Topic

    First, your application needs to embed the HttpWatch plug-in within an instance of Internet Explorer, as explained in the C# - Overview topic. Having done this, your application will contain references to Controller and Plugin objects.

    The following discussion assumes that these object references are called control and plug-in, respectively.

    Filter Control

    Before starting recording, you should decide whether to enable or disable HttpWatch filtering. The automation interface only allows you to enable or disable an existing filter. The filtering criteria itself can only be set up manually through the HttpWatch plug-in user interface.

    If you do not want specifically to use a filter it is best to disable filtering in your application, as follows:

     

    Turn Off Filtering
    Copy Code
    plugin.Log.EnableFilter(false);
    

     

    Alternatively to enable filtering, make the same call, but with the parameter set to  true.

    Clearing the HttpWatch Log and the Browser Cache

    To make sure that you don't pick up traffic that was previously recorded in HttpWatch by user or another automation program you should clear the Log object that is associate with the Plugin. This can be done with the Plugin object's Clear method:

     

    Clear the HttpWatch Log
    Copy Code
    plugin.Clear();
    

     

    It may also be necessary to put the browser into a known state at the start of your test. Often this is achieved by clearing the browser cache and cookie database to emulate the state of the browser when a new visitor opens a web page. The plug-in object provides two methods, ClearCache and ClearAllCookies to perform these tasks.

    Starting Recording

    To activate traffic logging call the Plugin object's Record method:

     

    Start Recording
    Copy Code
    plugin.Record();
    

    Generating HTTP Traffic to Record

    Of course, nothing will be recorded by HttpWatch until the browser starts to access and interact with web pages.

    In an automation program there are three ways to drive the browser:

    1. Drive the browser directly using it's own programmatic interface, e.g. with Internet Explorer you can use the IWebBrowser2 interface to navigate to any web page
    2. Use a framework that has been designed to drive browser interactions, e.g. Watir with Ruby or WatiN for .Net
    3. Use the Plugin object's GotoURL method

    Option 3) doesn't is not as powerful or flexible as the other two alternatives but it provides a simple way to test that pages load correctly and to measure their performance.

    The GotoURL methods returns immediate without waiting for the page to load. Normally, you would want to wait for the page to load so that you could look at the traffic that it generated or the performance timings gathered by HttpWatch. The way to do this is to call the Controller object's Wait methods passing the Plugin object reference and a timeout value in seconds (-1 is used to wait forever):

     

    Loading a Page using HttpWatch
    Copy Code
    string myUrl = http://www.example.com;
    plugin.GotoUrl( myUrl );
    control.Wait( plugin, -1 /* don't return until the page loads */ );
    

     

    For more information about how the page load is detected please see the documentation for the IsLoadingPage property and the Wait method.

    Stopping Recording

    When you wish to stop recording HTTP traffic call the Plugin object's Stop method:

    Closing the Browser

    At the end of your application, or earlier, if appropriate, you should close the browser, by calling the Plugin object's CloseBrowser method:

     

    See Also