org.apache.myfaces.test.htmlunit.junit4
Class AbstractHtmlUnitTestCase

java.lang.Object
  extended by org.apache.myfaces.test.htmlunit.junit4.AbstractHtmlUnitTestCase

public abstract class AbstractHtmlUnitTestCase
extends Object

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.

Since:
1.0.0

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()
          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.
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 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, 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()

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.

Throws:
Exception - if an error occurs

tearDown

protected void tearDown()
                 throws Exception

Tear down instance variables required by this test case.

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 © 2014 The Apache Software Foundation. All Rights Reserved.