public class

HtmlUnitDialog

extends Object
implements IJWebUnitDialog
java.lang.Object
   ↳ com.atlassian.confluence.htmlunit.HtmlUnitDialog
Known Direct Subclasses

Class Overview

An exact copy of net.sourceforge.jwebunit.htmlunit.HtmlUnitDialog from JWebUnit 1.4.1-atlassian-1, with some private methods and fields changed to protected to ConfluenceHtmlUnitDialog can override them. Don't change this class, except to change private methods or fields to protected.

Summary

Fields
protected LinkedList expectedJavascriptAlerts Javascript alerts.
protected LinkedList expectedJavascriptConfirms Javascript confirms.
protected LinkedList expectedJavascriptPrompts Javascript prompts.
protected HtmlForm form The currently selected form.
protected boolean jsEnabled Is Javascript enabled.
protected WebClient wc Encapsulate browser abilities.
protected WebWindow win The currently selected window.
Public Constructors
HtmlUnitDialog()
Public Methods
void beginAt(URL initialURL, TestContext context)
Begin a dialog with an initial URL and test client context.
void checkCheckbox(String checkBoxName, String value)
void checkCheckbox(String checkBoxName)
Select a specified checkbox.
void clickButton(String buttonId)
Click the indicated button (input type=button).
void clickButtonWithText(String buttonValueText)
void clickElementByXPath(String xpath)
void clickLink(String anID)
Navigate by submitting a request based on a link with a given ID.
void clickLinkWithExactText(String linkText, int index)
void clickLinkWithImage(String imageFileName, int index)
Navigate by submitting a request based on a link with a given image file name.
void clickLinkWithText(String linkText, int index)
void clickRadioOption(String radioGroup, String radioOption)
Clicks a radio option.
void closeBrowser()
void closeWindow()
HtmlButton getButtonWithText(String buttonValueText)
List getCookies()
String getCurrentPageTitle()
Return the page title of the current response page, encoded as specified by the current net.sourceforge.jwebunit.util.TestContext.
String getElementAttributByXPath(String xpath, String attribut)
String getElementTextByXPath(String xpath)
String getHiddenFieldValue(String paramName)
Return the current value of a hidden input element with name paramName.
HtmlTable getHtmlTable(String tableSummaryOrId)
Return the HttpUnit WebTable object representing a specified table in the current response.
InputStream getInputStream()
InputStream getInputStream(URL resourceUrl)
String getPageSource()
String getPageText()
String getPageTitle()
URL getPageURL()
HtmlResetInput getResetButton(String buttonName)
String getSelectOptionLabelForValue(String selectName, String value)
String getSelectOptionValueForLabel(String selectName, String label)
String[] getSelectOptionValues(String selectName)
Return a string array of select box option values.
String[] getSelectedOptions(String selectName)
String getSelectedRadio(String radioGroup)
String getServerResponse()
ClickableElement getSubmitButton(String buttonName)
Return the HtmlUnit submit button with a given name.
ClickableElement getSubmitButton(String buttonName, String buttonValue)
Return the HtmlUnit submit button with a given name and value.
Table getTable(String tableSummaryOrId)
String getTextFieldValue(String paramName)
Return the current value of a text input element with name paramName.
int getWindowCount()
void gotoFrame(String frameNameOrId)
void gotoPage(URL initialURL)
void gotoRootWindow()
Make the root window in the current conversation active.
void gotoWindow(String windowName)
Make the window with the given name in the current conversation active.
void gotoWindow(int windowID)
void gotoWindowByTitle(String title)
Goto first window with the given title.
boolean hasButton(String buttonId)
Returns if the button identified by buttonId is present.
boolean hasButtonWithText(String text)
Checks if a button with text is present.
boolean hasElement(String anID)
boolean hasElementByXPath(String xpath)
boolean hasForm()
Return true if the current response contains a form.
boolean hasForm(String nameOrID)
Return true if the current response contains a specific form.
boolean hasFormInputNamed(String inputName)
Return true if a form parameter (input element) is present on the current response.
boolean hasFormParameterNamed(String paramName)
boolean hasFormSelectNamed(String selectName)
Return true if a form parameter (input element) is present on the current response.
boolean hasFrame(String frameNameOrId)
boolean hasLink(String anId)
Return true if a link is present in the current response with the specified id.
boolean hasLinkWithExactText(String linkText, int index)
boolean hasLinkWithImage(String imageFileName, int index)
boolean hasLinkWithText(String linkText, int index)
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 hasRadioOption(String radioGroup, String radioOption)
Return true if a radio group contains the indicated option.
boolean hasResetButton()
boolean hasResetButton(String buttonName)
boolean hasSelectOption(String selectName, String optionLabel)
Return true if a select box contains the indicated option.
boolean hasSelectOptionValue(String selectName, String optionValue)
Return true if a select box contains the indicated option.
boolean hasSubmitButton(String buttonName, String buttonValue)
boolean hasSubmitButton(String buttonName)
boolean hasSubmitButton()
boolean hasTable(String tableSummaryOrId)
boolean hasWindow(String windowName)
boolean hasWindowByTitle(String title)
boolean isCheckboxSelected(String checkBoxName, String checkBoxValue)
boolean isCheckboxSelected(String checkBoxName)
boolean isMatchInElement(String elementID, String regexp)
boolean isTextInElement(String elementID, String text)
boolean isTextInTable(String tableSummaryOrId, String text)
Return true if given text is present in a specified table of the response.
void reset()
Reset the current form.
void selectOptions(String selectName, String[] options)
void setExpectedJavaScriptAlert(JavascriptAlert[] alerts)
void setExpectedJavaScriptConfirm(JavascriptConfirm[] confirms)
void setExpectedJavaScriptPrompt(JavascriptPrompt[] prompts)
void setScriptingEnabled(boolean value)
void setTextField(String fieldName, String text)
Set a form text, password input element or textarea to the provided value.
void setWorkingForm(int index)
void setWorkingForm(String nameOrId, int index)
void submit()
Submit the current form with the default submit button.
void submit(String buttonName, String buttonValue)
Submit the current form with the specifed submit button (by name and value).
void submit(String buttonName)
Submit the current form with the specifed submit button.
void uncheckCheckbox(String checkBoxName, String value)
void uncheckCheckbox(String checkBoxName)
Deselect a specified checkbox.
void unselectOptions(String selectName, String[] options)
Protected Methods
HtmlPage getCurrentPage()
HtmlElement getElement(String anID)
HtmlForm getForm()

Return the current form active for the dialog.

TestContext getTestContext()
void initWebClient()
[Expand]
Inherited Methods
From class java.lang.Object
From interface net.sourceforge.jwebunit.api.IJWebUnitDialog

Fields

protected LinkedList expectedJavascriptAlerts

Javascript alerts.

protected LinkedList expectedJavascriptConfirms

Javascript confirms.

protected LinkedList expectedJavascriptPrompts

Javascript prompts.

protected HtmlForm form

The currently selected form.

protected boolean jsEnabled

Is Javascript enabled.

protected WebClient wc

Encapsulate browser abilities.

protected WebWindow win

The currently selected window.

Public Constructors

public HtmlUnitDialog ()

Public Methods

public void beginAt (URL 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.
Throws
TestingEngineResponseException

public void checkCheckbox (String checkBoxName, String value)

public void checkCheckbox (String checkBoxName)

Select a specified checkbox. If the checkbox is already checked then the checkbox will stay checked.

Parameters
checkBoxName name of checkbox to be deselected.

public void clickButton (String buttonId)

Click the indicated button (input type=button).

public void clickButtonWithText (String buttonValueText)

public void clickElementByXPath (String xpath)

public void clickLink (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.

public void clickLinkWithExactText (String linkText, int index)

public void clickLinkWithImage (String imageFileName, int index)

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".

public void clickLinkWithText (String linkText, int index)

public void clickRadioOption (String radioGroup, String radioOption)

Clicks a radio option. Asserts that the radio option exists first. *

Parameters
radioGroup name of the radio group.
radioOption value of the option to check for.

public void closeBrowser ()

Throws
ExpectedJavascriptAlertException
ExpectedJavascriptConfirmException
ExpectedJavascriptPromptException

public void closeWindow ()

public HtmlButton getButtonWithText (String buttonValueText)

public List getCookies ()

public String getCurrentPageTitle ()

Return the page title of the current response page, encoded as specified by the current net.sourceforge.jwebunit.util.TestContext.

public String getElementAttributByXPath (String xpath, String attribut)

public String getElementTextByXPath (String xpath)

public String getHiddenFieldValue (String paramName)

Return the current value of a hidden input element with name paramName.

Parameters
paramName name of the input element. TODO: Find a way to handle multiple hidden input element with same name.

public HtmlTable getHtmlTable (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. tableSummaryOrId can also match on the class of a table if its unique.

Parameters
tableSummaryOrId summary, class or id of the table to return.

public InputStream getInputStream ()

public InputStream getInputStream (URL resourceUrl)

Throws
TestingEngineResponseException

public String getPageSource ()

public String getPageText ()

public String getPageTitle ()

public URL getPageURL ()

public HtmlResetInput getResetButton (String buttonName)

public String getSelectOptionLabelForValue (String selectName, String value)

public String getSelectOptionValueForLabel (String selectName, String label)

public String[] getSelectOptionValues (String selectName)

Return a string array of select box option values.

Parameters
selectName name of the select box.

public String[] getSelectedOptions (String selectName)

public String getSelectedRadio (String radioGroup)

public String getServerResponse ()

public ClickableElement getSubmitButton (String buttonName)

Return the HtmlUnit submit button with a given name.

Parameters
buttonName name of button.
Returns
  • the button

public ClickableElement getSubmitButton (String buttonName, String buttonValue)

Return the HtmlUnit submit button with a given name and value.

Parameters
buttonName button name.
buttonValue button value.
Returns
  • HtmlSubmitInput, HtmlImageInput or HtmlButton

public Table getTable (String tableSummaryOrId)

public String getTextFieldValue (String paramName)

Return the current value of a text input element with name paramName.

Parameters
paramName name of the input element. TODO: Find a way to handle multiple text input element with same name.

public int getWindowCount ()

public void gotoFrame (String frameNameOrId)

public void gotoPage (URL initialURL)

Throws
TestingEngineResponseException

public void gotoRootWindow ()

Make the root window in the current conversation active.

public void gotoWindow (String windowName)

Make the window with the given name in the current conversation active.

public void gotoWindow (int windowID)

public void gotoWindowByTitle (String title)

Goto first window with the given title.

public boolean hasButton (String buttonId)

Returns if the button identified by buttonId is present.

Parameters
buttonId the id of the button
Returns
  • true when the button was found.

public boolean hasButtonWithText (String text)

Checks if a button with text is present.

Parameters
text the text of the button (between <button></button>).
Returns
  • true when the button with text could be found.

public boolean hasElement (String anID)

public boolean hasElementByXPath (String xpath)

public boolean hasForm ()

Return true if the current response contains a form.

public boolean hasForm (String nameOrID)

Return true if the current response contains a specific form.

Parameters
nameOrID name of id of the form to check for.

public boolean hasFormInputNamed (String inputName)

Return true if a form parameter (input element) is present on the current response.

Parameters
inputName name of the input element to check for

public boolean hasFormParameterNamed (String paramName)

public boolean hasFormSelectNamed (String selectName)

Return true if a form parameter (input element) is present on the current response.

Parameters
selectName name of the input element to check for

public boolean hasFrame (String frameNameOrId)

public boolean hasLink (String anId)

Return true if a link is present in the current response with the specified id.

Parameters
anId link id to check for.

public boolean hasLinkWithExactText (String linkText, int index)

public boolean hasLinkWithImage (String imageFileName, int index)

public boolean hasLinkWithText (String linkText, int index)

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.
index The 0-based index, when more than one link with the same text is expected.

public boolean hasRadioOption (String radioGroup, 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.

public boolean hasResetButton ()

public boolean hasResetButton (String buttonName)

public boolean hasSelectOption (String selectName, String optionLabel)

Return true if a select box contains the indicated option.

Parameters
selectName name of the select box.
optionLabel label of the option.

public boolean hasSelectOptionValue (String selectName, String optionValue)

Return true if a select box contains the indicated option.

Parameters
selectName name of the select box.
optionValue value of the option.

public boolean hasSubmitButton (String buttonName, String buttonValue)

public boolean hasSubmitButton (String buttonName)

public boolean hasSubmitButton ()

public boolean hasTable (String tableSummaryOrId)

public boolean hasWindow (String windowName)

public boolean hasWindowByTitle (String title)

public boolean isCheckboxSelected (String checkBoxName, String checkBoxValue)

public boolean isCheckboxSelected (String checkBoxName)

public boolean isMatchInElement (String elementID, String regexp)

public boolean isTextInElement (String elementID, String text)

public boolean isTextInTable (String tableSummaryOrId, 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.

public void reset ()

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

public void selectOptions (String selectName, String[] options)

public void setExpectedJavaScriptAlert (JavascriptAlert[] alerts)

Throws
ExpectedJavascriptAlertException

public void setExpectedJavaScriptConfirm (JavascriptConfirm[] confirms)

Throws
ExpectedJavascriptConfirmException

public void setExpectedJavaScriptPrompt (JavascriptPrompt[] prompts)

Throws
ExpectedJavascriptPromptException

public void setScriptingEnabled (boolean value)

public void setTextField (String fieldName, String text)

Set a form text, password input element or textarea to the provided value.

Parameters
fieldName name of the input element or textarea
text parameter value to submit for the element.

public void setWorkingForm (int index)

public void setWorkingForm (String nameOrId, int index)

public void submit ()

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

public void submit (String buttonName, String buttonValue)

Submit the current form with the specifed submit button (by name and value). See getForm()for an explanation of how the current form is established.

Parameters
buttonName name of the button to use for submission.
buttonValue value/label of the button to use for submission

public void submit (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.

public void uncheckCheckbox (String checkBoxName, String value)

public void uncheckCheckbox (String checkBoxName)

Deselect a specified checkbox. If the checkbox is already unchecked then the checkbox will stay unchecked.

Parameters
checkBoxName name of checkbox to be deselected.

public void unselectOptions (String selectName, String[] options)

Protected Methods

protected HtmlPage getCurrentPage ()

protected HtmlElement getElement (String anID)

protected HtmlForm getForm ()

Return the current form active for the dialog.

The active form can also be explicitly set by setWorkingForm(int).

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 page.

Returns
  • HtmlForm 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.

protected TestContext getTestContext ()

Returns
  • Returns the testContext.

protected void initWebClient ()