net.sf.jameleon.plugin.htmlunit.util
Class HtmlUnitHelper

java.lang.Object
  extended by net.sf.jameleon.plugin.htmlunit.util.HtmlUnitHelper

public class HtmlUnitHelper
extends Object

This class is used as a facade around the HtmlUnit API and is used by both the HtmlUnitSessionTag and the HtmlUnitFunctionTag.


Field Summary
protected  HtmlUnitDelegate delegate
           
 
Constructor Summary
HtmlUnitHelper(HtmlUnitDelegate delegate)
           
 
Method Summary
 void clickElementWithXPath(String xpath)
          Clicks on an HtmlElement (ClickableElement) defined by the provided XPath expression
 Page getCurrentPage()
          Gets the current page in the currently active WebWindow
 String getCurrentPageContent()
          Gets the HTML source from the currently active window
 WebResponse getCurrentWebResponse()
          Gets the currnet WebResponse
 HtmlUnitDelegate getDelegate()
          Gets the HtmlUnitDelegate that this object uses to communicate with the existing session.
 HtmlElement getHtmlElementByAttributeNameAndValue(String tagname, String attributeName, String attributeValue)
          Gets an HTMLElement by the tag name, attribute name and the attribute value.
 HtmlElement getHtmlElementByXPath(DomNode container, String xpath)
          Gets an HtmlElement matching the provided xpath expression
 HtmlElement getHtmlElementByXPath(String xpath)
          Gets an HtmlElement matching the provided xpath expression
 HtmlForm getHtmlFormById(String id)
          Gets a form element back by its id attribute.
 HtmlForm getHtmlFormByIndex(int index)
          Gets a form element back by its index or location on the page.
 HtmlForm getHtmlFormByName(String formName)
          Gets a form element back by its name attribute.
 HtmlForm getHtmlFormByXPath(String xpath)
          Gets a form element back by an XPath expression
 HtmlInput getHtmlInputByName(String fieldName)
          Gets an HtmlInput tag based on the current workingForm or the currently active page if the workingForm is not set.
 HtmlInput getHtmlInputByNameAndValue(String fieldName, String fieldValue)
          Gets an HtmlInput tag based on the current workingForm or the currently active page if the workingForm is not set.
 void navigate(String url)
          Navigates to the provided URL
 void setCheckBox(String fieldName, boolean checked)
          Checks or unchecks the checkbox that either exists in the workingForm or in the current page
 void setCheckBox(String fieldName, String fieldValue, boolean checked)
          Checks or unchecks the checkbox that either exists in the workingForm or in the current page.
 void setFileField(String fieldName, String value)
          Sets the file field that either exists in the workingForm or in the current page
 void setHiddenField(String fieldName, String value)
          Sets the hidden field that either exists in the workingForm or in the current page
 void setHtmlInputValue(HtmlInput input, String value, String type)
          Sets an input field type's value
 void setHtmlInputValueByXPath(String xpath, String value, String type)
          Sets an input field type's value
 void setPasswordField(String fieldName, String value)
          Sets the password field that either exists in the workingForm or in the current page
 void setRadioButton(String fieldName, String fieldValue, boolean checked)
          Checks or unchecks the radio button that either exists in the workingForm or in the current page.
 void setSelectFieldByIndex(String fieldName, int index, boolean selected)
          Selects or unselects the option by its index order that either exists in the workingForm or in the current page.
 void setSelectFieldByOptionText(String fieldName, String optionText, boolean selected)
          Selects or unselects the option with the displayed text that either exists in the workingForm or in the current page.
 void setSelectFieldByValue(String fieldName, String valueAttribute, boolean selected)
          Selects or unselects the option with the given attribute value that either exists in the workingForm or in the current page.
 void setSelectFieldByXPath(String xpath, boolean selected)
          Selects or unselects the option defined by XPath.
 void setTextArea(String fieldName, String value)
          Sets the text area that either exists in the workingForm or in the current page
 void setTextField(String fieldName, String value)
          Sets the text field that either exists in the workingForm or in the current page
 File store(String fName)
          Store the contents of the currently active window
 boolean xPathMatches(String xpath)
          Checks that the the provided XPath expression matches something on the current page.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

delegate

protected HtmlUnitDelegate delegate
Constructor Detail

HtmlUnitHelper

public HtmlUnitHelper(HtmlUnitDelegate delegate)
Method Detail

clickElementWithXPath

public void clickElementWithXPath(String xpath)
Clicks on an HtmlElement (ClickableElement) defined by the provided XPath expression

Parameters:
xpath - - The XPath expression to locate the element to click on.

getDelegate

public HtmlUnitDelegate getDelegate()
Gets the HtmlUnitDelegate that this object uses to communicate with the existing session.

Returns:
The HtmlUnitDelegate that this object uses to communicate with the existing session.

getCurrentPage

public Page getCurrentPage()
Gets the current page in the currently active WebWindow

Returns:
The current page in the currently active WebWindow

getCurrentPageContent

public String getCurrentPageContent()
Gets the HTML source from the currently active window

Returns:
The HTML source used in the current window

getCurrentWebResponse

public WebResponse getCurrentWebResponse()
Gets the currnet WebResponse

Returns:
The current WebResponse

getHtmlElementByXPath

public HtmlElement getHtmlElementByXPath(String xpath)
Gets an HtmlElement matching the provided xpath expression

Parameters:
xpath - - An XPath expression that matches the desired HtmlElement
Returns:
The matching HtmlElement

getHtmlElementByXPath

public HtmlElement getHtmlElementByXPath(DomNode container,
                                         String xpath)
Gets an HtmlElement matching the provided xpath expression

Parameters:
container - - The DOM to start at
xpath - - An XPath expression that matches the desired HtmlElement
Returns:
The matching HtmlElement

getHtmlElementByAttributeNameAndValue

public HtmlElement getHtmlElementByAttributeNameAndValue(String tagname,
                                                         String attributeName,
                                                         String attributeValue)
Gets an HTMLElement by the tag name, attribute name and the attribute value. This then in turn gets translated to an XPath expression. An example of this might be to get a form with its id='ten'.

Parameters:
tagname - - The name of the tag to get back. In the above example, the value would be 'form'
attributeName - - The name of attribute to check against. In the above example, the value would be 'id'
attributeValue - - The value of the attribute to check against. In the above example, the value would be 'ten'
Returns:
HtmlElement - An element that matches the criteria.

getHtmlFormById

public HtmlForm getHtmlFormById(String id)
Gets a form element back by its id attribute.

Parameters:
id - - the value of the id attribute.
Returns:
HtmlForm

getHtmlFormByIndex

public HtmlForm getHtmlFormByIndex(int index)
Gets a form element back by its index or location on the page. For the first form on the page, pass in '1'

Parameters:
index - - the nth form on the page
Returns:
HtmlForm

getHtmlFormByName

public HtmlForm getHtmlFormByName(String formName)
Gets a form element back by its name attribute.

Parameters:
formName - - the value of the name attribute.
Returns:
HtmlForm

getHtmlFormByXPath

public HtmlForm getHtmlFormByXPath(String xpath)
Gets a form element back by an XPath expression

Parameters:
xpath - - The XPath expression matching the desired form
Returns:
HtmlForm

getHtmlInputByName

public HtmlInput getHtmlInputByName(String fieldName)
Gets an HtmlInput tag based on the current workingForm or the currently active page if the workingForm is not set.

Parameters:
fieldName - - The name of the input field
Returns:
HtmlForm

getHtmlInputByNameAndValue

public HtmlInput getHtmlInputByNameAndValue(String fieldName,
                                            String fieldValue)
Gets an HtmlInput tag based on the current workingForm or the currently active page if the workingForm is not set.

Parameters:
fieldName - - The name of the input field
fieldValue - - The value of the input field
Returns:
HtmlForm

navigate

public void navigate(String url)
Navigates to the provided URL

Parameters:
url - - the url to navigate to.

setCheckBox

public void setCheckBox(String fieldName,
                        boolean checked)
Checks or unchecks the checkbox that either exists in the workingForm or in the current page

Parameters:
fieldName - - The name of the input field to set the value of
checked - - set to true to check the checkbox and to false to uncheck it

setCheckBox

public void setCheckBox(String fieldName,
                        String fieldValue,
                        boolean checked)
Checks or unchecks the checkbox that either exists in the workingForm or in the current page. This method is used for pages that contain several checkboxes with the same name, but different values

Parameters:
fieldName - - The name of the checkbox to check
fieldValue - - The value of the input field to check
checked - - set to true to check the checkbox and to false to uncheck it

setFileField

public void setFileField(String fieldName,
                         String value)
Sets the file field that either exists in the workingForm or in the current page

Parameters:
fieldName - - The name of the input field to set the value of
value - - The value to set the input field to

setHiddenField

public void setHiddenField(String fieldName,
                           String value)
Sets the hidden field that either exists in the workingForm or in the current page

Parameters:
fieldName - - The name of the input field to set the value of
value - - The value to set the input field to

setPasswordField

public void setPasswordField(String fieldName,
                             String value)
Sets the password field that either exists in the workingForm or in the current page

Parameters:
fieldName - - The name of the input field to set the value of
value - - The value to set the input field to

setRadioButton

public void setRadioButton(String fieldName,
                           String fieldValue,
                           boolean checked)
Checks or unchecks the radio button that either exists in the workingForm or in the current page.

Parameters:
fieldName - - The name of the radio button to check
fieldValue - - The value of the radio button to check
checked - - set to true to check the radio button and to false to uncheck it

setSelectFieldByIndex

public void setSelectFieldByIndex(String fieldName,
                                  int index,
                                  boolean selected)
Selects or unselects the option by its index order that either exists in the workingForm or in the current page.

Parameters:
fieldName - - The name of the select field to select
index - - The nth option in the list. 1st option = 1
selected - - set to true to select and to false to unselect it

setSelectFieldByOptionText

public void setSelectFieldByOptionText(String fieldName,
                                       String optionText,
                                       boolean selected)
Selects or unselects the option with the displayed text that either exists in the workingForm or in the current page.

Parameters:
fieldName - - The name of the select field to select
optionText - - The text displayed in the drop-down
selected - - set to true to select and to false to unselect it

setSelectFieldByValue

public void setSelectFieldByValue(String fieldName,
                                  String valueAttribute,
                                  boolean selected)
Selects or unselects the option with the given attribute value that either exists in the workingForm or in the current page.

Parameters:
fieldName - - The name of the select field to select
valueAttribute - - The value of option field to select
selected - - set to true to select and to false to unselect it

setSelectFieldByXPath

public void setSelectFieldByXPath(String xpath,
                                  boolean selected)
Selects or unselects the option defined by XPath.

Parameters:
xpath - - The XPath expression that matches an HtmlOption (not a select) to be selected
selected - - set to true to select and to false to unselect it

setTextArea

public void setTextArea(String fieldName,
                        String value)
Sets the text area that either exists in the workingForm or in the current page

Parameters:
fieldName - - The name of the input field to set the value of
value - - The value to set the input field to

setTextField

public void setTextField(String fieldName,
                         String value)
Sets the text field that either exists in the workingForm or in the current page

Parameters:
fieldName - - The name of the input field to set the value of
value - - The value to set the input field to

setHtmlInputValue

public void setHtmlInputValue(HtmlInput input,
                              String value,
                              String type)
Sets an input field type's value

Parameters:
input - - The HtmlInput to set the value on
value - - The value to set the input element to.
type - - The input type. If this does not match the given field, then this method will fail

setHtmlInputValueByXPath

public void setHtmlInputValueByXPath(String xpath,
                                     String value,
                                     String type)
Sets an input field type's value

Parameters:
xpath - - An XPath expression that matches the desired HtmlInput Element.
value - - The value to set the input element to.
type - - The input type. If this does not match the given field, then this method will fail

store

public File store(String fName)
           throws IOException
Store the contents of the currently active window

Parameters:
fName - - The name of the file to store the source to.
Throws:
IOException

xPathMatches

public boolean xPathMatches(String xpath)
Checks that the the provided XPath expression matches something on the current page.

Parameters:
xpath - - The XPath expression to evaulate
Returns:
boolean - true if the XPath expresssion matches


Copyright © 2006-2008 Christian Hargraves. All Rights Reserved.