public class HtmlUnitTestingEngineImpl extends Object implements ITestingEngine
| Constructor and Description |
|---|
HtmlUnitTestingEngineImpl()
Initializes default HtmlUnit testing engine implementation.
|
| Modifier and Type | Method and Description |
|---|---|
void |
beginAt(URL initialURL,
TestContext context)
Begin a dialog with an initial URL and test client context.
|
void |
checkCheckbox(String checkBoxName)
Select a specified checkbox.
|
void |
checkCheckbox(String checkBoxName,
String value) |
void |
clickButton(String buttonId)
Click the indicated button (input type=button).
|
void |
clickButtonWithText(String buttonValueText)
Clicks the first button that contains the specified text as its label.
|
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()
Close the browser and check that all expected Javascript alerts, confirms and
prompts have been taken care of.
|
void |
closeWindow()
Close the current window.
|
protected com.gargoylesoftware.htmlunit.WebClient |
createWebClient()
Create the
WebClient that will be used for this test. |
Map<String,String> |
getAllHeaders()
Deprecated.
|
com.gargoylesoftware.htmlunit.html.HtmlElement |
getButtonWithText(String buttonValueText)
Returns the first button that contains the specified text as its label.
|
List<String> |
getComments()
Get all the comments in a document, as a list of strings.
|
List<javax.servlet.http.Cookie> |
getCookies() |
protected com.gargoylesoftware.htmlunit.html.HtmlPage |
getCurrentPage() |
String |
getCurrentPageTitle()
Return the page title of the current response page, encoded as specified by the current
TestContext. |
com.gargoylesoftware.htmlunit.WebWindow |
getCurrentWindow()
Return the currently opened window (issue 2697234).
|
com.gargoylesoftware.htmlunit.BrowserVersion |
getDefaultBrowserVersion()
An alternative to setting the
user agent string manually
is to provide it with all the information for a complete browser version. |
String |
getElementAttributByXPath(String xpath,
String attribut) |
IElement |
getElementByID(String id) |
IElement |
getElementByXPath(String xpath) |
List<IElement> |
getElementsByXPath(String xpath) |
String |
getElementTextByXPath(String xpath) |
protected com.gargoylesoftware.htmlunit.html.HtmlForm |
getForm()
Return the current form active for the dialog.
|
String |
getHeader(String name) |
String |
getHiddenFieldValue(String paramName)
Return the current value of a hidden input element with name
paramName. |
InputStream |
getInputStream() |
InputStream |
getInputStream(URL resourceUrl) |
String |
getPageSource() |
String |
getPageText() |
String |
getPageTitle() |
URL |
getPageURL() |
com.gargoylesoftware.htmlunit.html.HtmlElement |
getResetButton(String buttonName) |
List<HttpHeader> |
getResponseHeaders() |
String[] |
getSelectedOptions(String selectName) |
String[] |
getSelectedOptions(String selectName,
int index) |
String |
getSelectedRadio(String radioGroup) |
String |
getSelectOptionLabelForValue(String selectName,
int index,
String value) |
String |
getSelectOptionLabelForValue(String selectName,
String value) |
String |
getSelectOptionValueForLabel(String selectName,
int index,
String label) |
String |
getSelectOptionValueForLabel(String selectName,
String label) |
String[] |
getSelectOptionValues(String selectName)
Return a string array of select box option values.
|
String[] |
getSelectOptionValues(String selectName,
int index)
Return a string array of the Nth select box option values.
|
String |
getServerResponse() |
int |
getServerResponseCode() |
com.gargoylesoftware.htmlunit.html.HtmlElement |
getSubmitButton(String buttonName)
Return the HtmlUnit submit button with a given name.
|
com.gargoylesoftware.htmlunit.html.HtmlElement |
getSubmitButton(String buttonName,
String buttonValue)
Return the HtmlUnit submit button with a given name and value.
|
Table |
getTable(String tableSummaryNameOrId) |
protected TestContext |
getTestContext() |
String |
getTextFieldValue(String paramName)
Return the current value of a text input element with name
paramName. |
com.gargoylesoftware.htmlunit.WebClient |
getWebClient()
Return the current web client (issue 2697234).
|
com.gargoylesoftware.htmlunit.WebResponse |
getWebResponse()
Get the last WebResponse from HtmlUnit.
|
com.gargoylesoftware.htmlunit.WebWindow |
getWindow(String windowName)
Return the window with the given name in the current conversation.
|
int |
getWindowCount() |
void |
gotoFrame(String frameNameOrId) |
void |
gotoPage(URL initialURL)
Go to a particular page.
|
void |
gotoRootWindow() |
void |
gotoWindow(int windowID) |
void |
gotoWindow(String windowName)
Make the window with the given name in the current conversation active.
|
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 whether a button containing the specified text as its label exists.
|
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 |
hasForm(String nameOrID,
int index) |
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,
int index,
String optionLabel)
Return true if the Nth select box contains the indicated option.
|
boolean |
hasSelectOption(String selectName,
String optionLabel)
Return true if a select box contains the indicated option.
|
boolean |
hasSelectOptionValue(String selectName,
int index,
String optionValue)
Return true if the Nth select box contains the indicated option.
|
boolean |
hasSelectOptionValue(String selectName,
String optionValue)
Return true if a select box contains the indicated option.
|
boolean |
hasSubmitButton() |
boolean |
hasSubmitButton(String buttonName) |
boolean |
hasSubmitButton(String buttonName,
String buttonValue) |
boolean |
hasTable(String tableSummaryNameOrId) |
boolean |
hasWindow(String windowName) |
boolean |
hasWindowByTitle(String title) |
boolean |
isCheckboxSelected(String checkBoxName) |
boolean |
isCheckboxSelected(String checkBoxName,
String checkBoxValue) |
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,
int index,
String[] options)
Select the specified set of options in the select element
with the provided name.
|
void |
selectOptions(String selectName,
String[] options)
Select the specified set of options in the select element
with the provided name.
|
void |
setDefaultBrowserVersion(com.gargoylesoftware.htmlunit.BrowserVersion defaultBrowserVersion)
An alternative to setting the
user agent string manually
is to provide it with all the information for a complete browser version. |
void |
setExpectedJavaScriptAlert(JavascriptAlert[] alerts) |
void |
setExpectedJavaScriptConfirm(JavascriptConfirm[] confirms) |
void |
setExpectedJavaScriptPrompt(JavascriptPrompt[] prompts) |
void |
setHiddenField(String fieldName,
String text)
Set a form hidden element to the provided value.
|
void |
setIgnoreFailingStatusCodes(boolean ignore) |
void |
setRefreshHandler(com.gargoylesoftware.htmlunit.RefreshHandler handler) |
void |
setScriptingEnabled(boolean value) |
void |
setTextField(String paramName,
String text)
Set a form text, password input element or textarea to the provided value.
|
void |
setThrowExceptionOnScriptError(boolean value) |
void |
setTimeout(int milliseconds) |
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)
Submit the current form with the specified submit button.
|
void |
submit(String buttonName,
String buttonValue)
Submit the current form with the specifed submit button (by name and value).
|
void |
uncheckCheckbox(String checkBoxName)
Deselect a specified checkbox.
|
void |
uncheckCheckbox(String checkBoxName,
String value) |
void |
unselectOptions(String selectName,
int index,
String[] options) |
void |
unselectOptions(String selectName,
String[] options) |
public HtmlUnitTestingEngineImpl()
public void beginAt(URL initialURL, TestContext context) throws TestingEngineResponseException
beginAt in interface ITestingEngineinitialURL - absolute url at which to begin dialog.context - contains context information for the test client.TestingEngineResponseExceptionpublic void closeBrowser()
throws ExpectedJavascriptAlertException,
ExpectedJavascriptConfirmException,
ExpectedJavascriptPromptException
closeBrowser in interface ITestingEngineExpectedJavascriptAlertExceptionExpectedJavascriptConfirmExceptionExpectedJavascriptPromptExceptionpublic void gotoPage(URL initialURL) throws TestingEngineResponseException
gotoPage in interface ITestingEngineTestingEngineResponseException - if an error response code is encountered
and ignoreFailingStatusCodes is not enabled.public void setScriptingEnabled(boolean value)
setScriptingEnabled in interface ITestingEngineIJWebUnitDialogpublic void setThrowExceptionOnScriptError(boolean value)
setThrowExceptionOnScriptError in interface ITestingEnginepublic List<javax.servlet.http.Cookie> getCookies()
getCookies in interface ITestingEnginepublic boolean hasWindow(String windowName)
hasWindow in interface ITestingEnginepublic boolean hasWindowByTitle(String title)
hasWindowByTitle in interface ITestingEnginepublic void gotoWindow(String windowName)
gotoWindow in interface ITestingEnginewindowName - public void gotoWindow(int windowID)
gotoWindow in interface ITestingEnginepublic int getWindowCount()
getWindowCount in interface ITestingEnginepublic void gotoWindowByTitle(String title)
gotoWindowByTitle in interface ITestingEnginetitle - public void closeWindow()
closeWindow in interface ITestingEnginepublic boolean hasFrame(String frameNameOrId)
hasFrame in interface ITestingEnginepublic void gotoFrame(String frameNameOrId)
gotoFrame in interface ITestingEnginepublic void setWorkingForm(int index)
setWorkingForm in interface ITestingEnginepublic void setWorkingForm(String nameOrId, int index)
setWorkingForm in interface ITestingEnginepublic boolean hasForm()
hasForm in interface ITestingEnginepublic boolean hasForm(String nameOrID)
hasForm in interface ITestingEnginenameOrID - name of id of the form to check for.public boolean hasForm(String nameOrID, int index)
hasForm in interface ITestingEnginepublic boolean hasFormParameterNamed(String paramName)
hasFormParameterNamed in interface ITestingEnginepublic String getTextFieldValue(String paramName)
paramName.getTextFieldValue in interface ITestingEngineparamName - name of the input element. TODO: Find a way to handle multiple text input element with same
name.public String getHiddenFieldValue(String paramName)
paramName.getHiddenFieldValue in interface ITestingEngineparamName - name of the input element. TODO: Find a way to handle multiple hidden input element with same
name.public void setTextField(String paramName, String text)
setTextField in interface ITestingEnginefieldName - name of the input element or textareatext - parameter value to submit for the element.public void setHiddenField(String fieldName, String text)
setHiddenField in interface ITestingEnginefieldName - name of the hidden input elementparamValue - parameter value to submit for the element.public String[] getSelectOptionValues(String selectName)
getSelectOptionValues in interface ITestingEngineselectName - name of the select box.public String[] getSelectOptionValues(String selectName, int index)
getSelectOptionValues in interface ITestingEngineselectName - name of the select box.index - the 0-based index when more than one
select with the same name is expected.public String[] getSelectedOptions(String selectName)
getSelectedOptions in interface ITestingEnginepublic String[] getSelectedOptions(String selectName, int index)
getSelectedOptions in interface ITestingEnginepublic String getSelectOptionValueForLabel(String selectName, String label)
getSelectOptionValueForLabel in interface ITestingEnginepublic String getSelectOptionValueForLabel(String selectName, int index, String label)
getSelectOptionValueForLabel in interface ITestingEnginepublic String getSelectOptionLabelForValue(String selectName, String value)
getSelectOptionLabelForValue in interface ITestingEnginepublic String getSelectOptionLabelForValue(String selectName, int index, String value)
getSelectOptionLabelForValue in interface ITestingEnginepublic URL getPageURL()
getPageURL in interface ITestingEnginepublic String getPageSource()
getPageSource in interface ITestingEnginepublic String getPageTitle()
getPageTitle in interface ITestingEnginepublic String getPageText()
getPageText in interface ITestingEnginepublic String getServerResponse()
getServerResponse in interface ITestingEnginepublic InputStream getInputStream()
getInputStream in interface ITestingEnginepublic InputStream getInputStream(URL resourceUrl) throws TestingEngineResponseException
getInputStream in interface ITestingEngineTestingEngineResponseExceptionprotected com.gargoylesoftware.htmlunit.WebClient createWebClient()
WebClient that will be used for this test.
Subclasses should only override this method if they need to override
the default WebClient.
Also see issue 2697234.
WebClientpublic com.gargoylesoftware.htmlunit.WebWindow getWindow(String windowName)
windowName - com.gargoylesoftware.htmlunit.WebWindowNotFoundException - if the window could not be foundpublic com.gargoylesoftware.htmlunit.WebWindow getCurrentWindow()
public com.gargoylesoftware.htmlunit.WebClient getWebClient()
public List<String> getComments()
getComments in interface ITestingEnginepublic String getCurrentPageTitle()
TestContext.protected com.gargoylesoftware.htmlunit.html.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.
UnableToSetFormException - This runtime assertion failure will be raised if there is no form on the
response.protected com.gargoylesoftware.htmlunit.html.HtmlPage getCurrentPage()
public boolean hasFormSelectNamed(String selectName)
selectName - name of the input element to check forpublic com.gargoylesoftware.htmlunit.html.HtmlElement getSubmitButton(String buttonName)
buttonName - name of button.public com.gargoylesoftware.htmlunit.html.HtmlElement getResetButton(String buttonName)
public com.gargoylesoftware.htmlunit.html.HtmlElement getSubmitButton(String buttonName, String buttonValue)
buttonName - button name.buttonValue - button value.public boolean hasSubmitButton()
hasSubmitButton in interface ITestingEnginepublic boolean hasSubmitButton(String buttonName)
hasSubmitButton in interface ITestingEnginepublic boolean hasSubmitButton(String buttonName, String buttonValue)
hasSubmitButton in interface ITestingEnginepublic boolean hasResetButton()
hasResetButton in interface ITestingEnginepublic boolean hasResetButton(String buttonName)
hasResetButton in interface ITestingEnginepublic boolean hasButtonWithText(String text)
This method does not check whether the button is currently visible to the client.
hasButtonWithText in interface ITestingEnginetext - the text of the button (between <button></button>)
or the value of the "value" attribute.true when the button with text could be found.public com.gargoylesoftware.htmlunit.html.HtmlElement getButtonWithText(String buttonValueText)
This method does not check whether the button is currently visible to the client.
buttonValueText - the text of the button (between <button></button>)
or the value of the "value" attribute.public boolean hasButton(String buttonId)
buttonId is present.hasButton in interface ITestingEnginebuttonId - the id of the buttontrue when the button was found.public boolean isCheckboxSelected(String checkBoxName)
isCheckboxSelected in interface ITestingEnginepublic boolean isCheckboxSelected(String checkBoxName, String checkBoxValue)
isCheckboxSelected in interface ITestingEnginepublic boolean isTextInTable(String tableSummaryOrId, String text)
tableSummaryOrId - table summary or id to inspect for expected text.text - expected text to check for.public Table getTable(String tableSummaryNameOrId)
getTable in interface ITestingEnginepublic boolean hasTable(String tableSummaryNameOrId)
hasTable in interface ITestingEnginepublic void submit()
getForm()for an explanation of how the
current form is established.submit in interface ITestingEnginepublic void submit(String buttonName)
getForm()for an explanation of how the
current form is established.submit in interface ITestingEnginebuttonName - name of the button to use for submission.public void submit(String buttonName, String buttonValue)
getForm()for an
explanation of how the current form is established.submit in interface ITestingEnginebuttonName - name of the button to use for submission.buttonValue - value/label of the button to use for submissionpublic void reset()
getForm()for an explanation of how the current form is established.reset in interface ITestingEnginepublic boolean hasLinkWithText(String linkText, int index)
hasLinkWithText in interface ITestingEnginelinkText - 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 hasLinkWithExactText(String linkText, int index)
hasLinkWithExactText in interface ITestingEnginepublic boolean hasLinkWithImage(String imageFileName, int index)
hasLinkWithImage in interface ITestingEnginepublic boolean hasLink(String anId)
hasLink in interface ITestingEngineanId - link id to check for.public void clickLinkWithText(String linkText, int index)
clickLinkWithText in interface ITestingEnginepublic void clickLinkWithExactText(String linkText, int index)
clickLinkWithExactText in interface ITestingEnginepublic void checkCheckbox(String checkBoxName)
checkCheckbox in interface ITestingEnginecheckBoxName - name of checkbox to be deselected.public void checkCheckbox(String checkBoxName, String value)
checkCheckbox in interface ITestingEnginepublic void uncheckCheckbox(String checkBoxName)
uncheckCheckbox in interface ITestingEnginecheckBoxName - name of checkbox to be deselected.public void uncheckCheckbox(String checkBoxName, String value)
uncheckCheckbox in interface ITestingEnginepublic void clickRadioOption(String radioGroup, String radioOption)
clickRadioOption in interface ITestingEngineradioGroup - name of the radio group.radioOption - value of the option to check for.public void clickLink(String anID)
clickLink in interface ITestingEngineanID - id of link to be navigated.public void clickLinkWithImage(String imageFileName, int index)
clickLinkWithImage in interface ITestingEngineimageFileName - A suffix of the image's filename; for example, to match
"images/my_icon.png", you could just pass in
"my_icon.png".public boolean hasElement(String anID)
hasElement in interface ITestingEnginepublic boolean hasElementByXPath(String xpath)
hasElementByXPath in interface ITestingEnginepublic void clickElementByXPath(String xpath)
clickElementByXPath in interface ITestingEnginepublic String getElementAttributByXPath(String xpath, String attribut)
getElementAttributByXPath in interface ITestingEnginepublic String getElementTextByXPath(String xpath)
getElementTextByXPath in interface ITestingEnginepublic void clickButton(String buttonId)
clickButton in interface ITestingEnginebuttonId - public void clickButtonWithText(String buttonValueText)
clickButtonWithText in interface ITestingEnginepublic boolean hasRadioOption(String radioGroup, String radioOption)
hasRadioOption in interface ITestingEngineradioGroup - name of the radio group.radioOption - value of the option to check for.public String getSelectedRadio(String radioGroup)
getSelectedRadio in interface ITestingEnginepublic boolean hasSelectOption(String selectName, String optionLabel)
hasSelectOption in interface ITestingEngineselectName - name of the select box.optionLabel - label of the option.public boolean hasSelectOptionValue(String selectName, String optionValue)
hasSelectOptionValue in interface ITestingEngineselectName - name of the select box.optionValue - value of the option.public void selectOptions(String selectName, String[] options)
selectOptions in interface ITestingEngineselectName - name of the select boxoptions - set of options to select.public boolean hasSelectOption(String selectName, int index, String optionLabel)
hasSelectOption in interface ITestingEngineselectName - name of the select box.index - the 0-based index of the select element when multiple
select elements are expected.optionLabel - label of the option.public boolean hasSelectOptionValue(String selectName, int index, String optionValue)
hasSelectOptionValue in interface ITestingEngineselectName - name of the select box.index - the 0-based index of the select element when multiple
select elements are expected.optionValue - value of the option.public void selectOptions(String selectName, int index, String[] options)
selectOptions in interface ITestingEngineselectName - name of the select boxindex - the 0-based index of the select element when multiple
select elements are expected.options - set of options to select.public void unselectOptions(String selectName, String[] options)
unselectOptions in interface ITestingEnginepublic void unselectOptions(String selectName, int index, String[] options)
unselectOptions in interface ITestingEnginepublic boolean isTextInElement(String elementID, String text)
isTextInElement in interface ITestingEnginepublic boolean isMatchInElement(String elementID, String regexp)
isMatchInElement in interface ITestingEnginepublic void gotoRootWindow()
gotoRootWindow in interface ITestingEngineprotected TestContext getTestContext()
public void setExpectedJavaScriptAlert(JavascriptAlert[] alerts) throws ExpectedJavascriptAlertException
setExpectedJavaScriptAlert in interface ITestingEngineExpectedJavascriptAlertExceptionpublic void setExpectedJavaScriptConfirm(JavascriptConfirm[] confirms) throws ExpectedJavascriptConfirmException
setExpectedJavaScriptConfirm in interface ITestingEngineExpectedJavascriptConfirmExceptionpublic void setExpectedJavaScriptPrompt(JavascriptPrompt[] prompts) throws ExpectedJavascriptPromptException
setExpectedJavaScriptPrompt in interface ITestingEngineExpectedJavascriptPromptExceptionpublic IElement getElementByXPath(String xpath)
getElementByXPath in interface ITestingEnginepublic IElement getElementByID(String id)
getElementByID in interface ITestingEnginepublic List<IElement> getElementsByXPath(String xpath)
getElementsByXPath in interface ITestingEnginepublic int getServerResponseCode()
getServerResponseCode in interface ITestingEnginepublic com.gargoylesoftware.htmlunit.WebResponse getWebResponse()
public void setIgnoreFailingStatusCodes(boolean ignore)
setIgnoreFailingStatusCodes in interface ITestingEnginepublic String getHeader(String name)
getHeader in interface ITestingEngine@Deprecated public Map<String,String> getAllHeaders()
getAllHeaders in interface ITestingEnginepublic List<HttpHeader> getResponseHeaders()
getResponseHeaders in interface ITestingEnginepublic com.gargoylesoftware.htmlunit.BrowserVersion getDefaultBrowserVersion()
user agent string manually
is to provide it with all the information for a complete browser version.BrowserVersionpublic void setDefaultBrowserVersion(com.gargoylesoftware.htmlunit.BrowserVersion defaultBrowserVersion)
user agent string manually
is to provide it with all the information for a complete browser version.the - browser version to set as default for this engine instanceBrowserVersionpublic void setTimeout(int milliseconds)
setTimeout in interface ITestingEnginepublic void setRefreshHandler(com.gargoylesoftware.htmlunit.RefreshHandler handler)
Copyright © 2002–2015 JWebUnit. All rights reserved.