HttpWatch Automation Reference - Version 11.x
Using HttpWatch Automation with Ruby / Ruby - Overview
In This Topic
    Ruby - Overview
    In This Topic

    Prerequisites

    You can install the Ruby language runtime using the installer at http://rubyinstaller.org/ .

    Accessing HttpWatch from Ruby

    The HttpWatch automation library is packaged as a COM component. To access it from Ruby you will need to use WIN32OLE::new from the win32ole library. It can be referenced by adding the following require statement to your Ruby source file:

    Using the WIN32OLE library
    Copy Code
    require 'win32ole'
    

    Communicating with the HttpWatch Plug-In

    You can only directly create an instance of one class in the library - the Controller class.

    All communication with the HttpWatch plug-in stems from this class, so the first step is to create an instance of it:

     

    Creating the Controller
    Copy Code
    # Controller is the only creatable class in the HttpWatch automation interface
    
    controller = WIN32OLE.new('HttpWatch.Controller')
    

     

    Having created a Controller object, the next step is to create an instance of the plug-in and attach it to a browser instance. The exact code depends on whether you are using Internet Explorer or Google Chrome, but the principles are the same in either case. The Controller object has a property named IE. This property returns a reference to the IE object.

    The IE objects offer two methods, New and Attach. The New method creates a new instance of the IE browser with an HttpWatch plug-in embedded within it. Attach allows the user to create an HttpWatch plug-in and embed it in a browser instance that has already been created by some other component. Both methods return a reference to the Plugin object that represents the HttpWatch plug-in.

    The following code creates a new instance of Internet Explorer with an embedded HttpWatch plug-in component:

    Creating the HttpWatch plug-in for IE
    Copy Code
    controller = WIN32OLE.new('HttpWatch.Controller')
    
    plugin = controller.IE.New()
    


    Instances of Internet Explorer are referenced through the IE IWebBrowser2 interface, so the IE object's version of the Attach method takes an IWebBrowser2 reference:

    Attach HttpWatch to existing instance of IE
    Copy Code
    # You could have previously created your own instance of IE
    
    # directly or using a framework such as WatiN
    
    ieBrowser = WIN32OLE.new('InternetExplorer.Application') 
    
    ieBrowser.Visible = true    # Required to see the new window
    
     . . .
    
    control = WIN32OLE.new('HttpWatch.Controller')
    
    plugin = controller.IE.Attach(ieBrowser) 
    

     

    The following code creates a new instance of a Chrome tab with an attached HttpWatch plugin object:

    Creating the HttpWatch plug-in for Chrome
    Copy Code
    controller = WIN32OLE.new('HttpWatch.Controller')
    
    plugin = controller.Chrome.New()
    

    All of these code fragments return a reference to a Plugin object, through which the HttpWatch plug-in can be controlled.

     

    See Also