Cactus provides the exact same integration with HtmlUnit as with HttpUnit. This page discusses this integration.
Cactus test cases allow to assert the results of the returned server
output stream in an endXXX() method (where XXX
is the name of your test case).
Cactus proposes 2 ways of writing your endXXX() methods,
endXXX() method. Method 1 is a class provided by Cactus.
Depending on your need you can choose, on a per test case basis, the
method you want to use.
The signature of an endXXX() method is always:
public void endXXX(WebResponse theResponse)
{
[...]
}
The WebResponse object is passed by the Cactus framework
to your endXXX() method. What changes between the 2
methods described above is the class of the WebResponse
object that is passed:
org.apache.cactus.WebResponse for Method 1,
com.gargoylesoftware.htmlunit.WebResponse for Method 2
(HtmlUnit)
public void endXXX(org.apache.cactus.WebResponse theResponse)
{
// Get the returned cookies
Hashtable cookies = theResponse.getCookies();
// Get the returned content as a string
String content = theResponse.getText();
// Do some asserts
assertEquals(content, "<html><body><h1>Hello world!</h1></body></html>");
[...]
}
WebResponse object, see the associated Javadoc.
public void endXXX(com.meterware.httpunit.WebResponse theResponse)
{
WebTable table = theResponse.getTables()[0];
assertEquals("<html><head/><body>A GET request</body></html>", theResponse.getContentAsString());
[...]
}
WebResponse object, see the HtmlUnit
documentation.