net.sf.jameleon.plugin.htmlunit
Class HtmlUnitFunctionTag

java.lang.Object
  extended by org.apache.commons.jelly.TagSupport
      extended by net.sf.jameleon.LocationAwareTagSupport
          extended by net.sf.jameleon.JameleonTagSupport
              extended by net.sf.jameleon.function.FunctionTag
                  extended by net.sf.jameleon.plugin.htmlunit.HtmlUnitFunctionTag
All Implemented Interfaces:
BreakPoint, Attributable, Storable, DynaTag, LocationAware, Tag
Direct Known Subclasses:
AbstractHtmlUnitSetFormFieldTag, HtmlUnitClickTag, HtmlUnitNavigateTag, HtmlUnitRecordAlertsTag, HtmlUnitSetSelectFieldTag, HtmlUnitValidateTag

public abstract class HtmlUnitFunctionTag
extends FunctionTag


Field Summary
protected  HtmlUnitHelper helper
           
protected  HtmlUnitSessionTag sessionTag
           
protected  HtmlForm workingForm
           
 
Fields inherited from class net.sf.jameleon.function.FunctionTag
addt, breakPoint, expectException, expectFailure, fResults, functionDelay, functionId, lastFileWritten, log, NO_DELAY, params, postcondition, precondition, st, state, tct, vpt
 
Fields inherited from class net.sf.jameleon.JameleonTagSupport
attributes, broker, contextVars, fp, unsupportedAttributes
 
Fields inherited from class net.sf.jameleon.LocationAwareTagSupport
columnNumber, elementTagName, lineNumber, scriptFileName
 
Fields inherited from class org.apache.commons.jelly.TagSupport
body, context, hasTrimmed, parent, shouldTrim
 
Constructor Summary
HtmlUnitFunctionTag()
           
 
Method Summary
 void assertTextPresent(String expectedText)
          Validates that the provided text exists on the page.
 void assertTextPresent(String expectedText, int assertLevel)
          Validates that the title of the current html page matches the expected title
 void assertTextPresent(String msg, String expectedText)
          Validates that the title of the current html page matches the expected title If the test fails display the given message
 void assertTextPresent(String msg, String expectedText, int assertLevel)
          Validates that the title of the current html page matches the expected title If the test fails display the given message
 void assertTitleEquals(String expectedTitle)
          Validates that the title of the current html page matches the expected title
 void assertTitleEquals(String expectedTitle, int assertLevel)
          Validates that the title of the current html page matches the expected title
 void assertTitleEquals(String msg, String expectedTitle)
          Validates that the title of the current html page matches the expected title If the test fails display the given message
 void assertTitleEquals(String msg, String expectedTitle, int assertLevel)
          Validates that the title of the current html page matches the expected title If the test fails display the given message
 void assertXPathMatches(String xpath)
          Validates that the provided xpath matches against the currently active page
 void assertXPathMatches(String xpath, int assertLevel)
          Validates that the provided xpath matches against the currently active page
 void assertXPathMatches(String msg, String xpath)
          Validates that the provided xpath matches against the currently active page If the test fails display the given message
 void assertXPathMatches(String msg, String xpath, int assertLevel)
          Validates that the provided xpath matches against the currently active page If the test fails display the given message
 void clickElementWithXPath(String xpath)
          Clicks on the HTML element matching the provided XPath
 HtmlElement getHtmlElementByAttributeNameAndValue(String tagname, String attributeName, String attributeValue)
          Gets an HTMLElement by the tag name, attribute name and the attribute value.
 HtmlElement getHtmlElementByXPath(String xpath)
          Gets an HtmlElement matching the provided xpath expression
 HtmlForm getHtmlForm(String idNameIndexOrXpath)
          This is a power method to get a form element by the following order.
 HtmlForm getHtmlFormById(String attributeValue)
          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 attributeValue)
          Gets a form element back by its name attribute.
 HtmlForm getHtmlFormByXPath(String xpath)
          Gets a form element back by an XPath expression
 HtmlForm getWorkingForm()
          Gets the current working form or null if one hasn't been 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
 void setupEnvironment()
          Gets the references of the session and the test results from the parent TestCase This method gets called once all attributes are set from the macro language.
 void setWorkingForm(String idNameIndexOrXpath)
          Sets the working form to form with the given id This is a power method to set a form element by the following order.
 void setWorkingFormById(String id)
          Sets the working form to form with the given id
 void setWorkingFormByIndex(int index)
          Sets the working form to nth form on the current page.
 void setWorkingFormByName(String name)
          Sets the working form to nth form on the current page.
 void setWorkingFormByXPath(String xpath)
          Sets the working form by the matching XPath expression
 void store(String fName, int event)
           
 
Methods inherited from class net.sf.jameleon.function.FunctionTag
addParam, addRequiredAttribute, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertFalse, assertFalse, assertMethod, assertMethodWithLevel, assertNotNull, assertNotNull, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNotSame, assertNotSame, assertNull, assertNull, assertNull, assertNull, assertRegexMatches, assertRegexMatches, assertRegexMatches, assertRegexMatches, assertSame, assertSame, assertSame, assertSame, assertTextContains, assertTextContains, assertTextContains, assertTextContains, assertTextEndsWith, assertTextEndsWith, assertTextEndsWith, assertTextEndsWith, assertTextStartsWith, assertTextStartsWith, assertTextStartsWith, assertTextStartsWith, assertTrue, assertTrue, assertTrue, assertTrue, checkParamTypes, cleanUp, cleanUpEnvironment, delay, delay, doTag, fail, fail, fail, fail, getFunctionId, getFunctionResults, getMatchingRegexText, getParam, getParamLength, getParams, getParentTags, getSessionTag, getStoreToFileName, getStringOrDefault, getTestCaseTag, getVariable, getVariableAsBoolean, getVariableAsList, getVariableAsString, isBreakPoint, isContextVariableNull, pluginTearDown, recordFunctionResult, regexMatches, removeFunctionResult, removeVariable, setDefaultVariableValue, setDefaultVariableValue, setExpectException, setExpectFailure, setFunctionDelay, setFunctionId, setup, setUpFunctionResults, setVariable, tearDown, testBlock, traceMsg, validate
 
Methods inherited from class net.sf.jameleon.JameleonTagSupport
cleanVariablesInContext, createAttributes, describeAttributes, getAttributeBroker, getAttributes, getAttributeType, getClassAttributes, getFunctionalPoint, getUnsupportedAttributes, loadFunctionalPoint, resetFunctionalPoint, setAttribute, setVariableInContext, testForUnsupportedAttributesCaught
 
Methods inherited from class net.sf.jameleon.LocationAwareTagSupport
getColumnNumber, getElementName, getFileName, getLineNumber, setColumnNumber, setElementName, setFileName, setLineNumber
 
Methods inherited from class org.apache.commons.jelly.TagSupport
findAncestorWithClass, findAncestorWithClass, findAncestorWithClass, findAncestorWithClass, findAncestorWithClass, findAncestorWithClass, getBody, getBodyText, getBodyText, getContext, getParent, invokeBody, isEscapeText, isTrim, setBody, setContext, setEscapeText, setParent, setTrim, trimBody
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.commons.jelly.Tag
getBody, getContext, getParent, invokeBody, setBody, setContext, setParent
 

Field Detail

helper

protected HtmlUnitHelper helper

sessionTag

protected HtmlUnitSessionTag sessionTag

workingForm

protected HtmlForm workingForm
Constructor Detail

HtmlUnitFunctionTag

public HtmlUnitFunctionTag()
Method Detail

navigate

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

Parameters:
url - - the url to navigate to.

setupEnvironment

public void setupEnvironment()
Gets the references of the session and the test results from the parent TestCase This method gets called once all attributes are set from the macro language. Any required setup should go here.

Overrides:
setupEnvironment in class FunctionTag

store

public void store(String fName,
                  int event)
           throws IOException
Specified by:
store in interface Storable
Overrides:
store in class FunctionTag
Throws:
IOException

assertTextPresent

public void assertTextPresent(String expectedText)
Validates that the provided text exists on the page.

Parameters:
expectedText - expected text

assertTextPresent

public void assertTextPresent(String msg,
                              String expectedText)
Validates that the title of the current html page matches the expected title If the test fails display the given message

Parameters:
msg - - The message to display if text is not in the response.
expectedText - expected text

assertTextPresent

public void assertTextPresent(String expectedText,
                              int assertLevel)
Validates that the title of the current html page matches the expected title

Parameters:
expectedText - expected text
assertLevel - - Only run this test under the assertLevel as described in AssertLevel

assertTextPresent

public void assertTextPresent(String msg,
                              String expectedText,
                              int assertLevel)
Validates that the title of the current html page matches the expected title If the test fails display the given message

Parameters:
msg - - The message to display if text is not in the response.
expectedText - expected text
assertLevel - - Only run this test under the assertLevel as described in AssertLevel

assertTitleEquals

public void assertTitleEquals(String expectedTitle)
Validates that the title of the current html page matches the expected title

Parameters:
expectedTitle - expected title value

assertTitleEquals

public void assertTitleEquals(String msg,
                              String expectedTitle)
Validates that the title of the current html page matches the expected title If the test fails display the given message

Parameters:
msg - - The message to display if text is not in the response.
expectedTitle - expected title value

assertTitleEquals

public void assertTitleEquals(String expectedTitle,
                              int assertLevel)
Validates that the title of the current html page matches the expected title

Parameters:
expectedTitle - expected title value
assertLevel - - Only run this test under the assertLevel as described in AssertLevel

assertTitleEquals

public void assertTitleEquals(String msg,
                              String expectedTitle,
                              int assertLevel)
Validates that the title of the current html page matches the expected title If the test fails display the given message

Parameters:
msg - - The message to display if text is not in the response.
expectedTitle - expected title value
assertLevel - - Only run this test under the assertLevel as described in AssertLevel

assertXPathMatches

public void assertXPathMatches(String xpath)
Validates that the provided xpath matches against the currently active page

Parameters:
xpath - The XPath to match

assertXPathMatches

public void assertXPathMatches(String msg,
                               String xpath)
Validates that the provided xpath matches against the currently active page If the test fails display the given message

Parameters:
msg - - The message to display if text is not in the response.
xpath - The XPath to match

assertXPathMatches

public void assertXPathMatches(String xpath,
                               int assertLevel)
Validates that the provided xpath matches against the currently active page

Parameters:
xpath - The XPath to match
assertLevel - - Only run this test under the assertLevel as described in AssertLevel

assertXPathMatches

public void assertXPathMatches(String msg,
                               String xpath,
                               int assertLevel)
Validates that the provided xpath matches against the currently active page If the test fails display the given message

Parameters:
msg - - The message to display if text is not in the response.
xpath - The XPath to match
assertLevel - - Only run this test under the assertLevel as described in AssertLevel

clickElementWithXPath

public void clickElementWithXPath(String xpath)
Clicks on the HTML element matching the provided XPath

Parameters:
xpath - - the XPath expression that defines the HTML element to click.

getHtmlForm

public HtmlForm getHtmlForm(String idNameIndexOrXpath)
This is a power method to get a form element by the following order.
  1. getHtmlFormById
  2. getHtmlFormByName
  3. getHtmlFormByIndex
  4. getHtmlElementByXPath

Parameters:
idNameIndexOrXpath - - The id, name, index or XPath expression defining the location of the form
Returns:
HtmlForm

getHtmlFormById

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

Parameters:
attributeValue - - 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 attributeValue)
Gets a form element back by its name attribute.

Parameters:
attributeValue - - 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

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

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.

getWorkingForm

public HtmlForm getWorkingForm()
Gets the current working form or null if one hasn't been set.

Returns:
HtmlForm - The current working form

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 checkbox to check
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

Parameters:
fieldName - - The name of the checkbox to check
fieldValue - - The value of the checkbox 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 = 0
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

setWorkingForm

public void setWorkingForm(String idNameIndexOrXpath)
Sets the working form to form with the given id This is a power method to set a form element by the following order.
  1. getHtmlFormById
  2. getHtmlFormByName
  3. getHtmlFormByIndex
  4. getHtmlElementByXPath

Parameters:
idNameIndexOrXpath - - The id, name, index or XPath expression defining the location of the form

setWorkingFormById

public void setWorkingFormById(String id)
Sets the working form to form with the given id

Parameters:
id - - The value of the form's HTML id attribute

setWorkingFormByIndex

public void setWorkingFormByIndex(int index)
Sets the working form to nth form on the current page. This method is useful when the form doesn't have a name or id attribute

Parameters:
index - - The number of form on the page. The first form would be 1

setWorkingFormByName

public void setWorkingFormByName(String name)
Sets the working form to nth form on the current page.

Parameters:
name - - The value of the name attribute in the form

setWorkingFormByXPath

public void setWorkingFormByXPath(String xpath)
Sets the working form by the matching XPath expression

Parameters:
xpath - - The XPath expression that matches the form to use


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