Package com.meterware.httpunit
package com.meterware.httpunit
Classes for testing http server systems. Each test session should begin by creating a
WebConversation
to which it should submit an
initial http request
using the
getResponse
method. With each
subsequent step,
it will typically examine the response either textually or as a DOM, and create new
requests based on either submitting a form or clicking on a link.
Installation
The package depends on a number of external jar files, provided in thejar
directory:
- nekohtml.jar
- The NekoHTML parser, used to convert raw HTML into an XML DOM. This is required for handling HTML.
- js.jar
- The Rhino JavaScript interpreter, required for any JavaScript processing.
- xmlParserAPIs.jar
- The interfaces for a W3-compliant XML parser. Required for interpreting either HTML or XML pages.
- xercesImpl.jar
- The Xerces 2 implementation of an XML parser. NekoHTML requires this implementation.
- servlet.jar
- The APIs and common classes for the Java Servlet 1.3 standard. Required for use with ServletUnit.
- junit.jar
- JUnit, the unit test framework. Used to test HttpUnit and recommended for writing tests that use HttpUnit.
- tidy.jar
- JTidy, an alternate HTML parser/validator.
JTidy is a lot pickier about HTML structure than NekoHTML, and uses its own implementation of the DOM classes, rather than using those
found in the xerces jar. Some JavaScript features, such as
document.write()
will only work with NekoHTML.
Example
In the following code, a web conversation is started and an initial request sent. The program then prints out the response and extracts the first form (the login form) from it. After setting the name parameter to the desired value, it submits the form and prints the response.import com.meterware.httpunit.*; import java.io.IOException; import java.net.MalformedURLException; import org.xml.sax.*; public class Example { public static void main( String[] params ) { try { WebConversation conversation = new WebConversation(); WebResponse response = conversation.getResponse( "http://www.meterware.com/servlet/TopSecret" ); System.out.println( response ); WebForm loginForm = response.getForms()[0]; loginForm.setParameter( "name", "master" ); response = loginForm.submit(); System.out.println( response ); } catch (Exception e) { System.err.println( "Exception: " + e ); } } }Please direct any questions to Russell Gold.
-
ClassDescriptionThis exception is thrown when an unauthorized request is made for a page that requires authentication.A utility class to convert to and from base 64 encoding.Represents a block-level element such as a paragraph or table cell, which can contain other elements.A button in a form.A class which represents the properties of a web client.Interface for an object to supply user responses to dialogs.A listener for DNS Requests.Represents a control in an HTML form.Represents the aggregate of all form controls with a particular name.An immutable class which describes the position of a frame in the window hierarchy.An HTTP request using the GET method.A web request which has no information in its message body.A web request using the HEAD method.An interface which defines the common properties for an HTML element, which can correspond to any HTML tag.An interface which can be used to define matching criteria for an HTML element.Deprecated.as of 1.5.2, use HTMLParserListenerThis class represents an HTML page returned from a request.Represents the parse tree for a segment of HTML.This exception is thrown when an Http error (response code 4xx or 5xx) is detected.This exception is thrown when an internal error is found on the server.This exception is thrown when the desired URL is not found.Encapsulates support for the HTTPS protocol.A collection of global options to control HttpUnit's behavior.Utility code shared by httpunit and servletunit.This exception is thrown on an attempt to set a form parameter in a way not possible from a browser.A web request which contains a non-empty message body.A method request message body read directly from an input stream.Some common utilities for manipulating DOM nodes.An HTTP request using the POST method.A web request using the PUT protocol.Radio button controlClass used to indicate when a request to a resource resulted in an HTTP redirect response that lead to a recursive loop of redirectionsRepresents a form 'reset' button.An exception thrown when there is a problem running a script.This class represents a submit button in an HTML form.A single cell in an HTML table.A class which represents a block of text in a web page.An exception thrown when an action URL is not supported.This class represents the embedding of an applet in a web page.The context for a series of web requests.A listener for messages sent and received by a web client.The context for a series of HTTP requests.This class represents a form in an HTML page.Represents an image in an HTML document.This class represents a link in an HTML page.Represents an HTML list.A request sent to a web server.Base class for objects which can be clicked to generate new web requests.A response to a web request from a web server.This class represents a table in an HTML page.A window managed by a
WebClient
.A listener for web window openings and closings.