org.apache.shale.test.htmlunit
Class AbstractHtmlUnitTestCase

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by org.apache.shale.test.htmlunit.AbstractHtmlUnitTestCase
All Implemented Interfaces:
junit.framework.Test

public abstract class AbstractHtmlUnitTestCase
extends junit.framework.TestCase

Abstract base class for system integration tests based on HtmlUnit. These tests will expect a system property named url to be present, which will define the URL (including the context path, but without a trailing slash) of the application to be tested.


Field Summary
protected  com.gargoylesoftware.htmlunit.html.HtmlPage page
          The most recently retrieved page from the server.
protected  URL url
          The calculated URL for the installed "systest" web application.
protected  com.gargoylesoftware.htmlunit.WebClient webClient
          The web client for this test case.
 
Constructor Summary
AbstractHtmlUnitTestCase(String name)
          Construct a new instance of this test case.
 
Method Summary
protected  com.gargoylesoftware.htmlunit.html.HtmlBody body()
          Return the body element for the most recently retrieved page.
protected  com.gargoylesoftware.htmlunit.html.HtmlElement element(String id)
          Return the HTML element with the specified id from the most recently retrieved page.
protected  com.gargoylesoftware.htmlunit.html.HtmlForm form(String id)
          Return the form with the specified id from the most recently retrieved page.
protected  com.gargoylesoftware.htmlunit.html.HtmlHead head()
          Return the head element for the most recently retrieved page.
protected  com.gargoylesoftware.htmlunit.html.HtmlPage link(com.gargoylesoftware.htmlunit.html.HtmlAnchor anchor)
          Click the specified hyperlink, and retrieve the subsequent page, saving a reference so that other utility methods may be used to retrieve information from it.
protected  com.gargoylesoftware.htmlunit.html.HtmlPage page()
          Return the currently stored page reference.
protected  com.gargoylesoftware.htmlunit.html.HtmlPage page(String path)
          Retrieve and return the page at the specified context relative path.
protected  void reset(com.gargoylesoftware.htmlunit.html.HtmlPage page)
          Reset the stored page reference to the specified value.
protected  void setUp()
          Set up the instance variables required for this test case.
protected  com.gargoylesoftware.htmlunit.html.HtmlPage submit(com.gargoylesoftware.htmlunit.html.HtmlSubmitInput submit)
          Submit the current page, using the specified component, and retrieve the subsequent page, saving a reference so that other utility methods may be used to retrieve information from it.
static junit.framework.Test suite()
          Return the set of tests included in this test suite.
protected  void tearDown()
          Tear down instance variables required by this test case.
protected  String title()
          Return the page title from the most recently retrieved page.
protected  URL url(String path)
          Calculate and return an absolute URL for the specified context relative path, which must begin with a '/' character.
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, runBare, runTest, setName, toString
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

page

protected com.gargoylesoftware.htmlunit.html.HtmlPage page

The most recently retrieved page from the server.


url

protected URL url

The calculated URL for the installed "systest" web application. This value is based on a system property named url, which must be defined as part of the command line that executes each test case.


webClient

protected com.gargoylesoftware.htmlunit.WebClient webClient

The web client for this test case.

Constructor Detail

AbstractHtmlUnitTestCase

public AbstractHtmlUnitTestCase(String name)

Construct a new instance of this test case.

Parameters:
name - Name of the new test case
Method Detail

setUp

protected void setUp()
              throws Exception

Set up the instance variables required for this test case.

Overrides:
setUp in class junit.framework.TestCase
Throws:
Exception - if an error occurs

suite

public static junit.framework.Test suite()

Return the set of tests included in this test suite.


tearDown

protected void tearDown()
                 throws Exception

Tear down instance variables required by this test case.

Overrides:
tearDown in class junit.framework.TestCase
Throws:
Exception

body

protected com.gargoylesoftware.htmlunit.html.HtmlBody body()
                                                    throws Exception

Return the body element for the most recently retrieved page. If there is no such element, return null.

Throws:
Exception - if an error occurs

element

protected com.gargoylesoftware.htmlunit.html.HtmlElement element(String id)
                                                          throws Exception

Return the HTML element with the specified id from the most recently retrieved page. If there is no such element, return null.

Parameters:
id - Identifier of the requested element.
Throws:
Exception - if an error occurs

form

protected com.gargoylesoftware.htmlunit.html.HtmlForm form(String id)
                                                    throws Exception

Return the form with the specified id from the most recently retrieved page. If there is no such form, return null.

Parameters:
id - Identifier of the requested form.
Throws:
Exception - if an error occurs

head

protected com.gargoylesoftware.htmlunit.html.HtmlHead head()
                                                    throws Exception

Return the head element for the most recently retrieved page. If there is no such element, return null.

Throws:
Exception - if an error occurs

link

protected com.gargoylesoftware.htmlunit.html.HtmlPage link(com.gargoylesoftware.htmlunit.html.HtmlAnchor anchor)
                                                    throws IOException

Click the specified hyperlink, and retrieve the subsequent page, saving a reference so that other utility methods may be used to retrieve information from it.

Parameters:
anchor - Anchor component to click
Throws:
IOException - if an input/output error occurs

page

protected com.gargoylesoftware.htmlunit.html.HtmlPage page()

Return the currently stored page reference.


page

protected com.gargoylesoftware.htmlunit.html.HtmlPage page(String path)
                                                    throws Exception

Retrieve and return the page at the specified context relative path. Save a reference to this page so that other utility methods may be used to retrieve information from it.

Parameters:
path - Context relative path
Throws:
IllegalArgumentException - if the context relative path does not begin with a '/' character
Exception - if a different error occurs

reset

protected void reset(com.gargoylesoftware.htmlunit.html.HtmlPage page)

Reset the stored page reference to the specified value. This is useful for scenarios testing resubmit of the same page (simulating the user pressing the back button and then submitting again).

Parameters:
page - Previously saved page to which to reset

submit

protected com.gargoylesoftware.htmlunit.html.HtmlPage submit(com.gargoylesoftware.htmlunit.html.HtmlSubmitInput submit)
                                                      throws IOException

Submit the current page, using the specified component, and retrieve the subsequent page, saving a reference so that other utility methods may be used to retrieve information from it.

Parameters:
submit - Submit button component to click
Throws:
IOException - if an input/output error occurs

title

protected String title()
                throws Exception

Return the page title from the most recently retrieved page. Any leading and trailing whitespace will be trimmed.

Throws:
Exception - if an error occurs

url

protected URL url(String path)
           throws Exception

Calculate and return an absolute URL for the specified context relative path, which must begin with a '/' character.

Parameters:
path - Context relative path
Throws:
IllegalArgumentException - if the context relative path does not begin with a '/' character
Exception - if a different error ocurs


Copyright © 2004-2007 Apache Software Foundation. All Rights Reserved.