net.sourceforge.jwebunit
Class HttpUnitDialog

java.lang.Object
  |
  +--net.sourceforge.jwebunit.HttpUnitDialog

public class HttpUnitDialog
extends java.lang.Object

Acts as the wrapper for HttpUnit access. A dialog is initialized with a given URL, and maintains conversational state as the dialog progresses through link navigation, form submission, etc. Public access is provided for wrappered HttpUnit objects.

Author:
Jim Weaver, Wilkes Joiner

Constructor Summary
HttpUnitDialog(java.lang.String initialURL, TestContext context)
          Begin a dialog with an initial URL and test client context.
 
Method Summary
 void clickButton(java.lang.String buttonId)
          Click the indicated button (input type=button).
 void clickLink(java.lang.String anID)
          Navigate by submitting a request based on a link with a given ID.
 void clickLinkWithImage(java.lang.String imageFileName)
          Navigate by submitting a request based on a link with a given image file name.
 void clickLinkWithText(java.lang.String linkText)
          Navigate by submitting a request based on a link containing the specified text.
 com.meterware.httpunit.Button getButton(java.lang.String buttonId)
          Return the HttpUnit Button with a given id.
 org.w3c.dom.Element getElement(java.lang.String anID)
          Return the org.w3c.dom.Element in the current response by id.
 com.meterware.httpunit.WebForm getForm()
          Return the current form active for the dialog.
 java.lang.String getFormElementNameForLabel(java.lang.String formElementLabel)
          Return the name of a form parameter (input element) on the current response preceded by a givel label.
 java.lang.String getFormParameterValue(java.lang.String paramName)
          Return the current value of a form input element.
 com.meterware.httpunit.WebResponse getFrame(java.lang.String frameName)
          Return the response for the given frame in the current conversation.
 java.lang.String[] getOptionsFor(java.lang.String selectName)
          Return a string array of select box option labels.
 java.lang.String[] getOptionValuesFor(java.lang.String selectName)
          Return a string array of select box option values.
 com.meterware.httpunit.WebResponse getResponse()
          Return the HttpUnit object which represents the current response.
 java.lang.String getResponsePageTitle()
          Return the page title of the current response page, encoded as specified by the current TestContext.
 java.lang.String getResponseText()
          Return the string representation of the current response, encoded as specified by the current TestContext.
 java.lang.String getSelectedOption(java.lang.String selectName)
          Return the label of the currently selected item in a select box.
 java.lang.String[][] getSparseTableBySummaryOrId(java.lang.String tableSummaryOrId)
          Return a sparse array (rows or columns without displayable text are removed) for a given table in the response.
 com.meterware.httpunit.SubmitButton getSubmitButton(java.lang.String buttonName)
          Return the HttpUnit SubmitButton with a given name.
 java.lang.String getValueForOption(java.lang.String selectName, java.lang.String option)
          Get the value for a given option of a select box.
 com.meterware.httpunit.WebConversation getWebConversation()
          Return the HttpUnit WebConversation object for this dialog.
 com.meterware.httpunit.WebTable getWebTableBySummaryOrId(java.lang.String tableSummaryOrId)
          Return the HttpUnit WebTable object representing a specified table in the current response.
 com.meterware.httpunit.WebWindow getWindow(java.lang.String windowName)
          Return the window with the given name in the current conversation.
 void gotoFrame(java.lang.String frameName)
          Make the frame with the given name active in the current conversation.
 void gotoRootWindow()
          Make the root window in the current conversation active.
 void gotoWindow(java.lang.String windowName)
          Make the window with the given name in the current conversation active.
 boolean hasForm()
          Return true if the current response contains a form.
 boolean hasForm(java.lang.String nameOrID)
          Return true if the current response contains a specific form.
 boolean hasFormParameterLabeled(java.lang.String paramLabel)
          Return true if a form parameter (input element) is present on the current response preceded by a given label.
 boolean hasFormParameterNamed(java.lang.String paramName)
          Return true if a form parameter (input element) is present on the current response.
 boolean hasRadioOption(java.lang.String radioGroup, java.lang.String radioOption)
          Return true if a radio group contains the indicated option.
 boolean isLinkPresent(java.lang.String anId)
          Return true if a link is present in the current response with the specified id.
 boolean isLinkPresentWithImage(java.lang.String imageFileName)
          Return true if a link is present with a given image based on filename of image.
 boolean isLinkPresentWithText(java.lang.String linkText)
          Return true if a link is present in the current response containing the specified text (note that HttpUnit uses contains rather than an exact match - if this is a problem consider using ids on the links to uniquely identify them).
 boolean isTextInElement(org.w3c.dom.Element element, java.lang.String text)
          Return true if a given string is contained within the specified element.
 boolean isTextInResponse(java.lang.String text)
          Return true if given text is present anywhere in the current response.
 boolean isTextInTable(java.lang.String tableSummaryOrId, java.lang.String text)
          Return true if given text is present in a specified table of the response.
 void removeFormParameter(java.lang.String paramName)
          Specify that no parameter value should be submitted for a given input element.
 void reset()
          Reset the current form.
 void selectOption(java.lang.String selectName, java.lang.String option)
          Select an option of a select box by display label.
 void setFormParameter(java.lang.String paramName, java.lang.String paramValue)
          Set a form parameter / input element to the provided value.
 void setWorkingForm(java.lang.String nameOrId)
          Set the form on the current response that the client wishes to work with explicitly by either the form name or id (match by id is attempted first).
 void submit()
          Submit the current form with the default submit button.
 void submit(java.lang.String buttonName)
          Submit the current form with the specifed submit button.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpUnitDialog

public HttpUnitDialog(java.lang.String initialURL,
                      TestContext context)
Begin a dialog with an initial URL and test client context.
Parameters:
initialURL - absolute url at which to begin dialog.
context - contains context information for the test client.
Method Detail

getWebConversation

public com.meterware.httpunit.WebConversation getWebConversation()
Return the HttpUnit WebConversation object for this dialog.

getResponse

public com.meterware.httpunit.WebResponse getResponse()
Return the HttpUnit object which represents the current response.

getResponseText

public java.lang.String getResponseText()
Return the string representation of the current response, encoded as specified by the current TestContext.

getResponsePageTitle

public java.lang.String getResponsePageTitle()
Return the page title of the current response page, encoded as specified by the current TestContext.

getForm

public com.meterware.httpunit.WebForm getForm()

Return the current form active for the dialog. A form from the dialog's response is implicitly identified as active when an element from the form is inspected or set:

The active form can also be explicitly set by setWorkingForm(java.lang.String).

If this method is called without the form having been implicitly or explicitly set, it will attempt to return the default first form on the response.

Returns:
HttpUnit WebForm object representing the current active form from the response.
Throws:
UnableToSetFormException - This runtime assertion failure will be raised if there is no form on the response.

setWorkingForm

public void setWorkingForm(java.lang.String nameOrId)
Set the form on the current response that the client wishes to work with explicitly by either the form name or id (match by id is attempted first).
Parameters:
nameOrId - name or id of the form to be worked with.

hasForm

public boolean hasForm()
Return true if the current response contains a form.

hasForm

public boolean hasForm(java.lang.String nameOrID)
Return true if the current response contains a specific form.
Parameters:
nameOrID - name of id of the form to check for.

hasFormParameterNamed

public boolean hasFormParameterNamed(java.lang.String paramName)
Return true if a form parameter (input element) is present on the current response.
Parameters:
paramName - name of the input element to check for

setFormParameter

public void setFormParameter(java.lang.String paramName,
                             java.lang.String paramValue)
Set a form parameter / input element to the provided value.
Parameters:
paramName - name of the input element
paramValue - parameter value to submit for the element.

getFormParameterValue

public java.lang.String getFormParameterValue(java.lang.String paramName)
Return the current value of a form input element.
Parameters:
paramName - name of the input element.

removeFormParameter

public void removeFormParameter(java.lang.String paramName)
Specify that no parameter value should be submitted for a given input element. Typically used to uncheck check boxes.
Parameters:
paramName - name of the input element.

hasFormParameterLabeled

public boolean hasFormParameterLabeled(java.lang.String paramLabel)
Return true if a form parameter (input element) is present on the current response preceded by a given label.
Parameters:
paramLabel - label of the input element to check for

getFormElementNameForLabel

public java.lang.String getFormElementNameForLabel(java.lang.String formElementLabel)
Return the name of a form parameter (input element) on the current response preceded by a givel label.
Parameters:
formElementLabel - label of the input element to fetch name.

getSubmitButton

public com.meterware.httpunit.SubmitButton getSubmitButton(java.lang.String buttonName)
Return the HttpUnit SubmitButton with a given name.
Parameters:
buttonName - name of button.

getButton

public com.meterware.httpunit.Button getButton(java.lang.String buttonId)
Return the HttpUnit Button with a given id.
Parameters:
buttonId -  

isTextInResponse

public boolean isTextInResponse(java.lang.String text)
Return true if given text is present anywhere in the current response.
Parameters:
text - string to check for.

isTextInTable

public boolean isTextInTable(java.lang.String tableSummaryOrId,
                             java.lang.String text)
Return true if given text is present in a specified table of the response.
Parameters:
tableSummaryOrId - table summary or id to inspect for expected text.
text - expected text to check for.

getWebTableBySummaryOrId

public com.meterware.httpunit.WebTable getWebTableBySummaryOrId(java.lang.String tableSummaryOrId)
Return the HttpUnit WebTable object representing a specified table in the current response. Null is returned if a parsing exception occurs looking for the table or no table with the id or summary could be found.
Parameters:
tableSummaryOrId - summary or id of the table to return.

getSparseTableBySummaryOrId

public java.lang.String[][] getSparseTableBySummaryOrId(java.lang.String tableSummaryOrId)
Return a sparse array (rows or columns without displayable text are removed) for a given table in the response.
Parameters:
tableSummaryOrId - summary or id of the table.

submit

public void submit()
Submit the current form with the default submit button. See getForm() for an explanation of how the current form is established.

submit

public void submit(java.lang.String buttonName)
Submit the current form with the specifed submit button. See getForm() for an explanation of how the current form is established.
Parameters:
buttonName - name of the button to use for submission.

reset

public void reset()
Reset the current form. See getForm() for an explanation of how the current form is established.

isLinkPresentWithText

public boolean isLinkPresentWithText(java.lang.String linkText)
Return true if a link is present in the current response containing the specified text (note that HttpUnit uses contains rather than an exact match - if this is a problem consider using ids on the links to uniquely identify them).
Parameters:
linkText - text to check for in links on the response.

isLinkPresentWithImage

public boolean isLinkPresentWithImage(java.lang.String imageFileName)
Return true if a link is present with a given image based on filename of image.
Parameters:
imageFileName - A suffix of the image's filename; for example, to match "images/my_icon.png", you could just pass in "my_icon.png".

isLinkPresent

public boolean isLinkPresent(java.lang.String anId)
Return true if a link is present in the current response with the specified id.
Parameters:
anId - link id to check for.

clickLinkWithText

public void clickLinkWithText(java.lang.String linkText)
Navigate by submitting a request based on a link containing the specified text. A RuntimeException is thrown if no such link can be found.
Parameters:
linkText - text which link to be navigated should contain.

clickLink

public void clickLink(java.lang.String anID)
Navigate by submitting a request based on a link with a given ID. A RuntimeException is thrown if no such link can be found.
Parameters:
anID - id of link to be navigated.

clickLinkWithImage

public void clickLinkWithImage(java.lang.String imageFileName)
Navigate by submitting a request based on a link with a given image file name. A RuntimeException is thrown if no such link can be found.
Parameters:
imageFileName - A suffix of the image's filename; for example, to match "images/my_icon.png", you could just pass in "my_icon.png".

clickButton

public void clickButton(java.lang.String buttonId)
Click the indicated button (input type=button).
Parameters:
buttonId -  

hasRadioOption

public boolean hasRadioOption(java.lang.String radioGroup,
                              java.lang.String radioOption)
Return true if a radio group contains the indicated option.
Parameters:
radioGroup - name of the radio group.
radioOption - value of the option to check for.

getOptionsFor

public java.lang.String[] getOptionsFor(java.lang.String selectName)
Return a string array of select box option labels.
Parameters:
selectName - name of the select box.

getOptionValuesFor

public java.lang.String[] getOptionValuesFor(java.lang.String selectName)
Return a string array of select box option values.
Parameters:
selectName - name of the select box.

getSelectedOption

public java.lang.String getSelectedOption(java.lang.String selectName)
Return the label of the currently selected item in a select box.
Parameters:
selectName - name of the select box.

getValueForOption

public java.lang.String getValueForOption(java.lang.String selectName,
                                          java.lang.String option)
Get the value for a given option of a select box.
Parameters:
selectName - name of the select box.
option - label of the option.

selectOption

public void selectOption(java.lang.String selectName,
                         java.lang.String option)
Select an option of a select box by display label.
Parameters:
selectName - name of the select box.
option - label of the option to select.

getElement

public org.w3c.dom.Element getElement(java.lang.String anID)
Return the org.w3c.dom.Element in the current response by id.
Parameters:
anID - id of the element.

isTextInElement

public boolean isTextInElement(org.w3c.dom.Element element,
                               java.lang.String text)
Return true if a given string is contained within the specified element.
Parameters:
element - org.w3c.com.Element to inspect.
text - text to check for.

getWindow

public com.meterware.httpunit.WebWindow getWindow(java.lang.String windowName)
Return the window with the given name in the current conversation.
Parameters:
windowName -  

gotoWindow

public void gotoWindow(java.lang.String windowName)
Make the window with the given name in the current conversation active.
Parameters:
windowName -  

gotoRootWindow

public void gotoRootWindow()
Make the root window in the current conversation active.

gotoFrame

public void gotoFrame(java.lang.String frameName)
Make the frame with the given name active in the current conversation.
Parameters:
frameName -  

getFrame

public com.meterware.httpunit.WebResponse getFrame(java.lang.String frameName)
Return the response for the given frame in the current conversation.
Parameters:
frameName -  


Copyright © 2002 ThoughtWorks, Inc. All Rights Reserved.