com.meterware.httpunit |
Classes for testing http server systems. Each test session should begin by creating a
{@link com.meterware.httpunit.WebConversation WebConversation} to which it should submit an
initial {@link com.meterware.httpunit.GetMethodWebRequest http request} using the
{@link com.meterware.httpunit.WebConversation#getResponse 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 the jar 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.
|
Java Source File Name | Type | Comment |
AppletContextImpl.java | Class | |
AppletStubImpl.java | Class | |
AuthorizationRequiredException.java | Class | This exception is thrown when an unauthorized request is made for a page that requires authentication. |
Base64.java | Class | A utility class to convert to and from base 64 encoding. |
BlockElement.java | Class | Represents a block-level element such as a paragraph or table cell, which can contain other elements. |
Button.java | Class | A button in a form. |
ClientProperties.java | Class | A class which represents the properties of a web client. |
ContentConcealer.java | Interface | This is a marker interface implemented by HTMLElement classes which hide their content. |
DialogAdapter.java | Class | |
DialogResponder.java | Interface | Interface for an object to supply user responses to dialogs. |
DNSListener.java | Interface | A listener for DNS Requests. |
FixedURLWebRequestSource.java | Class | An implementation of web request source whose URL does not change under user action. |
FormControl.java | Class | Represents a control in an HTML form. |
FormParameter.java | Class | Represents the aggregate of all form controls with a particular name. |
FrameHolder.java | Class | |
FrameSelector.java | Class | An immutable class which describes the position of a frame in the window hierarchy. |
GetMethodWebRequest.java | Class | An HTTP request using the GET method. |
HeaderOnlyWebRequest.java | Class | A web request which has no information in its message body. |
HeadMethodWebRequest.java | Class | A web request using the HEAD method. |
HTMLElement.java | Interface | An interface which defines the common properties for an HTML element, which can correspond to any HTML tag. |
HTMLElementBase.java | Class | |
HTMLElementPredicate.java | Interface | An interface which can be used to define matching criteria for an HTML element. |
HTMLElementScriptable.java | Class | |
HtmlErrorListener.java | Interface | This interface represents a listener which can receive notification of errors and warnings during the parsing
of an HTML page. |
HTMLPage.java | Class | This class represents an HTML page returned from a request. |
HTMLSegment.java | Interface | Represents the parse tree for a segment of HTML. |
HttpException.java | Class | This exception is thrown when an Http error (response code 4xx or 5xx) is detected. |
HttpInternalErrorException.java | Class | This exception is thrown when an internal error is found on the server. |
HttpNotFoundException.java | Class | This exception is thrown when the desired URL is not found. |
HttpsProtocolSupport.java | Class | Encapsulates support for the HTTPS protocol. |
HttpUnitOptions.java | Class | A collection of global options to control HttpUnit's behavior. |
HttpUnitUtils.java | Class | Utility code shared by httpunit and servletunit. |
HttpWebResponse.java | Class | A response from a web server to an Http request. |
IllegalRequestParameterException.java | Class | This exception is thrown on an attempt to set a form parameter in a way not possible from a browser. |
MessageBody.java | Class | An abstract class representing the body of a web request. |
MessageBodyWebRequest.java | Class | A web request which contains a non-empty message body. |
MimeEncodedMessageBody.java | Class | A POST-method message body which is MIME-encoded. |
NodeUtils.java | Class | Some common utilities for manipulating DOM nodes. |
NoSuchFrameException.java | Class | |
NotHTMLException.java | Class | $Id: NotHTMLException.java,v 1.1 2002/05/16 17:44:20 russgold Exp $
Copyright (c) 2002, Russell Gold
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
ParameterHolder.java | Class | This abstract class is extended by classes which hold parameters for web requests. |
ParameterProcessor.java | Interface | |
ParsedHTML.java | Class | |
PostMethodWebRequest.java | Class | An HTTP request using the POST method. |
PutMethodWebRequest.java | Class | A web request using the PUT protocol. |
RequestContext.java | Class | The context for a request which could have subrequests. |
ResetButton.java | Class | Represents a form 'reset' button. |
ScriptException.java | Class | An exception thrown when there is a problem running a script. |
SubmitButton.java | Class | This class represents a submit button in an HTML form. |
TableCell.java | Class | A single cell in an HTML table. |
TableRow.java | Class | |
TextBlock.java | Class | A class which represents a block of text in a web page. |
UncheckedParameterHolder.java | Class | |
UnsupportedActionException.java | Class | An exception thrown when an action URL is not supported. |
UploadFileSpec.java | Class | A description of a file to be uploaded as part of a form submission. |
WebApplet.java | Class | This class represents the embedding of an applet in a web page. |
WebClient.java | Class | The context for a series of web requests. |
WebClientListener.java | Interface | A listener for messages sent and received by a web client. |
WebConversation.java | Class | The context for a series of HTTP requests. |
WebForm.java | Class | This class represents a form in an HTML page. |
WebFrame.java | Class | A frame in a web page. |
WebImage.java | Class | Represents an image in an HTML document. |
WebLink.java | Class | This class represents a link in an HTML page. |
WebList.java | Class | Represents an HTML list. |
WebRequest.java | Class | A request sent to a web server. |
WebRequestSource.java | Class | Base class for objects which can be clicked to generate new web requests. |
WebResponse.java | Class | A response to a web request from a web server. |
WebTable.java | Class | This class represents a table in an HTML page. |
WebWindow.java | Class | A window managed by a
com.meterware.httpunit.WebClient WebClient . |
WebWindowListener.java | Interface | A listener for web window openings and closings. |