Download (direct link):
public WebResponse getResponse(java.lang.String urlString) throws java.net.MalformedURLException,
This method returns a WebResponse containing the result of a GET method request to the specified URL. It's essentially a convenience method for getResponse(new GetMethodWebRequest(urlString)) (see that method for details).
public WebResponse getResponse(WebRequest request) throws java.net.MalformedURLException, java.io.IOException, org.xml.sax.SAXException
One of the key methods in the HttpUnit API, getResponse() embodies a Webbrowser request and server response. Functionally, it sends the specified WebRequest to the server using all the state information (cookies, headers, and so on) stored in the WebClient.
The list of exceptions is large but manageable. In most test methods, you'll want to declare that the test method throws Exception and allow JUnit to treat these occurrences as test failures. The java exceptions are simply passed on from classes in the java.net package (representing an illegal URL and IO problem during network connection respectively). The SAXException occurs when an error occurs while parsing the received page as XML.
public String getUserAgent()
This method gets the User-Agent header (the type of browser this WebClient is emulating) that is sent to the server.
protected abstract WebResponse newResponse(WebRequest request) throws java.net.MalformedURLException, java.io.IOException
This method is used internally to talk to the server and create a new WebResponse from the results.
setAuthorization(String userName, String password)
public void setAuthorization(String userName, String password)
This method sets the Authorization header using the basic authorization scheme. (See the "Description" section of this class for an example.)
setHeaderField(String fieldName, String fieldValue)
public void setHeaderField(String fieldName, String fieldValue)
This method sets a header that will be sent to the server with every request. If a header is set to null, that header is removed from future requests:
conversation.setHeaderField("Cache-Control", "Cache-Control :
public void setUserAgent(String userAgent)
This method sets the User-Agent header (used to emulate a type of browser). updateClient(WebResponse response) protected final void updateClient(WebResponse response) throws java.net.MalformedURLException, java.io.IOException, org.xml.sax.SAXException
This method is used internally to update the state of the WebClient to reflect the results of the latest transaction.
public class WebConversation
WebConversation is the concrete implementation of WebClient; it provides no new external behavior. See the section on WebClient for details and examples.
protected WebResponse newResponse(WebRequest request) throws java.net.MalformedURLException, java.io.IOException
public class WebForm
This class represents an HTML form present in a Web page. It provides a variety of shortcut methods that make examining the form and writing assertions against it easier. It also provides the facility to create a WebRequest that simulates the submission of this form. (See the section on WebRequest for more details.) Note A common problem that occurs when working with WebForm relates to poorly
structured HTML. HttpUnit uses an HTML parser (JTidy) that parses strictly according to the HTML specification. Any improperly nested tags are ignored. For instance, JTidy would not recognize the form tags in the following lines:
This behavior can cause inconsistent results in HttpUnit even though the (more forgiving) standard browsers will have no problems with the form. To check if your HTML is improperly formatted, call HttpUnitOptions.setParserWarningsEnabled(true) (see the section on HttpUnitOptions for details) before retrieving the page in question. Doing so will cause any warnings generated by JTidy during parsing to be printed to System.out. Listing 16.2 (in the section on WebRequest) contains an example of using WebForm and WebRequest to access a form, verify it, and simulate a user's submission to that form.
public String getCharacterSet()
This method gets the character set encoding for this form. This information is contained in the Content-type header for the parent page.
public org.w3c.dom.Node getDOMSubtree()
This method returns a copy of the DOM Node representing this form in the underlying page. getID()
public String getID()