net.sourceforge.jwebunit.htmlunit
Class HtmlUnitTestingEngineImpl

java.lang.Object
  extended by net.sourceforge.jwebunit.htmlunit.HtmlUnitTestingEngineImpl
All Implemented Interfaces:
ITestingEngine

public class HtmlUnitTestingEngineImpl
extends java.lang.Object
implements ITestingEngine

Acts as the wrapper for HtmlUnit access. A testing engine is initialized with a given URL, and maintains conversational state as the dialog progresses through link navigation, form submission, etc.

Author:
Julien Henry

Constructor Summary
HtmlUnitTestingEngineImpl()
          Initializes default HtmlUnit testing engine implementation.
 
Method Summary
 void beginAt(java.net.URL initialURL, TestContext context)
          Begin a dialog with an initial URL and test client context.
 void checkCheckbox(java.lang.String checkBoxName)
          Select a specified checkbox.
 void checkCheckbox(java.lang.String checkBoxName, java.lang.String value)
          Select a specified checkbox.
 void clickButton(java.lang.String buttonId)
          Click the indicated button (input type=button).
 void clickButtonWithText(java.lang.String buttonValueText)
          Clicks the first button that contains the specified text as its label.
 void clickElementByXPath(java.lang.String xpath)
          Click element with given xpath.
 void clickLink(java.lang.String anID)
          Navigate by submitting a request based on a link with a given ID.
 void clickLinkWithExactText(java.lang.String linkText, int index)
          Navigate by clicking a link with the exact specified text.
 void clickLinkWithImage(java.lang.String imageFileName, int index)
          Navigate by submitting a request based on a link with a given image file name.
 void clickLinkWithText(java.lang.String linkText, int index)
          Navigate by submitting a request based on a link containing the specified text.
 void clickRadioOption(java.lang.String radioGroup, java.lang.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.
 java.util.Map<java.lang.String,java.lang.String> getAllHeaders()
          Get all headers.
 com.gargoylesoftware.htmlunit.html.HtmlElement getButtonWithText(java.lang.String buttonValueText)
          Returns the first button that contains the specified text as its label.
 java.util.List<java.lang.String> getComments()
          Get all the comments in a document, as a list of strings.
 java.util.List<javax.servlet.http.Cookie> getCookies()
          Get all cookies.
 java.lang.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.
 java.lang.String getElementAttributByXPath(java.lang.String xpath, java.lang.String attribut)
          Get attribut value of the given element.
 IElement getElementByID(java.lang.String id)
          Get an element wrapper for a given ID.
 IElement getElementByXPath(java.lang.String xpath)
          Get an element wrapper for a given xpath.
 java.util.List<IElement> getElementsByXPath(java.lang.String xpath)
          Get a list of all elements that match the given xpath.
 java.lang.String getElementTextByXPath(java.lang.String xpath)
          Get text of the given element.
 java.lang.String getHeader(java.lang.String name)
          Get a particular header or null.
 java.lang.String getHiddenFieldValue(java.lang.String paramName)
          Return the current value of a hidden input element with name paramName.
 com.gargoylesoftware.htmlunit.html.HtmlTable getHtmlTable(java.lang.String tableSummaryOrId)
          Return the HttpUnit WebTable object representing a specified table in the current response.
 java.io.InputStream getInputStream()
          Gets the last server response as input stream.
 java.io.InputStream getInputStream(java.net.URL resourceUrl)
          Gets the input stream for a given URL - can be used to test images or other resources without changing the current navigation context.
 java.lang.String getPageSource()
          Return the source of the current page (like in a browser).
 java.lang.String getPageText()
          Return the string representation of the current page, encoded as specified by the current TestContext.
 java.lang.String getPageTitle()
          Return the page title of the current response page, encoded as specified by the current TestContext.
 java.net.URL getPageURL()
          Get the location of the current page.
 com.gargoylesoftware.htmlunit.html.HtmlElement getResetButton(java.lang.String buttonName)
           
 java.lang.String[] getSelectedOptions(java.lang.String selectName)
          Return the values of the currently selected items in a select box.
 java.lang.String[] getSelectedOptions(java.lang.String selectName, int index)
          Return the values of the currently selected items in the Nth select box with the provided name.
 java.lang.String getSelectedRadio(java.lang.String radioGroup)
          Return the currently selected radio button.
 java.lang.String getSelectOptionLabelForValue(java.lang.String selectName, int index, java.lang.String value)
          Get the label for a given option of the Nth select box with the specified name.
 java.lang.String getSelectOptionLabelForValue(java.lang.String selectName, java.lang.String value)
          Get the label for a given option of a select box.
 java.lang.String getSelectOptionValueForLabel(java.lang.String selectName, int index, java.lang.String label)
          Get the value for a given option of the Nth select box with the specified name.
 java.lang.String getSelectOptionValueForLabel(java.lang.String selectName, java.lang.String label)
          Get the value for a given option of a select box.
 java.lang.String[] getSelectOptionValues(java.lang.String selectName)
          Return a string array of select box option values.
 java.lang.String[] getSelectOptionValues(java.lang.String selectName, int index)
          Return a string array of the Nth select box option values.
 java.lang.String getServerResponse()
          Return the response of the server for the current page.
 int getServerResponseCode()
          Get the request response code.
 com.gargoylesoftware.htmlunit.html.HtmlElement getSubmitButton(java.lang.String buttonName)
          Return the HtmlUnit submit button with a given name.
 com.gargoylesoftware.htmlunit.html.HtmlElement getSubmitButton(java.lang.String buttonName, java.lang.String buttonValue)
          Return the HtmlUnit submit button with a given name and value.
 Table getTable(java.lang.String tableSummaryOrId)
          Each framework have it's own way to represent a Table.
 java.lang.String getTextFieldValue(java.lang.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(java.lang.String windowName)
          Return the window with the given name in the current conversation.
 int getWindowCount()
          Get the number of openend Windows.
 void gotoFrame(java.lang.String frameNameOrId)
          Make the frame with the given name or ID active in the current conversation.
 void gotoPage(java.net.URL initialURL)
          Go to a particular page.
 void gotoRootWindow()
          Make the root window in the current conversation active.
 void gotoWindow(int windowID)
          Goto window with the given Javascript ID.
 void gotoWindow(java.lang.String windowName)
          Make the window with the given name in the current conversation active.
 void gotoWindowByTitle(java.lang.String title)
          Goto first window with the given title.
 boolean hasButton(java.lang.String buttonId)
          Returns if the button identified by buttonId is present.
 boolean hasButtonWithText(java.lang.String text)
          Checks whether a button containing the specified text as its label exists.
 boolean hasElement(java.lang.String anID)
          Test if element with given id exists.
 boolean hasElementByXPath(java.lang.String xpath)
          Test if element with given xpath exists.
 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 hasFormParameterNamed(java.lang.String paramName)
          Return true if a form input element is present on the current form.
 boolean hasFormSelectNamed(java.lang.String selectName)
          Return true if a form parameter (input element) is present on the current response.
 boolean hasFrame(java.lang.String frameNameOrId)
          Test if the given frame is present.
 boolean hasLink(java.lang.String anId)
          Return true if a link is present in the current response with the specified id.
 boolean hasLinkWithExactText(java.lang.String linkText, int index)
          Return true if a link is present in the current page containing the exact specified text.
 boolean hasLinkWithImage(java.lang.String imageFileName, int index)
          Return true if a link is present with a given image based on filename of image.
 boolean hasLinkWithText(java.lang.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(java.lang.String radioGroup, java.lang.String radioOption)
          Return true if a radio group contains the indicated option.
 boolean hasResetButton()
          Checks if the current form contains a reset button.
A reset button can be the following HTML elements: input type=reset button type=reset
 boolean hasResetButton(java.lang.String buttonName)
          Checks if the current form contains a specific reset button.
A reset button can be the following HTML elements: input type=reset button type=reset
 boolean hasSelectOption(java.lang.String selectName, int index, java.lang.String optionLabel)
          Return true if the Nth select box contains the indicated option.
 boolean hasSelectOption(java.lang.String selectName, java.lang.String optionLabel)
          Return true if a select box contains the indicated option.
 boolean hasSelectOptionValue(java.lang.String selectName, int index, java.lang.String optionValue)
          Return true if the Nth select box contains the indicated option.
 boolean hasSelectOptionValue(java.lang.String selectName, java.lang.String optionValue)
          Return true if a select box contains the indicated option.
 boolean hasSubmitButton()
          Checks if the current form contains a submit button.
 boolean hasSubmitButton(java.lang.String buttonName)
          Checks if the current form contains a specific submit button.
A submit button can be the following HTML elements: input type=submit input type=image button type=submit
 boolean hasSubmitButton(java.lang.String buttonName, java.lang.String buttonValue)
          Checks if the current form contains a specific submit button.
A submit button can be the following HTML elements: input type=submit input type=image button type=submit
 boolean hasTable(java.lang.String tableSummaryOrId)
          Check if the Table object representing a specified table exists.
 boolean hasWindow(java.lang.String windowName)
          Test if the window with the given name is present.
 boolean hasWindowByTitle(java.lang.String title)
          Test if window with the given title is present.
 boolean isCheckboxSelected(java.lang.String checkBoxName)
          Determines if the checkbox is selected.
 boolean isCheckboxSelected(java.lang.String checkBoxName, java.lang.String checkBoxValue)
          Determines if the checkbox is selected.
 boolean isIgnoreFailingStatusCodes()
           
 boolean isMatchInElement(java.lang.String elementID, java.lang.String regexp)
          Return true if a given regexp is contained within the specified element.
 boolean isTextInElement(java.lang.String elementID, java.lang.String text)
          Return true if a given string is contained within the specified element.
 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 reset()
          Reset the current form.
 void selectOptions(java.lang.String selectName, int index, java.lang.String[] options)
          Select the specified set of options in the select element with the provided name.
 void selectOptions(java.lang.String selectName, java.lang.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)
          Tell the testing engine that the given alert boxes are expected in the given order.
 void setExpectedJavaScriptConfirm(JavascriptConfirm[] confirms)
          Tell the testing engine that the given confirm boxes are expected in the given order.
 void setExpectedJavaScriptPrompt(JavascriptPrompt[] prompts)
          Tell the testing engine that the given prompt boxes are expected in the given order.
 void setHiddenField(java.lang.String fieldName, java.lang.String text)
          Set a form hidden element to the provided value.
 void setIgnoreFailingStatusCodes(boolean ignore)
          Should the tester ignore failing status codes (300+)? Otherwise, failing status codes will throw an exception.
 void setRefreshHandler(com.gargoylesoftware.htmlunit.RefreshHandler handler)
           
 void setScriptingEnabled(boolean value)
          Enable or disable Javascript support.
 void setTextField(java.lang.String paramName, java.lang.String text)
          Set a form text, password input element or textarea to the provided value.
 void setThrowExceptionOnScriptError(boolean value)
          Set whether or not to throw an exception on Javascript errors.
 void setTimeout(int milliseconds)
          Set the timeout for the request.
 void setWorkingForm(int index)
          Set the form on the current page that the client wishes to work with explicitly by index in the page.
 void setWorkingForm(java.lang.String nameOrId, int index)
          Set the form on the current page 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 specified submit button.
 void submit(java.lang.String buttonName, java.lang.String buttonValue)
          Submit the current form with the specifed submit button (by name and value).
 void uncheckCheckbox(java.lang.String checkBoxName)
          Deselect a specified checkbox.
 void uncheckCheckbox(java.lang.String checkBoxName, java.lang.String value)
          Deselect a specified checkbox.
 void unselectOptions(java.lang.String selectName, int index, java.lang.String[] options)
          Unselect option(s) of the Nth select box with the specified name by value.
 void unselectOptions(java.lang.String selectName, java.lang.String[] options)
          Unselect option(s) of a select box by value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HtmlUnitTestingEngineImpl

public HtmlUnitTestingEngineImpl()
Initializes default HtmlUnit testing engine implementation.

Method Detail

beginAt

public void beginAt(java.net.URL initialURL,
                    TestContext context)
             throws TestingEngineResponseException
Begin a dialog with an initial URL and test client context.

Specified by:
beginAt in interface ITestingEngine
Parameters:
initialURL - absolute url at which to begin dialog.
context - contains context information for the test client.
Throws:
TestingEngineResponseException

closeBrowser

public void closeBrowser()
                  throws ExpectedJavascriptAlertException,
                         ExpectedJavascriptConfirmException,
                         ExpectedJavascriptPromptException
Close the browser and check that all expected Javascript alerts, confirms and prompts have been taken care of.

Specified by:
closeBrowser in interface ITestingEngine
Throws:
ExpectedJavascriptAlertException - If there is pending Javascript alert ITestingEngine.setExpectedJavaScriptAlert(JavascriptAlert[])
ExpectedJavascriptConfirmException - If there is pending Javascript confirm ITestingEngine.setExpectedJavaScriptConfirm(JavascriptConfirm[])
ExpectedJavascriptPromptException - If there is pending Javascript prompt ITestingEngine.setExpectedJavaScriptPrompt(JavascriptPrompt[])

gotoPage

public void gotoPage(java.net.URL initialURL)
              throws TestingEngineResponseException
Go to a particular page.

Specified by:
gotoPage in interface ITestingEngine
Parameters:
initialURL - Full URL of the page.
Throws:
TestingEngineResponseException - if an error response code is encountered and ignoreFailingStatusCodes is not enabled.

setScriptingEnabled

public void setScriptingEnabled(boolean value)
Description copied from interface: ITestingEngine
Enable or disable Javascript support.

Specified by:
setScriptingEnabled in interface ITestingEngine
Parameters:
value - true to enable Javascript.
See Also:
net.sourceforge.jwebunit.api.IJWebUnitDialog#setScriptingEnabled(boolean)

setThrowExceptionOnScriptError

public void setThrowExceptionOnScriptError(boolean value)
Description copied from interface: ITestingEngine
Set whether or not to throw an exception on Javascript errors.

Specified by:
setThrowExceptionOnScriptError in interface ITestingEngine
Parameters:
value - true to throw an exception on Javascript errors.

getCookies

public java.util.List<javax.servlet.http.Cookie> getCookies()
Description copied from interface: ITestingEngine
Get all cookies.

Specified by:
getCookies in interface ITestingEngine
Returns:
List of javax.servlet.http.Cookie.

hasWindow

public boolean hasWindow(java.lang.String windowName)
Description copied from interface: ITestingEngine
Test if the window with the given name is present.

Specified by:
hasWindow in interface ITestingEngine
Parameters:
windowName - Name of the window.
Returns:
true if the Window exists.

hasWindowByTitle

public boolean hasWindowByTitle(java.lang.String title)
Description copied from interface: ITestingEngine
Test if window with the given title is present.

Specified by:
hasWindowByTitle in interface ITestingEngine
Parameters:
title - Title of the window.
Returns:
true if the Window exists.

gotoWindow

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

Specified by:
gotoWindow in interface ITestingEngine
Parameters:
windowName -

gotoWindow

public void gotoWindow(int windowID)
Description copied from interface: ITestingEngine
Goto window with the given Javascript ID.

Specified by:
gotoWindow in interface ITestingEngine
Parameters:
windowID - Javascript ID of the window

getWindowCount

public int getWindowCount()
Description copied from interface: ITestingEngine
Get the number of openend Windows.

Specified by:
getWindowCount in interface ITestingEngine
Returns:
Number of openend Windows.

gotoWindowByTitle

public void gotoWindowByTitle(java.lang.String title)
Goto first window with the given title.

Specified by:
gotoWindowByTitle in interface ITestingEngine
Parameters:
title -

closeWindow

public void closeWindow()
Close the current window.

Specified by:
closeWindow in interface ITestingEngine

hasFrame

public boolean hasFrame(java.lang.String frameNameOrId)
Test if the given frame is present.

Specified by:
hasFrame in interface ITestingEngine
Parameters:
frameNameOrId - Name or ID of the frame. ID is checked first.
Returns:
true if the frame exists.

gotoFrame

public void gotoFrame(java.lang.String frameNameOrId)
Make the frame with the given name or ID active in the current conversation.

Specified by:
gotoFrame in interface ITestingEngine
Parameters:
frameNameOrId - Name or ID of the frame. ID is checked first.

setWorkingForm

public void setWorkingForm(int index)
Set the form on the current page that the client wishes to work with explicitly by index in the page.

Specified by:
setWorkingForm in interface ITestingEngine
Parameters:
index - The 0-based index, when more than one form with the same name is expected.

setWorkingForm

public void setWorkingForm(java.lang.String nameOrId,
                           int index)
Set the form on the current page that the client wishes to work with explicitly by either the form name or id (match by id is attempted first).

Specified by:
setWorkingForm in interface ITestingEngine
Parameters:
nameOrId - name or id of the form to be worked with.
index - The 0-based index, when more than one form with the same name is expected.

hasForm

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

Specified by:
hasForm in interface ITestingEngine
Returns:
true if there is at least a form.

hasForm

public boolean hasForm(java.lang.String nameOrID)
Return true if the current response contains a specific form.

Specified by:
hasForm in interface ITestingEngine
Parameters:
nameOrID - name of id of the form to check for.
Returns:
true if there is at least a form.

hasFormParameterNamed

public boolean hasFormParameterNamed(java.lang.String paramName)
Description copied from interface: ITestingEngine
Return true if a form input element is present on the current form.

Specified by:
hasFormParameterNamed in interface ITestingEngine
Parameters:
paramName - name of the input element to check for
Returns:
true if there is at least a form parameter.

getTextFieldValue

public java.lang.String getTextFieldValue(java.lang.String paramName)
Return the current value of a text input element with name paramName.

Specified by:
getTextFieldValue in interface ITestingEngine
Parameters:
paramName - name of the input element. TODO: Find a way to handle multiple text input element with same name.
Returns:
Text content of the text field.

getHiddenFieldValue

public java.lang.String getHiddenFieldValue(java.lang.String paramName)
Return the current value of a hidden input element with name paramName.

Specified by:
getHiddenFieldValue in interface ITestingEngine
Parameters:
paramName - name of the input element. TODO: Find a way to handle multiple hidden input element with same name.
Returns:
Value of the hidden input.

setTextField

public void setTextField(java.lang.String paramName,
                         java.lang.String text)
Set a form text, password input element or textarea to the provided value.

Specified by:
setTextField in interface ITestingEngine
Parameters:
fieldName - name of the input element or textarea
text - parameter value to submit for the element.

setHiddenField

public void setHiddenField(java.lang.String fieldName,
                           java.lang.String text)
Set a form hidden element to the provided value.

Specified by:
setHiddenField in interface ITestingEngine
Parameters:
fieldName - name of the hidden input element
paramValue - parameter value to submit for the element.

getSelectOptionValues

public java.lang.String[] getSelectOptionValues(java.lang.String selectName)
Return a string array of select box option values.

Specified by:
getSelectOptionValues in interface ITestingEngine
Parameters:
selectName - name of the select box.
Returns:
Array of select options values.

getSelectOptionValues

public java.lang.String[] getSelectOptionValues(java.lang.String selectName,
                                                int index)
Return a string array of the Nth select box option values.

Specified by:
getSelectOptionValues in interface ITestingEngine
Parameters:
selectName - name of the select box.
index - the 0-based index when more than one select with the same name is expected.
Returns:
Array of select options values.

getSelectedOptions

public java.lang.String[] getSelectedOptions(java.lang.String selectName)
Description copied from interface: ITestingEngine
Return the values of the currently selected items in a select box.

Specified by:
getSelectedOptions in interface ITestingEngine
Parameters:
selectName - name of the select box.

getSelectedOptions

public java.lang.String[] getSelectedOptions(java.lang.String selectName,
                                             int index)
Description copied from interface: ITestingEngine
Return the values of the currently selected items in the Nth select box with the provided name.

Specified by:
getSelectedOptions in interface ITestingEngine
Parameters:
selectName - name of the select box.
index - the 0-based index used when more than one select with the same name is expected.

getSelectOptionValueForLabel

public java.lang.String getSelectOptionValueForLabel(java.lang.String selectName,
                                                     java.lang.String label)
Description copied from interface: ITestingEngine
Get the value for a given option of a select box.

Specified by:
getSelectOptionValueForLabel in interface ITestingEngine
Parameters:
selectName - name of the select box.
label - label of the option.

getSelectOptionValueForLabel

public java.lang.String getSelectOptionValueForLabel(java.lang.String selectName,
                                                     int index,
                                                     java.lang.String label)
Description copied from interface: ITestingEngine
Get the value for a given option of the Nth select box with the specified name.

Specified by:
getSelectOptionValueForLabel in interface ITestingEngine
Parameters:
selectName - name of the select box.
index - the 0-based index used when more than one select with the same name is expected.
label - label of the option.

getSelectOptionLabelForValue

public java.lang.String getSelectOptionLabelForValue(java.lang.String selectName,
                                                     java.lang.String value)
Description copied from interface: ITestingEngine
Get the label for a given option of a select box.

Specified by:
getSelectOptionLabelForValue in interface ITestingEngine
Parameters:
selectName - name of the select box.
value - label of the option.

getSelectOptionLabelForValue

public java.lang.String getSelectOptionLabelForValue(java.lang.String selectName,
                                                     int index,
                                                     java.lang.String value)
Description copied from interface: ITestingEngine
Get the label for a given option of the Nth select box with the specified name.

Specified by:
getSelectOptionLabelForValue in interface ITestingEngine
Parameters:
selectName - name of the select box.
index - the 0-based index used when more than one select with the same name is expected.
value - label of the option.

getPageURL

public java.net.URL getPageURL()
Description copied from interface: ITestingEngine
Get the location of the current page.

Specified by:
getPageURL in interface ITestingEngine
Returns:
an URL.

getPageSource

public java.lang.String getPageSource()
Description copied from interface: ITestingEngine
Return the source of the current page (like in a browser).

Specified by:
getPageSource in interface ITestingEngine
Returns:
Source of the page (or HTTP Body as String)

getPageTitle

public java.lang.String getPageTitle()
Description copied from interface: ITestingEngine
Return the page title of the current response page, encoded as specified by the current TestContext.

Specified by:
getPageTitle in interface ITestingEngine
Returns:
Title of the page.

getPageText

public java.lang.String getPageText()
Description copied from interface: ITestingEngine
Return the string representation of the current page, encoded as specified by the current TestContext.

Specified by:
getPageText in interface ITestingEngine
Returns:
Visible text in the page.

getServerResponse

public java.lang.String getServerResponse()
Description copied from interface: ITestingEngine
Return the response of the server for the current page.

Specified by:
getServerResponse in interface ITestingEngine
Returns:
HTTP header & body

getInputStream

public java.io.InputStream getInputStream()
Description copied from interface: ITestingEngine
Gets the last server response as input stream.

Specified by:
getInputStream in interface ITestingEngine

getInputStream

public java.io.InputStream getInputStream(java.net.URL resourceUrl)
                                   throws TestingEngineResponseException
Description copied from interface: ITestingEngine
Gets the input stream for a given URL - can be used to test images or other resources without changing the current navigation context.

Specified by:
getInputStream in interface ITestingEngine
Parameters:
resourceUrl - the url to the resource
Throws:
TestingEngineResponseException

createWebClient

protected com.gargoylesoftware.htmlunit.WebClient createWebClient()
Create the 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.

Returns:
A newly created WebClient

getWindow

public com.gargoylesoftware.htmlunit.WebWindow getWindow(java.lang.String windowName)
Return the window with the given name in the current conversation.

Parameters:
windowName -
Throws:
com.gargoylesoftware.htmlunit.WebWindowNotFoundException - if the window could not be found

getCurrentWindow

public com.gargoylesoftware.htmlunit.WebWindow getCurrentWindow()
Return the currently opened window (issue 2697234).

Returns:
the currently opened window

getWebClient

public com.gargoylesoftware.htmlunit.WebClient getWebClient()
Return the current web client (issue 2697234).

Returns:
the current web client

getComments

public java.util.List<java.lang.String> getComments()
Get all the comments in a document, as a list of strings.

Specified by:
getComments in interface ITestingEngine

getCurrentPageTitle

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


hasFormSelectNamed

public boolean hasFormSelectNamed(java.lang.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

getSubmitButton

public com.gargoylesoftware.htmlunit.html.HtmlElement getSubmitButton(java.lang.String buttonName)
Return the HtmlUnit submit button with a given name.

Parameters:
buttonName - name of button.
Returns:
the button

getResetButton

public com.gargoylesoftware.htmlunit.html.HtmlElement getResetButton(java.lang.String buttonName)

getSubmitButton

public com.gargoylesoftware.htmlunit.html.HtmlElement getSubmitButton(java.lang.String buttonName,
                                                                      java.lang.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

hasSubmitButton

public boolean hasSubmitButton()
Checks if the current form contains a submit button.

Specified by:
hasSubmitButton in interface ITestingEngine

hasSubmitButton

public boolean hasSubmitButton(java.lang.String buttonName)
Checks if the current form contains a specific submit button.
A submit button can be the following HTML elements:

Specified by:
hasSubmitButton in interface ITestingEngine
Parameters:
buttonName - name or id of the button to check for.

hasSubmitButton

public boolean hasSubmitButton(java.lang.String buttonName,
                               java.lang.String buttonValue)
Checks if the current form contains a specific submit button.
A submit button can be the following HTML elements:

Specified by:
hasSubmitButton in interface ITestingEngine
Parameters:
buttonName - name of id of the button to check for.
buttonValue - value of the button

hasResetButton

public boolean hasResetButton()
Description copied from interface: ITestingEngine
Checks if the current form contains a reset button.
A reset button can be the following HTML elements:

Specified by:
hasResetButton in interface ITestingEngine

hasResetButton

public boolean hasResetButton(java.lang.String buttonName)
Description copied from interface: ITestingEngine
Checks if the current form contains a specific reset button.
A reset button can be the following HTML elements:

Specified by:
hasResetButton in interface ITestingEngine
Parameters:
buttonName - name or id of the button to check for.

hasButtonWithText

public boolean hasButtonWithText(java.lang.String text)
Checks whether a button containing the specified text as its label exists. For HTML input tags of type submit, reset, or button, this checks the value attribute. For HTML button tags, this checks the element's content by converting it to text.

Specified by:
hasButtonWithText in interface ITestingEngine
Parameters:
text - the text of the button (between <button></button>) or the value of the "value" attribute.
Returns:
true when the button with text could be found.

getButtonWithText

public com.gargoylesoftware.htmlunit.html.HtmlElement getButtonWithText(java.lang.String buttonValueText)
Returns the first button that contains the specified text as its label. For HTML input tags of type submit, reset, or button, this checks the value attribute. For HTML button tags, this checks the element's content by converting it to text.

Parameters:
buttonValueText - the text of the button (between <button></button>) or the value of the "value" attribute.
Returns:
the ClickableElement with the specified text or null if no such button is found.

hasButton

public boolean hasButton(java.lang.String buttonId)
Returns if the button identified by buttonId is present.

Specified by:
hasButton in interface ITestingEngine
Parameters:
buttonId - the id of the button
Returns:
true when the button was found.

isCheckboxSelected

public boolean isCheckboxSelected(java.lang.String checkBoxName)
Description copied from interface: ITestingEngine
Determines if the checkbox is selected.

Specified by:
isCheckboxSelected in interface ITestingEngine
Parameters:
checkBoxName - name of the checkbox.
Returns:
true if the first checkbox with given name is selected.

isCheckboxSelected

public boolean isCheckboxSelected(java.lang.String checkBoxName,
                                  java.lang.String checkBoxValue)
Description copied from interface: ITestingEngine
Determines if the checkbox is selected.

Specified by:
isCheckboxSelected in interface ITestingEngine
Parameters:
checkBoxName - name attribut of the checkbox.
checkBoxValue - value attribut of the checkbox.
Returns:
true if the first checkbox with given name and value is selected.

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.

getTable

public Table getTable(java.lang.String tableSummaryOrId)
Description copied from interface: ITestingEngine
Each framework have it's own way to represent a Table. Testing engines are responsible for converting to the unified JWebUnit format.

Specified by:
getTable in interface ITestingEngine
Parameters:
tableSummaryOrId - summary, name or id of the table to return.
Returns:
unified JWebUnit representation of a table.

getHtmlTable

public com.gargoylesoftware.htmlunit.html.HtmlTable getHtmlTable(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.

hasTable

public boolean hasTable(java.lang.String tableSummaryOrId)
Description copied from interface: ITestingEngine
Check if the Table object representing a specified table exists.

Specified by:
hasTable in interface ITestingEngine
Parameters:
tableSummaryOrId - summary, name or id of the table.
Returns:
true if table exists.

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.

Specified by:
submit in interface ITestingEngine

submit

public void submit(java.lang.String buttonName)
Submit the current form with the specified submit button. See getForm()for an explanation of how the current form is established.

Specified by:
submit in interface ITestingEngine
Parameters:
buttonName - name of the button to use for submission.

submit

public void submit(java.lang.String buttonName,
                   java.lang.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.

Specified by:
submit in interface ITestingEngine
Parameters:
buttonName - name of the button to use for submission.
buttonValue - value/label 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.

Specified by:
reset in interface ITestingEngine

hasLinkWithText

public boolean hasLinkWithText(java.lang.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).

Specified by:
hasLinkWithText in interface ITestingEngine
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.

hasLinkWithExactText

public boolean hasLinkWithExactText(java.lang.String linkText,
                                    int index)
Description copied from interface: ITestingEngine
Return true if a link is present in the current page containing the exact specified text. Note. This will call String.trim() to trim all leading / trailing spaces. RFE 996031...

Specified by:
hasLinkWithExactText in interface ITestingEngine
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.

hasLinkWithImage

public boolean hasLinkWithImage(java.lang.String imageFileName,
                                int index)
Description copied from interface: ITestingEngine
Return true if a link is present with a given image based on filename of image.

Specified by:
hasLinkWithImage in interface ITestingEngine
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".
index - The 0-based index, when more than one link with the same text is expected.

hasLink

public boolean hasLink(java.lang.String anId)
Return true if a link is present in the current response with the specified id.

Specified by:
hasLink in interface ITestingEngine
Parameters:
anId - link id to check for.

clickLinkWithText

public void clickLinkWithText(java.lang.String linkText,
                              int index)
Description copied from interface: ITestingEngine
Navigate by submitting a request based on a link containing the specified text. A RuntimeException is thrown if no such link can be found.

Specified by:
clickLinkWithText in interface ITestingEngine
Parameters:
linkText - text which link to be navigated should contain.
index - The 0-based index, when more than one link with the same text is expected.

clickLinkWithExactText

public void clickLinkWithExactText(java.lang.String linkText,
                                   int index)
Description copied from interface: ITestingEngine
Navigate by clicking a link with the exact specified text. A RuntimeException is thrown if no such link can be found.

Specified by:
clickLinkWithExactText in interface ITestingEngine
Parameters:
linkText - exact text which link to be navigated should contain.
index - The 0-based index, when more than one link with the same text is expected.

checkCheckbox

public void checkCheckbox(java.lang.String checkBoxName)
Select a specified checkbox. If the checkbox is already checked then the checkbox will stay checked.

Specified by:
checkCheckbox in interface ITestingEngine
Parameters:
checkBoxName - name of checkbox to be deselected.

checkCheckbox

public void checkCheckbox(java.lang.String checkBoxName,
                          java.lang.String value)
Description copied from interface: ITestingEngine
Select a specified checkbox. If the checkbox is already checked then the checkbox will stay checked.

Specified by:
checkCheckbox in interface ITestingEngine
Parameters:
checkBoxName - name of checkbox to be selected.
value - value of the checkbox (to differenciate checkboxes with the same name).

uncheckCheckbox

public void uncheckCheckbox(java.lang.String checkBoxName)
Deselect a specified checkbox. If the checkbox is already unchecked then the checkbox will stay unchecked.

Specified by:
uncheckCheckbox in interface ITestingEngine
Parameters:
checkBoxName - name of checkbox to be deselected.

uncheckCheckbox

public void uncheckCheckbox(java.lang.String checkBoxName,
                            java.lang.String value)
Description copied from interface: ITestingEngine
Deselect a specified checkbox. If the checkbox is already unchecked then the checkbox will stay unchecked.

Specified by:
uncheckCheckbox in interface ITestingEngine
Parameters:
checkBoxName - name of checkbox to be deselected.
value - value of the checkbox (to differenciate checkboxes with the same name).

clickRadioOption

public void clickRadioOption(java.lang.String radioGroup,
                             java.lang.String radioOption)
Clicks a radio option. Asserts that the radio option exists first. *

Specified by:
clickRadioOption in interface ITestingEngine
Parameters:
radioGroup - name of the radio group.
radioOption - value of the option to check for.

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.

Specified by:
clickLink in interface ITestingEngine
Parameters:
anID - id of link to be navigated.

clickLinkWithImage

public void clickLinkWithImage(java.lang.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.

Specified by:
clickLinkWithImage in interface ITestingEngine
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".
index - The 0-based index, when more than one link with the same text is expected.

hasElement

public boolean hasElement(java.lang.String anID)
Description copied from interface: ITestingEngine
Test if element with given id exists.

Specified by:
hasElement in interface ITestingEngine
Parameters:
anID - id of the element.
Returns:
true if element was found.

hasElementByXPath

public boolean hasElementByXPath(java.lang.String xpath)
Description copied from interface: ITestingEngine
Test if element with given xpath exists.

Specified by:
hasElementByXPath in interface ITestingEngine
Parameters:
xpath - xpath of the element.
Returns:
true if element was found.

clickElementByXPath

public void clickElementByXPath(java.lang.String xpath)
Description copied from interface: ITestingEngine
Click element with given xpath.

Specified by:
clickElementByXPath in interface ITestingEngine
Parameters:
xpath - xpath of the element.

getElementAttributByXPath

public java.lang.String getElementAttributByXPath(java.lang.String xpath,
                                                  java.lang.String attribut)
Description copied from interface: ITestingEngine
Get attribut value of the given element. For example, if you have img src="bla.gif" alt="toto", getElementAttributByXPath("//img[@src='bla.gif']", "alt") returns "toto"

Specified by:
getElementAttributByXPath in interface ITestingEngine
Parameters:
xpath - xpath of the element.
attribut - name of the attribut.
Returns:
Attribut value or null if the element is not found.

getElementTextByXPath

public java.lang.String getElementTextByXPath(java.lang.String xpath)
Description copied from interface: ITestingEngine
Get text of the given element.

Specified by:
getElementTextByXPath in interface ITestingEngine
Parameters:
xpath - xpath of the element.

clickButton

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

Specified by:
clickButton in interface ITestingEngine
Parameters:
buttonId -

clickButtonWithText

public void clickButtonWithText(java.lang.String buttonValueText)
Clicks the first button that contains the specified text as its label. For HTML input tags of type submit, reset, or button, this checks the value attribute. For HTML button tags, this checks the element's content by converting it to text. or an HTML <button> tag.

Specified by:
clickButtonWithText in interface ITestingEngine
Parameters:
buttonValueText - the text of the button (contents of the value attribute).

hasRadioOption

public boolean hasRadioOption(java.lang.String radioGroup,
                              java.lang.String radioOption)
Return true if a radio group contains the indicated option.

Specified by:
hasRadioOption in interface ITestingEngine
Parameters:
radioGroup - name of the radio group.
radioOption - value of the option to check for.

getSelectedRadio

public java.lang.String getSelectedRadio(java.lang.String radioGroup)
Description copied from interface: ITestingEngine
Return the currently selected radio button.

Specified by:
getSelectedRadio in interface ITestingEngine
Parameters:
radioGroup - name of the radio group.
Returns:
value of the selected radio.

hasSelectOption

public boolean hasSelectOption(java.lang.String selectName,
                               java.lang.String optionLabel)
Return true if a select box contains the indicated option.

Specified by:
hasSelectOption in interface ITestingEngine
Parameters:
selectName - name of the select box.
optionLabel - label of the option.
Returns:
true if a select box has the given option (by label).

hasSelectOptionValue

public boolean hasSelectOptionValue(java.lang.String selectName,
                                    java.lang.String optionValue)
Return true if a select box contains the indicated option.

Specified by:
hasSelectOptionValue in interface ITestingEngine
Parameters:
selectName - name of the select box.
optionValue - value of the option.
Returns:
true if a select box has the given option (by value).

selectOptions

public void selectOptions(java.lang.String selectName,
                          java.lang.String[] options)
Select the specified set of options in the select element with the provided name.

Specified by:
selectOptions in interface ITestingEngine
Parameters:
selectName - name of the select box
options - set of options to select.

hasSelectOption

public boolean hasSelectOption(java.lang.String selectName,
                               int index,
                               java.lang.String optionLabel)
Return true if the Nth select box contains the indicated option.

Specified by:
hasSelectOption in interface ITestingEngine
Parameters:
selectName - 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.
Returns:
true if a select box has the given option (by label).

hasSelectOptionValue

public boolean hasSelectOptionValue(java.lang.String selectName,
                                    int index,
                                    java.lang.String optionValue)
Return true if the Nth select box contains the indicated option.

Specified by:
hasSelectOptionValue in interface ITestingEngine
Parameters:
selectName - 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.
Returns:
true if a select box has the given option (by value).

selectOptions

public void selectOptions(java.lang.String selectName,
                          int index,
                          java.lang.String[] options)
Select the specified set of options in the select element with the provided name.

Specified by:
selectOptions in interface ITestingEngine
Parameters:
selectName - name of the select box
index - the 0-based index of the select element when multiple select elements are expected.
options - set of options to select.

unselectOptions

public void unselectOptions(java.lang.String selectName,
                            java.lang.String[] options)
Description copied from interface: ITestingEngine
Unselect option(s) of a select box by value.

Specified by:
unselectOptions in interface ITestingEngine
Parameters:
selectName - name of the select box.
options - vaules of the options to unselect.

unselectOptions

public void unselectOptions(java.lang.String selectName,
                            int index,
                            java.lang.String[] options)
Description copied from interface: ITestingEngine
Unselect option(s) of the Nth select box with the specified name by value.

Specified by:
unselectOptions in interface ITestingEngine
Parameters:
selectName - name of the select box.
index - the 0-based index of the select element when multiple select elements are expected.
options - vaules of the options to unselect.

isTextInElement

public boolean isTextInElement(java.lang.String elementID,
                               java.lang.String text)
Description copied from interface: ITestingEngine
Return true if a given string is contained within the specified element.

Specified by:
isTextInElement in interface ITestingEngine
Parameters:
elementID - ID of element to inspect.
text - text to check for.
Returns:
true if text was found.

isMatchInElement

public boolean isMatchInElement(java.lang.String elementID,
                                java.lang.String regexp)
Description copied from interface: ITestingEngine
Return true if a given regexp is contained within the specified element.

Specified by:
isMatchInElement in interface ITestingEngine
Parameters:
elementID - Id of element to inspect.
regexp - regexp to match.
Returns:
true if a match is found.

gotoRootWindow

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

Specified by:
gotoRootWindow in interface ITestingEngine

setExpectedJavaScriptAlert

public void setExpectedJavaScriptAlert(JavascriptAlert[] alerts)
                                throws ExpectedJavascriptAlertException
Description copied from interface: ITestingEngine
Tell the testing engine that the given alert boxes are expected in the given order.

Specified by:
setExpectedJavaScriptAlert in interface ITestingEngine
Parameters:
alerts - Expected alerts.
Throws:
ExpectedJavascriptAlertException - If there are still unconsummed alert since a previous call of this method.

setExpectedJavaScriptConfirm

public void setExpectedJavaScriptConfirm(JavascriptConfirm[] confirms)
                                  throws ExpectedJavascriptConfirmException
Description copied from interface: ITestingEngine
Tell the testing engine that the given confirm boxes are expected in the given order.

Specified by:
setExpectedJavaScriptConfirm in interface ITestingEngine
Parameters:
confirms - Expected confirms.
Throws:
ExpectedJavascriptConfirmException - If there are still unconsummed confirm since a previous call of this method.

setExpectedJavaScriptPrompt

public void setExpectedJavaScriptPrompt(JavascriptPrompt[] prompts)
                                 throws ExpectedJavascriptPromptException
Description copied from interface: ITestingEngine
Tell the testing engine that the given prompt boxes are expected in the given order.

Specified by:
setExpectedJavaScriptPrompt in interface ITestingEngine
Parameters:
prompts - Expected prompts.
Throws:
ExpectedJavascriptPromptException - If there are still unconsummed prompt since a previous call of this method.

getElementByXPath

public IElement getElementByXPath(java.lang.String xpath)
Description copied from interface: ITestingEngine
Get an element wrapper for a given xpath.

Specified by:
getElementByXPath in interface ITestingEngine
Parameters:
xpath - XPath to evaluate
Returns:
The element if found
See Also:
ITestingEngine.getElementsByXPath(String)

getElementByID

public IElement getElementByID(java.lang.String id)
Description copied from interface: ITestingEngine
Get an element wrapper for a given ID.

Specified by:
getElementByID in interface ITestingEngine
Parameters:
id - element ID to find
Returns:
The element if found

getElementsByXPath

public java.util.List<IElement> getElementsByXPath(java.lang.String xpath)
Description copied from interface: ITestingEngine
Get a list of all elements that match the given xpath.

Specified by:
getElementsByXPath in interface ITestingEngine
Parameters:
xpath - XPath to evaluate
Returns:
List of all elements found
See Also:
ITestingEngine.getElementByXPath(String)

getServerResponseCode

public int getServerResponseCode()
Description copied from interface: ITestingEngine
Get the request response code.

Specified by:
getServerResponseCode in interface ITestingEngine
Returns:
The request response code.

getWebResponse

public com.gargoylesoftware.htmlunit.WebResponse getWebResponse()
Get the last WebResponse from HtmlUnit.


isIgnoreFailingStatusCodes

public boolean isIgnoreFailingStatusCodes()

setIgnoreFailingStatusCodes

public void setIgnoreFailingStatusCodes(boolean ignore)
Description copied from interface: ITestingEngine
Should the tester ignore failing status codes (300+)? Otherwise, failing status codes will throw an exception.

Specified by:
setIgnoreFailingStatusCodes in interface ITestingEngine

getHeader

public java.lang.String getHeader(java.lang.String name)
Description copied from interface: ITestingEngine
Get a particular header or null.

Specified by:
getHeader in interface ITestingEngine
Parameters:
name - The header name
Returns:
The first header value or null

getAllHeaders

public java.util.Map<java.lang.String,java.lang.String> getAllHeaders()
Description copied from interface: ITestingEngine
Get all headers.

Specified by:
getAllHeaders in interface ITestingEngine
Returns:
The header values stored in a map.

getDefaultBrowserVersion

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

Returns:
The default browser version
See Also:
BrowserVersion

setDefaultBrowserVersion

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

Parameters:
the - browser version to set as default for this engine instance
See Also:
BrowserVersion

setTimeout

public void setTimeout(int milliseconds)
Description copied from interface: ITestingEngine
Set the timeout for the request. A timeout of 0 means an infinite timeout.

Specified by:
setTimeout in interface ITestingEngine
Parameters:
milliseconds - the milliseconds in which to timeout, or 0 for infinite wait (the default).

setRefreshHandler

public void setRefreshHandler(com.gargoylesoftware.htmlunit.RefreshHandler handler)


Copyright © 2002-2011 SourceForge. All Rights Reserved.