What is jacobie?

Jacobie is a Java API for use with Internet Explorer. Based on the JACOB project (JAva to COm Bridge) and the IE COM Object, it directly controls IE from java. This API can be used as a true end-user web browser test with IE and not a Http-Based test such as HttpUnit.

While using other testing frameworks, I ran into the true goal of testing a web-based app. It must be a true browser test. A true end-user test. Here are a few problems I ran into using other forms of testing harnesses: lack of javascript support, hard to connect to secure sites (SSL), no visual view of what is happening.

What does jacobie provide?

jacobie provides a high-level API for navigating a web application combined with a set of assertions to verify the application's correctness. This includes navigation via links, form entry and submission, validation of table contents, and other typical business web application features. This code utilizes HttpUnit behind the scenes. The simple navigation methods and ready-to-use assertions allow for more rapid test creation than using only JUnit and HttpUnit.

The following gives you quick summary of the different implementations of browser testing frameworks.

-Jacob only accessing IE without Jacobie (IE Wrapper.) True-Browser testing.

-Jacobie accessing IE. True-Browser testing.

-HttpUnit accessing the google via its API. Simulated-Browser testing.

-jWebUnit accessing the google via its API. Eases the coding aspect. Jacobie or HttpUnit is integrated.

Jacob Only Test
package net.sf.jacobie.examples;

import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.Dispatch;
import com.jacob.com.DispatchEvents;
import com.jacob.com.Variant;

/*
 * This example shows how to directly call Internet Explorer without the jacobie
 * wrapper classes.  This makes direct calls to the jacob api
 * 
 * Basic example taken directly from the jacob example.
 * 
 * This demonstrates the new event handling code in jacob 1.7
 * This example will open up IE and print out some of the events
 * it listens to as it havigates to web sites.
 */
public class JacobOnlyIETest {
	
	public static void main(String[] args) {
		ActiveXComponent ie = new ActiveXComponent("clsid:0002DF01-0000-0000-C000-000000000046");
		Object ieo = ie.getObject();
		try {
			Dispatch.put(ieo, "Visible", new Variant(true));
			Dispatch.put(ieo, "AddressBar", new Variant(true));
			System.out.println(Dispatch.get(ieo, "Path"));
			Dispatch.put(ieo, "StatusText", new Variant("My Status Text"));

			IEEvents ieE = new IEEvents();
			DispatchEvents de = new DispatchEvents((Dispatch) ieo, ieE, "InternetExplorer.Application.1");
			Variant optional = new Variant();
			optional.noParam();

			Dispatch.call(ieo, "Navigate", new Variant("http://www.google.com"));
			try {
				Thread.sleep(5000);
			} catch (Exception e) {
			}

			Object theDocument = Dispatch.get(ieo, "Document").toDispatch();
			System.out.println(theDocument);

			Object theLink = Dispatch.call(theDocument, "links", new Integer(1)).toDispatch();

			Dispatch.call(theLink, "click");

			try {
				Thread.sleep(5000);
			} catch (Exception e) {
			}

		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			ie.invoke("Quit", new Variant[] {
			});
		}
	}
}
Jacobie Test
package net.sf.jacobie.examples;

import java.util.ListIterator;
import java.util.Vector;

import net.sf.jacobie.ie.A;
import net.sf.jacobie.ie.Document;
import net.sf.jacobie.ie.Form;
import net.sf.jacobie.ie.IE;

/*
 * This simple example shows how to directly call Internet Explorer WITH the jacobie
 * wrapper classes.  This makes it much easier to access IE's COM object via
 * java.
 * 
 * @author Nick Neuberger
 */

public class JacobieSimpleIETest {
	
	public static void main(String[] args) {
		IE theIE = new IE();
		
		try {
			theIE.setVisible(true);
			theIE.setAddressBar(true);
			System.out.println("IE Path is: [" + theIE.getPath() + "]");

			theIE.Navigate("http://www.google.com");			
			theIE.waitWhileBusy();

			Document theDocument = theIE.getDocument();	
			
			System.out.println("Title is: [" + theDocument.getTitle() + "]");
			
			printLinksFromDocument(theDocument);
			printFormsFromDocument(theDocument);
			
			A theLink = theDocument.getLinks(1);			
			System.out.println("InnerText is: [" + theLink.getInnerText() + "]");
			theLink.click();

			theIE.waitWhileBusy();
			
			Thread.sleep(5000);
			
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			theIE.Quit();
		}
	}
HttpUnit Test
package net.sourceforge.jacobie.sample;

import junit.framework.TestCase;
import com.meterware.httpunit.WebResponse;
import com.meterware.httpunit.WebConversation;
import com.meterware.httpunit.WebForm;
import com.meterware.httpunit.WebRequest;

public class SearchExample extends TestCase {

   public void testSearch() throws Exception {
      WebConversation wc = new WebConversation();
      WebResponse resp = wc.getResponse( "http://www.google.com");
      WebForm form = resp.getForms()[0];
      form.setParameter("q", "HttpUnit");
      WebRequest req = form.getRequest("btnG");
      resp = wc.getResponse(req);
      assertNotNull(resp.getLinkWith("HttpUnit"));
      resp = resp.getLinkWith("HttpUnit").click();
      assertEquals(resp.getTitle(), "HttpUnit");
      assertNotNull(resp.getLinkWith("User's Manual"));
   }
}
jWebUnit Test (with either httpunit or jacobie)
package net.sourceforge.jacobie.sample;

import net.sourceforge.jacobie.WebTestCase;

public class JWebUnitSearchExample extends WebTestCase {

   public JWebUnitSearchExample(String name) {
      super(name);
   }

   public void setUp() {
      getTestContext().setBaseUrl("http://www.google.com");
   }

    /**
     * Initializes a new instance of the web tester class.
     * Override this method if you want to pass in a different testing engine (dialog).
     */
    public WebTester initializeWebTester() {
    	IJWebUnitDialog theIJWebUnitDialog = null;
    	
    	//theIJWebUnitDialog = new HttpUnitDialog();
    	//theIJWebUnitDialog = new JacobieDialog();
    	
        return new WebTester(theIJWebUnitDialog);
    }

   public void testSearch() {
      beginAt("/");
      setFormElement("q", "httpunit");
      submit("btnG");
      clickLinkWithText("HttpUnit");
      assertTitleEquals("HttpUnit");
      assertLinkPresentWithText("User's Manual");
   }
}