[JWebUnit-development] SF.net SVN: jwebunit:[964] trunk
Brought to you by:
henryju
|
From: <he...@us...> - 2012-11-27 15:57:15
|
Revision: 964
http://jwebunit.svn.sourceforge.net/jwebunit/?rev=964&view=rev
Author: henryju
Date: 2012-11-27 15:57:02 +0000 (Tue, 27 Nov 2012)
Log Message:
-----------
[3590252] Assert form is present before call of setWorkingForm(nameOrId, index)
Modified Paths:
--------------
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/FormSubmissionTest.java
trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/api/ITestingEngine.java
trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/junit/WebTester.java
trunk/jwebunit-htmlunit-plugin/src/main/java/net/sourceforge/jwebunit/htmlunit/HtmlUnitTestingEngineImpl.java
trunk/jwebunit-webdriver-plugin/src/main/java/net/sourceforge/jwebunit/webdriver/WebDriverTestingEngineImpl.java
trunk/src/changes/changes.xml
Modified: trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/FormSubmissionTest.java
===================================================================
--- trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/FormSubmissionTest.java 2012-11-27 15:39:46 UTC (rev 963)
+++ trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/FormSubmissionTest.java 2012-11-27 15:57:02 UTC (rev 964)
@@ -18,6 +18,8 @@
*/
package net.sourceforge.jwebunit.tests;
+import junit.framework.AssertionFailedError;
+
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
@@ -32,10 +34,10 @@
/**
* Test form submission related methods of WebTestCase.
- *
+ *
* If there is more than one submit button on a page, WebTestCase / httpunit
* require indication of which button to submit with prior to form submission.
- *
+ *
* @author Jim Weaver
*/
public class FormSubmissionTest extends JWebUnitAPITestCase {
@@ -94,7 +96,7 @@
//The following depend on the browser: IE send full path (i.e. temp.getAbsolutePath()) but FF send only file name.
assertTextPresent("file=[" + temp.getName() + "{abcdefgh}]");
}
-
+
@Test
public void testSubmitImageInput() {
beginAt("/InputImageForm.html");
@@ -158,22 +160,22 @@
submit();
assertTextPresent("color=[blue]");
}
-
+
@Test
public void testRadioSelection() {
- beginAt("/RadioForm.html");
- clickRadioOption("radio", "1");
- assertRadioOptionSelected("radio", "1");
- submit();
- assertTextPresent("radio=[1]");
- clickLink("return");
- clickRadioOption("radio", "2");
- clickRadioOption("radio", "3");
- assertRadioOptionNotSelected("radio", "1");
- assertRadioOptionNotSelected("radio", "2");
- assertRadioOptionSelected("radio", "3");
- submit();
- assertTextPresent("radio=[3]");
+ beginAt("/RadioForm.html");
+ clickRadioOption("radio", "1");
+ assertRadioOptionSelected("radio", "1");
+ submit();
+ assertTextPresent("radio=[1]");
+ clickLink("return");
+ clickRadioOption("radio", "2");
+ clickRadioOption("radio", "3");
+ assertRadioOptionNotSelected("radio", "1");
+ assertRadioOptionNotSelected("radio", "2");
+ assertRadioOptionSelected("radio", "3");
+ submit();
+ assertTextPresent("radio=[3]");
}
@Test
@@ -259,14 +261,20 @@
assertSubmitButtonPresent("myInput2");
}
+ @Test(expected=AssertionError.class)
+ public void testSetWorkingFormWithIndexPresent() {
+ beginAt("/MultiFormPage.html");
+ setWorkingForm("dontExists", 2);
+ }
+
@Test
public void testInvalidButton() {
beginAt("/InvalidActionForm.html");
try {
- submit("button1");
- fail("A TestingEngineResponseException was expected.");
+ submit("button1");
+ fail("A TestingEngineResponseException was expected.");
} catch (TestingEngineResponseException e) {
- assertEquals(404, e.getHttpStatusCode());
+ assertEquals(404, e.getHttpStatusCode());
}
}
@@ -325,7 +333,7 @@
private void gotoMultiButtonPage() {
beginAt("/MultiNamedButtonForm.html");
}
-
+
@Test
public void testCachedForm() {
beginAt("/Submit1.html");
@@ -335,7 +343,7 @@
submit();
assertTextPresent("Page 3");
}
-
+
/**
* Submit input
*/
@@ -347,7 +355,7 @@
assertTextPresent("Submitted parameters");
assertTextPresent("color=[blue]");
}
-
+
@Test
public void testSetHiddenField() {
beginAt("/SingleNamedButtonForm.html");
Modified: trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/api/ITestingEngine.java
===================================================================
--- trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/api/ITestingEngine.java 2012-11-27 15:39:46 UTC (rev 963)
+++ trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/api/ITestingEngine.java 2012-11-27 15:57:02 UTC (rev 964)
@@ -37,7 +37,7 @@
/**
* This is the interface for all communications between JWebUnit and the specific running test engine.
- *
+ *
* @author Julien Henry
* @author Nick Neuberger
*/
@@ -45,7 +45,7 @@
/**
* Open the browser at an initial URL.
- *
+ *
* @param aInitialURL Initial URL
* @param aTestContext Test context
* @throws TestingEngineResponseException If something bad happend (404)
@@ -55,7 +55,7 @@
/**
* Close the browser and check if there is no pending Javascript alert, confirm or prompt.
- *
+ *
* @throws ExpectedJavascriptAlertException If there is pending Javascript alert
* {@link ITestingEngine#setExpectedJavaScriptAlert(JavascriptAlert[])}
* @throws ExpectedJavascriptConfirmException If there is pending Javascript confirm
@@ -69,36 +69,36 @@
/**
* Simulate user typing a new URL in the browser.
- *
+ *
* @param url Full URL of the page.
* @throws TestingEngineResponseException If something bad happend (404)
*/
void gotoPage(URL url) throws TestingEngineResponseException;
-
+
/**
* Enable or disable Javascript support.
- *
+ *
* @param value true to enable Javascript.
*/
void setScriptingEnabled(boolean value);
/**
* Set whether or not to throw an exception on Javascript errors.
- *
+ *
* @param value true to throw an exception on Javascript errors.
*/
void setThrowExceptionOnScriptError(boolean value);
/**
* Get all cookies.
- *
+ *
* @return List of javax.servlet.http.Cookie.
*/
List<?> getCookies();
/**
* Test if the window with the given name is present.
- *
+ *
* @param windowName Name of the window.
* @return true if the Window exists.
*/
@@ -106,7 +106,7 @@
/**
* Test if window with the given title is present.
- *
+ *
* @param windowTitle Title of the window.
* @return true if the Window exists.
*/
@@ -114,21 +114,21 @@
/**
* Make the window with the given name active.
- *
+ *
* @param windowName Name of the window
*/
void gotoWindow(String windowName);
/**
* Goto first window with the given title.
- *
+ *
* @param title Title of the window
*/
void gotoWindowByTitle(String title);
/**
* Goto window with the given Javascript ID.
- *
+ *
* @param windowID Javascript ID of the window
* @deprecated Javascript ID does'nt not exists. Currently this is an index
* in the list of available windows, but this is not portable (and probably not stable).
@@ -139,26 +139,26 @@
/**
* Make the root window active. Used to reset the effect of {@link ITestingEngine#gotoFrame(String)}.
- *
+ *
*/
void gotoRootWindow();
/**
* Get the number of opened Windows.
- *
+ *
* @return Number of opened Windows.
*/
int getWindowCount();
/**
* Close the current window.
- *
+ *
*/
void closeWindow();
/**
* Test if the given frame is present.
- *
+ *
* @param frameNameOrId Name or ID of the frame. ID is checked first.
* @return true if the frame exists.
*/
@@ -166,14 +166,14 @@
/**
* Make the frame with the given name or ID active in the current conversation.
- *
+ *
* @param frameNameOrId Name or ID of the frame. ID is checked first.
*/
void gotoFrame(String frameNameOrId);
/**
* Set the form on the current page that the client wishes to work with explicitly by index in the page.
- *
+ *
* @param index The 0-based index, when more than one form with the same name is expected.
*/
void setWorkingForm(int index);
@@ -181,7 +181,7 @@
/**
* 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).
- *
+ *
* @param nameOrId name or id of the form to be worked with.
* @param index The 0-based index, when more than one form with the same name is expected.
*/
@@ -189,22 +189,31 @@
/**
* Check whether the current page contains a form.
- *
+ *
* @return true if there is at least a form.
*/
boolean hasForm();
/**
* Return true if the current page contains a specific form.
- *
+ *
* @param nameOrID name of id of the form to check for.
* @return true if there is at least a form.
*/
boolean hasForm(String nameOrID);
/**
+ * Return true if the current page contains a specific form.
+ *
+ * @param nameOrID name of id of the form to check for.
+ * @param index The 0-based index, when more than one form with the same name is expected.
+ * @return true if there is at least a form.
+ */
+ boolean hasForm(String nameOrID, int index);
+
+ /**
* Return true if a form input element is present on the current form.
- *
+ *
* @param paramName name of the input element to check for
* @return true if there is at least a form parameter.
*/
@@ -213,7 +222,7 @@
/**
* Return the current value of a text field with name <code>paramName</code>. Text fields are input text, input
* password and textarea
- *
+ *
* @param paramName name of the text field element.
* @return Text content of the text field.
*/
@@ -221,7 +230,7 @@
/**
* Return the current value of a hidden input element with name <code>paramName</code>.
- *
+ *
* @param paramName name of the hidden input element.
* @return Value of the hidden input.
*/
@@ -229,15 +238,15 @@
/**
* Fill a text, password or textarea field with the provided text.
- *
+ *
* @param inputName name of the text, password or textarea element
* @param text value to type in the field.
*/
void setTextField(String inputName, String text);
-
+
/**
* Fill hidden field with the provided text.
- *
+ *
* @param inputName name of the hidden element
* @param text value to set in the hidden field.
*/
@@ -245,9 +254,9 @@
/**
* Return a string array of select box option values.
- *
+ *
* Exemple: <br/>
- *
+ *
* <code>
* <FORM action="http://my_host/doit" method="post">
* <P>
@@ -263,18 +272,18 @@
* </P>
* </FORM>
* </code>
- *
+ *
* Should return [Component_1_a, Component_1_b, Component_3, Component_4, Component_5]
- *
+ *
* @param selectName name of the select box.
* @return Array of select options values.
*/
String[] getSelectOptionValues(String selectName);
-
+
/**
* Return a string array of option values for the Nth select box
* with the specified name.
- *
+ *
* @param selectName name of the select box.
* @param index the 0-based index used when more than one select with
* the same name is expected.
@@ -284,7 +293,7 @@
/**
* Return the values of the currently selected items in a select box.
- *
+ *
* @param selectName name of the select box.
*/
String[] getSelectedOptions(String selectName);
@@ -292,17 +301,17 @@
/**
* Return the values of the currently selected items in the Nth select box
* with the provided name.
- *
+ *
* @param selectName name of the select box.
* @param index the 0-based index used when more than one select with
* the same name is expected.
*/
String[] getSelectedOptions(String selectName, int index);
-
+
/**
* Get the label for a given option of a select box.
- *
+ *
* @param selectName name of the select box.
* @param optionValue label of the option.
*/
@@ -311,7 +320,7 @@
/**
* Get the label for a given option of the Nth select box with the
* specified name.
- *
+ *
* @param selectName name of the select box.
* @param index the 0-based index used when more than one select with
* the same name is expected.
@@ -319,10 +328,10 @@
*/
String getSelectOptionLabelForValue(String selectName, int index, String optionValue);
-
+
/**
* Get the value for a given option of a select box.
- *
+ *
* @param selectName name of the select box.
* @param optionLabel label of the option.
*/
@@ -331,7 +340,7 @@
/**
* Get the value for a given option of the Nth select box with
* the specified name.
- *
+ *
* @param selectName name of the select box.
* @param index the 0-based index used when more than one select with
* the same name is expected.
@@ -339,10 +348,10 @@
*/
String getSelectOptionValueForLabel(String selectName, int index, String optionLabel);
-
+
/**
* Select option(s) of a select box by value.
- *
+ *
* @param selectName name of the select box.
* @param optionValues values of the options to select.
*/
@@ -350,18 +359,18 @@
/**
* Select option(s) of the Nth select box by value.
- *
+ *
* @param selectName name of the select box.
* @param index the 0-based index of the select element when multiple
- * select elements are expected.
+ * select elements are expected.
* @param optionValues values of the options to select.
*/
void selectOptions(String selectName, int index, String[] optionValues);
-
+
/**
* Unselect option(s) of a select box by value.
- *
+ *
* @param selectName name of the select box.
* @param optionValues vaules of the options to unselect.
*/
@@ -370,18 +379,18 @@
/**
* Unselect option(s) of the Nth select box with the specified name
* by value.
- *
+ *
* @param selectName name of the select box.
* @param index the 0-based index of the select element when multiple
- * select elements are expected.
+ * select elements are expected.
* @param optionValues vaules of the options to unselect.
*/
void unselectOptions(String selectName, int index, String[] optionValues);
-
+
/**
* Test if a select box has the given option (by label).
- *
+ *
* @param selectName name of the select box.
* @param optionLabel label of the option.
* @return true if a select box has the given option (by label).
@@ -390,7 +399,7 @@
/**
* Test if a select box has the given option (by value).
- *
+ *
* @param selectName name of the select box.
* @param optionValue value of the option.
* @return true if a select box has the given option (by value).
@@ -399,10 +408,10 @@
/**
* Test if the Nth select box has the given option (by label).
- *
+ *
* @param selectName name of the select box.
* @param index the 0-based index of the select element when multiple
- * select elements are expected.
+ * select elements are expected.
* @param optionLabel label of the option.
* @return true if a select box has the given option (by label).
*/
@@ -410,19 +419,19 @@
/**
* Test if the Nth select box has the given option (by value).
- *
+ *
* @param selectName name of the select box.
* @param index the 0-based index of the select element when multiple
- * select elements are expected.
+ * select elements are expected.
* @param optionValue value of the option.
* @return true if a select box has the given option (by value).
*/
boolean hasSelectOptionValue(String selectName, int index, String optionValue);
-
+
/**
* Determines if the checkbox is selected.
- *
+ *
* @param checkBoxName name of the checkbox.
* @return true if the first checkbox with given name is selected.
*/
@@ -430,7 +439,7 @@
/**
* Determines if the checkbox is selected.
- *
+ *
* @param checkBoxName name attribut of the checkbox.
* @param checkBoxValue value attribut of the checkbox.
* @return true if the first checkbox with given name and value is selected.
@@ -439,14 +448,14 @@
/**
* Select a specified checkbox. If the checkbox is already checked then the checkbox will stay checked.
- *
+ *
* @param checkBoxName name of checkbox to be selected.
*/
void checkCheckbox(String checkBoxName);
/**
* Select a specified checkbox. If the checkbox is already checked then the checkbox will stay checked.
- *
+ *
* @param checkBoxName name of checkbox to be selected.
* @param checkBoxValue value of the checkbox (to differenciate checkboxes with the same name).
*/
@@ -454,14 +463,14 @@
/**
* Deselect a specified checkbox. If the checkbox is already unchecked then the checkbox will stay unchecked.
- *
+ *
* @param checkBoxName name of checkbox to be deselected.
*/
void uncheckCheckbox(String checkBoxName);
/**
* Deselect a specified checkbox. If the checkbox is already unchecked then the checkbox will stay unchecked.
- *
+ *
* @param checkBoxName name of checkbox to be deselected.
* @param value value of the checkbox (to differenciate checkboxes with the same name).
*/
@@ -469,7 +478,7 @@
/**
* Clicks a radio option. Asserts that the radio option exists first.
- *
+ *
* @param radioGroup name of the radio group.
* @param radioOptionValue value of the option to check for.
*/
@@ -477,12 +486,12 @@
/**
* Checks if a radio group contains the indicated option.
- *
+ *
* @param radioGroup name of the radio group.
* @param radioOptionValue value of the option to check for.
*/
boolean hasRadioOption(String radioGroup, String radioOptionValue);
-
+
/**
* Return the currently selected radio button.
* @param radioGroup name of the radio group.
@@ -492,7 +501,7 @@
/**
* Checks if the current form contains a submit button.
- *
+ *
*/
boolean hasSubmitButton();
@@ -504,7 +513,7 @@
* <li>input type=image
* <li>button type=submit
* </ul>
- *
+ *
* @param nameOrID name or id of the button to check for.
*/
boolean hasSubmitButton(String nameOrID);
@@ -517,7 +526,7 @@
* <li>input type=image
* <li>button type=submit
* </ul>
- *
+ *
* @param nameOrID name of id of the button to check for.
* @param value value of the button
*/
@@ -542,7 +551,7 @@
* <li>input type=image
* <li>button type=submit
* </ul>
- *
+ *
* @param buttonName name of the button to use for submission.
*/
void submit(String buttonName);
@@ -555,7 +564,7 @@
* <li>input type=image
* <li>button type=submit
* </ul>
- *
+ *
* @author Dragos Manolescu
* @param buttonName name of the button to use for submission.
* @param buttonValue value/label of the button to use for submission
@@ -568,7 +577,7 @@
* <li>input type=reset
* <li>button type=reset
* </ul>
- *
+ *
*/
boolean hasResetButton();
@@ -579,7 +588,7 @@
* <li>input type=reset
* <li>button type=reset
* </ul>
- *
+ *
* @param nameOrID name or id of the button to check for.
*/
boolean hasResetButton(String nameOrID);
@@ -600,7 +609,7 @@
* <li>input type=button
* <li>button type=button
* </ul>
- *
+ *
* @param text the text of the button (contents of the value attribute).
* @return <code>true</code> when the button with text could be found.
*/
@@ -612,7 +621,7 @@
* <li>input type=button
* <li>button type=button
* </ul>
- *
+ *
* @param buttonId the ID of the button.
* @return <code>true</code> when the button with text could be found.
*/
@@ -624,7 +633,7 @@
* <li>input type=button
* <li>button type=button
* </ul>
- *
+ *
* @param buttonId the ID of the button.
*/
void clickButton(String buttonId);
@@ -636,7 +645,7 @@
* <li>input type=button
* <li>button type=button
* </ul>
- *
+ *
* @param buttonValueText the text of the button (contents of the value attribute).
*/
void clickButtonWithText(String buttonValueText);
@@ -646,18 +655,18 @@
* @return an URL.
*/
URL getPageURL();
-
+
/**
* Return the string representation of the current page, encoded as specified by the current
* {@link net.sourceforge.jwebunit.util.TestContext}.
- *
+ *
* @return Visible text in the page.
*/
String getPageText();
/**
* Return the source of the current page (like in a browser).
- *
+ *
* @return Source of the page (or HTTP Body as String)
*/
String getPageSource();
@@ -665,28 +674,28 @@
/**
* Return the page title of the current response page, encoded as specified by the current
* {@link net.sourceforge.jwebunit.util.TestContext}.
- *
+ *
* @return Title of the page.
*/
String getPageTitle();
/**
* Return the response of the server for the current page.
- *
+ *
* @return HTTP header & body
*/
String getServerResponse();
/**
* Gets the last server response as input stream.
- *
+ *
*/
InputStream getInputStream();
/**
* Gets the input stream for a given URL - can be used to test images or other resources without changing the current
* navigation context.
- *
+ *
* @param url the url to the resource
*/
InputStream getInputStream(URL url)
@@ -694,7 +703,7 @@
/**
* Check if the Table object representing a specified table exists.
- *
+ *
* @param tableSummaryNameOrId summary, name or id of the table.
* @return true if table exists.
*/
@@ -703,7 +712,7 @@
/**
* Each framework have it's own way to represent a Table. Testing engines are responsible for converting to the unified
* JWebUnit format.
- *
+ *
* @param tableSummaryNameOrId summary, name or id of the table to return.
* @return unified JWebUnit representation of a table.
*/
@@ -711,7 +720,7 @@
/**
* Return true if a link is present in the current response containing the specified text.
- *
+ *
* @param linkText text to check for in links on the response.
* @param index The 0-based index, when more than one link with the same text is expected.
*/
@@ -720,9 +729,9 @@
/**
* 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...
- *
+ *
* @param linkText text to check for in links on the response.
* @param index The 0-based index, when more than one link with the same text is expected.
*/
@@ -730,7 +739,7 @@
/**
* Return true if a link is present with a given image based on filename of image.
- *
+ *
* @param imageFileName A suffix of the image's filename; for example, to match
* <tt>"images/my_icon.png"<tt>, you could just pass in
* <tt>"my_icon.png"<tt>.
@@ -742,7 +751,7 @@
/**
* Return true if a link is present in the current response with the specified id.
- *
+ *
* @param anId link id to check for.
*/
boolean hasLink(String anId);
@@ -750,7 +759,7 @@
/**
* Navigate by submitting a request based on a link containing the specified text. A RuntimeException is thrown if
* no such link can be found.
- *
+ *
* @param linkText text which link to be navigated should contain.
* @param index The 0-based index, when more than one link with the same text is expected.
*/
@@ -759,7 +768,7 @@
/**
* Navigate by clicking a link with the exact specified text. A RuntimeException is thrown if no such link can be
* found.
- *
+ *
* @param linkText exact text which link to be navigated should contain.
* @param index The 0-based index, when more than one link with the same text is expected.
*/
@@ -768,7 +777,7 @@
/**
* Navigate by submitting a request based on a link with a given ID. A RuntimeException is thrown if no such link
* can be found.
- *
+ *
* @param anID id of link to be navigated.
*/
void clickLink(String anID);
@@ -776,7 +785,7 @@
/**
* 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.
- *
+ *
* @param imageFileName A suffix of the image's filename; for example, to match <tt>"images/my_icon.png"</tt>,
* you could just pass in <tt>"my_icon.png"</tt>.
* @param index The 0-based index, when more than one link with the same text is expected.
@@ -785,7 +794,7 @@
/**
* Test if element with given id exists.
- *
+ *
* @param anID id of the element.
* @return true if element was found.
*/
@@ -793,7 +802,7 @@
/**
* Test if element with given xpath exists.
- *
+ *
* @param xpath xpath of the element.
* @return true if element was found.
*/
@@ -801,7 +810,7 @@
/**
* Click element with given xpath.
- *
+ *
* @param xpath xpath of the element.
*/
void clickElementByXPath(String xpath);
@@ -809,7 +818,7 @@
/**
* 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"
- *
+ *
* @param xpath xpath of the element.
* @param attribut name of the attribut.
* @return Attribut value or null if the element is not found.
@@ -818,15 +827,15 @@
/**
* Get text of the given element.
- *
+ *
* @param xpath xpath of the element.
*/
String getElementTextByXPath(String xpath);
-
-
+
+
/**
* Return true if a given string is contained within the specified element.
- *
+ *
* @param elementID ID of element to inspect.
* @param text text to check for.
* @return true if text was found.
@@ -835,7 +844,7 @@
/**
* Return true if a given regexp is contained within the specified element.
- *
+ *
* @param elementID Id of element to inspect.
* @param regexp regexp to match.
* @return true if a match is found.
@@ -844,7 +853,7 @@
/**
* Tell the testing engine that the given alert boxes are expected in the given order.
- *
+ *
* @param alerts Expected alerts.
* @throws ExpectedJavascriptAlertException If there are still unconsummed alert since a previous call of this
* method.
@@ -854,7 +863,7 @@
/**
* Tell the testing engine that the given confirm boxes are expected in the given order.
- *
+ *
* @param confirms Expected confirms.
* @throws ExpectedJavascriptConfirmException If there are still unconsummed confirm since a previous call of this
* method.
@@ -864,7 +873,7 @@
/**
* Tell the testing engine that the given prompt boxes are expected in the given order.
- *
+ *
* @param prompts Expected prompts.
* @throws ExpectedJavascriptPromptException If there are still unconsummed prompt since a previous call of this
* method.
@@ -872,82 +881,82 @@
void setExpectedJavaScriptPrompt(JavascriptPrompt[] prompts)
throws ExpectedJavascriptPromptException;
- /**
- * Get an element wrapper for a given xpath.
- *
- * @see #getElementsByXPath(String)
- * @param xpath XPath to evaluate
- * @return The element if found
- */
- IElement getElementByXPath(String xpath);
-
- /**
- * Get an element wrapper for a given ID.
- *
- * @param id element ID to find
- * @return The element if found
- */
- IElement getElementByID(String id);
-
- /**
- * Get a list of all elements that match the given xpath.
- *
- * @see #getElementByXPath(String)
- * @param xpath XPath to evaluate
- * @return List of all elements found
- */
- List<IElement> getElementsByXPath(String xpath);
+ /**
+ * Get an element wrapper for a given xpath.
+ *
+ * @see #getElementsByXPath(String)
+ * @param xpath XPath to evaluate
+ * @return The element if found
+ */
+ IElement getElementByXPath(String xpath);
- /**
- * Get the request response code.
- *
- * @return The request response code.
- */
- int getServerResponseCode();
-
- /**
- * Get a particular header or null.
- *
- * @param name The header name
- * @return The first header value or null
- */
- String getHeader(String name);
-
+ /**
+ * Get an element wrapper for a given ID.
+ *
+ * @param id element ID to find
+ * @return The element if found
+ */
+ IElement getElementByID(String id);
+
+ /**
+ * Get a list of all elements that match the given xpath.
+ *
+ * @see #getElementByXPath(String)
+ * @param xpath XPath to evaluate
+ * @return List of all elements found
+ */
+ List<IElement> getElementsByXPath(String xpath);
+
+ /**
+ * Get the request response code.
+ *
+ * @return The request response code.
+ */
+ int getServerResponseCode();
+
+ /**
+ * Get a particular header or null.
+ *
+ * @param name The header name
+ * @return The first header value or null
+ */
+ String getHeader(String name);
+
/**
* Get all distinct response headers. In case there are duplicate headers with same name, the last one will be returned.
- *
+ *
* @return The header values stored in a map.
* @deprecated Use {@link #getResponseHeaders()}
*/
@Deprecated
Map<String, String> getAllHeaders();
-
+
/**
* Get all response headers.
* @return the response headers as a list of {@link HttpHeader}s
*/
List<HttpHeader> getResponseHeaders();
-
+
/**
* Should the tester ignore failing status codes (300+)? Otherwise,
* failing status codes will throw an exception.
- *
+ *
* @param ignore
*/
public void setIgnoreFailingStatusCodes(boolean ignore);
-
+
/**
* Get all the comments in a document, as a list of strings.
*/
public List<String> getComments();
-
+
/**
* Set the timeout for the request. A timeout of 0 means
* an infinite timeout.
- *
+ *
* @param milliseconds the milliseconds in which to timeout, or 0 for infinite
* wait (the default).
*/
public void setTimeout(int milliseconds);
-
+
}
Modified: trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/junit/WebTester.java
===================================================================
--- trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/junit/WebTester.java 2012-11-27 15:39:46 UTC (rev 963)
+++ trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/junit/WebTester.java 2012-11-27 15:57:02 UTC (rev 964)
@@ -79,7 +79,7 @@
private ITestingEngine testingEngine = null;
private TestContext testContext = null;
-
+
/**
* This is the testing engine key that the webtester will use to find the correct testing engine from the registry.
*/
@@ -97,23 +97,23 @@
public ITestingEngine getDialog() {
return getTestingEngine();
}
-
+
/**
* Set the base url for the test context.
- *
+ *
* @param url Base url value - A trailing "/" is appended if not provided.
*/
public void setBaseUrl(String url) {
- getTestContext().setBaseUrl(url);
+ getTestContext().setBaseUrl(url);
}
-
+
/**
* Set the base url for the test context.
- *
+ *
* @param url Base url value - A trailing "/" is appended if not provided.
*/
public void setBaseUrl(URL url) {
- getTestContext().setBaseUrl(url);
+ getTestContext().setBaseUrl(url);
}
/**
@@ -260,7 +260,7 @@
}
/**
- *
+ *
* @param url Absolute or relative URL
* @param baseURL Base URL of the page
* @return Final absolute URL.
@@ -321,88 +321,88 @@
}
// Assertions
-
+
/**
* Assert that the page response has a particular code.
- *
- * @param status the expected status code
+ *
+ * @param status the expected status code
*/
public void assertResponseCode(int status) {
- assertEquals( status, getTestingEngine().getServerResponseCode() );
+ assertEquals( status, getTestingEngine().getServerResponseCode() );
}
/**
* Assert that the page response has a particular code between lower and higher
* (<code>lower <= status <= higher</code>).
- *
- * @param lower the lower bound for the expected status code
- * @param higher the upper bound for the expected status code
+ *
+ * @param lower the lower bound for the expected status code
+ * @param higher the upper bound for the expected status code
*/
public void assertResponseCodeBetween(int lower, int higher) {
- assertTrue( getTestingEngine().getServerResponseCode() >= lower && getTestingEngine().getServerResponseCode() <= higher );
- }
-
- /**
- * Should the tester ignore failing status codes (300+)? Otherwise,
- * failing status codes will throw an exception.
- *
- * @param ignore
- */
+ assertTrue( getTestingEngine().getServerResponseCode() >= lower && getTestingEngine().getServerResponseCode() <= higher );
+ }
+
+ /**
+ * Should the tester ignore failing status codes (300+)? Otherwise,
+ * failing status codes will throw an exception.
+ *
+ * @param ignore
+ */
public void setIgnoreFailingStatusCodes(boolean ignore) {
- getTestingEngine().setIgnoreFailingStatusCodes(ignore);
+ getTestingEngine().setIgnoreFailingStatusCodes(ignore);
}
-
+
/**
* Assert a header is present.
- *
+ *
* @param name The header to find
*/
public void assertHeaderPresent(String name) {
- assertFalse( "header '" + name + "' not present", getTestingEngine().getHeader(name) == null );
+ assertFalse( "header '" + name + "' not present", getTestingEngine().getHeader(name) == null );
}
-
+
/**
* Assert a header is NOT present.
- *
+ *
* @param name The header to find
*/
public void assertHeaderNotPresent(String name) {
- assertTrue( "header '" + name + "' present", getTestingEngine().getHeader(name) == null );
+ assertTrue( "header '" + name + "' present", getTestingEngine().getHeader(name) == null );
}
-
+
/**
* Assert a header is equal to a particular value.
- *
+ *
* @param name Header to find
* @param value Value to compare against
*/
public void assertHeaderEquals(String name, String value) {
- assertEquals( value, getTestingEngine().getHeader(name) );
+ assertEquals( value, getTestingEngine().getHeader(name) );
}
-
+
/**
* Assert a header matches a particular pattern.
- *
+ *
* @param name Header to find
* @param regexp Pattern to compare against
*/
public void assertHeaderMatches(String name, String regexp) {
- assertMatch("Unable to match [" + regexp + "] in header [" + name + "]", regexp, getTestingEngine().getHeader(name));
+ assertMatch("Unable to match [" + regexp + "] in header [" + name + "]", regexp, getTestingEngine().getHeader(name));
}
-
+
/**
* Get a particular header value.
- *
+ *
* @param name Header to find
* @return The found header value, or null
*/
public String getHeader(String name) {
- return getTestingEngine().getHeader(name);
+ return getTestingEngine().getHeader(name);
}
-
+
/**
* Get all response headers.
- *
+ *
* @return A map of response headers
* @deprecated This method do not deal with several headers with same name. Use {@link #getResponseHeaders()} instead.
*/
@@ -410,10 +410,10 @@
public Map<String, String> getAllHeaders() {
return getTestingEngine().getAllHeaders();
}
-
+
/**
* Return all HTTP headers that are in last response. It is possible to have several headers with same name.
- *
+ *
* @return A list of {@link HttpHeader} elements.
*/
public List<HttpHeader> getResponseHeaders() {
@@ -430,7 +430,7 @@
public void assertTitleEquals(String title) {
assertEquals(title, getTestingEngine().getPageTitle());
}
-
+
/**
* Assert title of current html page in conversation is not
* equal to another value.
@@ -441,7 +441,7 @@
*/
@Deprecated
public void assertTitleNotSame(String title) {
- assertTitleNotEquals(title);
+ assertTitleNotEquals(title);
}
/**
@@ -452,7 +452,7 @@
* unexpected title value
*/
public void assertTitleNotEquals(String title) {
- assertThat(title, not(equalTo(getTestingEngine().getPageTitle())));
+ assertThat(title, not(equalTo(getTestingEngine().getPageTitle())));
}
/**
@@ -461,7 +461,7 @@
* @param regexp expected title regexp
*/
public void assertTitleMatch(String regexp) {
- assertMatch("Unable to match [" + regexp + "] in title", regexp, getTestingEngine().getPageTitle());
+ assertMatch("Unable to match [" + regexp + "] in title", regexp, getTestingEngine().getPageTitle());
}
/**
@@ -528,31 +528,31 @@
fail("Expected rexexp not matched in response: [" + regexp
+ "]");
}
-
+
/**
* Assert a given string matches a given regular expression.
- *
+ *
* @param regexp
* @param text
*/
public void assertMatch(String regexp, String text) {
- assertMatch("Expected rexexp '" + regexp + "' not matched in text '" + text + "'", regexp, text);
+ assertMatch("Expected rexexp '" + regexp + "' not matched in text '" + text + "'", regexp, text);
}
/**
* Assert a given string does not match a given regular expression.
- *
+ *
* @param regexp
* @param text
*/
public void assertNotMatch(String regexp, String text) {
- assertNotMatch("Expected rexexp '" + regexp + "' matched in text '" + text + "'", regexp, text);
+ assertNotMatch("Expected rexexp '" + regexp + "' matched in text '" + text + "'", regexp, text);
}
-
+
/**
* Assert a given string matches a given regular expression.
- *
+ *
* @param regexp
* @param text
*/
@@ -564,7 +564,7 @@
/**
* Assert a given string does not match a given regular expression.
- *
+ *
* @param regexp
* @param text
*/
@@ -573,7 +573,7 @@
if (re.match(text))
fail(message);
}
-
+
/**
* Assert that a web resource's value is not present.
*
@@ -610,9 +610,9 @@
* @param regexp
*/
public void assertNoMatch(String regexp) {
- assertNotMatch("Regexp matched in response when not expected: [" + regexp + "]",
- regexp,
- getTestingEngine().getPageText());
+ assertNotMatch("Regexp matched in response when not expected: [" + regexp + "]",
+ regexp,
+ getTestingEngine().getPageText());
}
/**
@@ -1020,6 +1020,17 @@
}
/**
+ * Assert that there is a form with the specified name or id and the given index present.
+ *
+ * @param nameOrID
+ * @param index The 0-based index, when more than one form with the same name is expected.
+ */
+ public void assertFormPresent(String nameOrID, int index) {
+ assertTrue("No form present with name or id [" + nameOrID + "] at index " + index,
+ getTestingEngine().hasForm(nameOrID, index));
+ }
+
+ /**
* Assert that there is not a form present.
*
*/
@@ -1060,7 +1071,7 @@
* @param regexp
*/
public void assertFormElementMatch(String formElementName, String regexp) {
- // how can we @deprecate this if there is no available alternative?
+ // how can we @deprecate this if there is no available alternative?
assertFormElementPresent(formElementName);
RE re = null;
try {
@@ -1080,7 +1091,7 @@
* @param formElementName
* @see #setTextField(String, String)
* @see #setHiddenField(String, String)
- * @deprecated use an explicit testing method, e.g. {@link #setTextField(String, String)} or {@link #setHiddenField(String, String)}
+ * @deprecated use an explicit testing method, e.g. {@link #setTextField(String, String)} or {@link #setHiddenField(String, String)}
*/
public void assertFormElementEmpty(String formElementName) {
assertFormElementPresent(formElementName);
@@ -1207,7 +1218,7 @@
public void assertRadioOptionSelected(String name, String radioOption) {
assertRadioOptionPresent(name, radioOption);
assertEquals(radioOption, getTestingEngine()
- .getSelectedRadio(name));
+ .getSelectedRadio(name));
}
/**
@@ -1317,8 +1328,8 @@
* @param optionValues option labels.
*/
public void assertSelectOptionValuesPresent(String selectName,
- int index,
- String[] optionValues) {
+ int index,
+ String[] optionValues) {
assertFormElementPresent(selectName);
for (int i = 0; i < optionValues.length; i++)
assertTrue("Option [" + optionValues[i]
@@ -1337,8 +1348,8 @@
* @param optionValue option value.
*/
public void assertSelectOptionValuePresent(String selectName,
- int index,
- String optionValue) {
+ int index,
+ String optionValue) {
assertSelectOptionValuesPresent(selectName, index,
new String[] { optionValue });
}
@@ -2084,7 +2095,7 @@
*/
public void assertLinkNotPresentWithImage(String imageFileName, int index) {
assertFalse("Link with image file [" + imageFileName
- + "] and index " + index + " found in response.",
+ + "] and index " + index + " found in response.",
getTestingEngine().hasLinkWithImage(imageFileName, index));
}
@@ -2127,30 +2138,30 @@
assertFalse("Located element with xpath \"" + xpath + "\"",
getTestingEngine().hasElementByXPath(xpath));
}
-
+
/**
* Get all the comments in a document, as a list of strings.
*/
public List<String> getComments() {
- return getTestingEngine().getComments();
+ return getTestingEngine().getComments();
}
-
+
/**
* Assert that a comment is present.
- *
+ *
* @param comment
*/
public void assertCommentPresent(String comment) {
- assertTrue("Comment present: '" + comment + "'", getComments().contains(comment.trim()));
+ assertTrue("Comment present: '" + comment + "'", getComments().contains(comment.trim()));
}
-
+
/**
* Assert that a comment is not present.
- *
+ *
* @param comment
*/
public void assertCommentNotPresent(String comment) {
- assertFalse("Comment not present: '" + comment + "'", getComments().contains(comment.trim()));
+ assertFalse("Comment not present: '" + comment + "'", getComments().contains(comment.trim()));
}
/**
@@ -2363,6 +2374,7 @@
* @param index The 0-based index, when more than one form with the same name is expected.
*/
public void setWorkingForm(String nameOrId, int index) {
+ assertFormPresent(nameOrId, index);
getTestingEngine().setWorkingForm(nameOrId, index);
}
@@ -2683,7 +2695,7 @@
}
/**
- * Get the attribute value of the given element.
+ * Get the attribute value of the given element.
* For example, if you have an element <code><img src="test.gif" alt="picture"></code>
* getElementAttributeByXPath("//img[@src='test.gif']", "alt") returns "picture".
*
@@ -2695,12 +2707,12 @@
assertElementPresentByXPath(xpath);
return getTestingEngine().getElementAttributByXPath(xpath, attribute);
}
-
+
/**
- * @deprecated Use {@link #getElementAttributeByXPath(String, String)}
+ * @deprecated Use {@link #getElementAttributeByXPath(String, String)}
*/
public String getElementAttributByXPath(String xpath, String attribute) {
- return getElementAttributeByXPath(xpath, attribute);
+ return getElementAttributeByXPath(xpath, attribute);
}
/**
@@ -2710,7 +2722,7 @@
*/
public String getElementTextByXPath(String xpath){
assertElementPresentByXPath(xpath);
- return getTestingEngine().getElementTextByXPath(xpath);
+ return getTestingEngine().getElementTextByXPath(xpath);
}
/**
@@ -2718,11 +2730,11 @@
*
* @param xpath XPath to search
* @return the requested element
- * @throws AssertionError if the element xpath is not found
+ * @throws AssertionError if the element xpath is not found
*/
public IElement getElementByXPath(String xpath) {
- assertElementPresentByXPath(xpath);
- return getTestingEngine().getElementByXPath(xpath);
+ assertElementPresentByXPath(xpath);
+ return getTestingEngine().getElementByXPath(xpath);
}
@@ -2731,11 +2743,11 @@
*
* @param id element ID to find
* @return the requested element
- * @throws AssertionError if the element is not found
+ * @throws AssertionError if the element is not found
*/
public IElement getElementById(String id) {
- assertElementPresent(id);
- return getTestingEngine().getElementByID(id);
+ assertElementPresent(id);
+ return getTestingEngine().getElementByID(id);
}
/**
@@ -2745,53 +2757,53 @@
* @return the requested elements found
*/
public List<IElement> getElementsByXPath(String xpath) {
- return getTestingEngine().getElementsByXPath(xpath);
+ return getTestingEngine().getElementsByXPath(xpath);
}
-
+
// label methods
/**
* Assert a label for a given ID exists.
*/
public void assertLabelPresent(String id) {
- assertNotNull("No label found with id [" + id + "]", getLabel(id));
+ assertNotNull("No label found with id [" + id + "]", getLabel(id));
}
-
+
/**
* Get a label for a particular ID.
- *
+ *
* @param id
* @return
*/
private IElement getLabel(String id) {
- // get all labels
- for (IElement e : getTestingEngine().getElementsByXPath("//label")) {
- if (id.equals(e.getAttribute("id")))
- return e; // label found
- }
- return null;
+ // get all labels
+ for (IElement e : getTestingEngine().getElementsByXPath("//label")) {
+ if (id.equals(e.getAttribute("id")))
+ return e; // label found
+ }
+ return null;
}
-
+
/**
* Find a particular element with given text
- *
+ *
* @param elementName the element type e.g. "input", "label"
* @param text the text to search for
* @return the found element, or null
*/
private IElement getElementWithText(String elementName, String text) {
- for (IElement e : getTestingEngine().getElementsByXPath("//" + elementName)) {
- if (elementName.equals(e.getName()) && text.equals(e.getTextContent())) {
- return e;
- }
- }
- return null;
+ for (IElement e : getTestingEngine().getElementsByXPath("//" + elementName)) {
+ if (elementName.equals(e.getName()) && text.equals(e.getTextContent())) {
+ return e;
+ }
+ }
+ return null;
}
/**
* Assert a label exists.
*/
public void assertLabelMatches(String regexp) {
- // get regexp
+ // get regexp
RE re = null;
try {
re = new RE(regexp, RE.MATCH_SINGLELINE);
@@ -2800,97 +2812,97 @@
}
// get all labels
- for (IElement e : getTestingEngine().getElementsByXPath("//label")) {
- if (e.getName().equals("label") && re.match( e.getTextContent() ))
- return; // label found
- }
- fail("No label found with text matching [" + regexp + "]");
+ for (IElement e : getTestingEngine().getElementsByXPath("//label")) {
+ if (e.getName().equals("label") && re.match( e.getTextContent() ))
+ return; // label found
+ }
+ fail("No label found with text matching [" + regexp + "]");
}
-
+
/**
* Get all the fields of type <code>input</code>, <code>textarea</code> or <code>select</code>
* that are referenced or contained in a particular label.
- *
+ *
* @param label The label to consider
* @return A list of all fields contained or referenced in this label
*/
public List<IElement> getFieldsForLabel(IElement label) {
- List<IElement> fields = new java.util.ArrayList<IElement>();
- // a direct "for" attribute
- if (label.getAttribute("for") != null) {
- IElement e = getTestingEngine().getElementByID(label.getAttribute("for"));
- if (e != null)
- fields.add(e);
- }
-
- // implicitly the elements inside the label
- if (fields.isEmpty()) {
- // get elements inside the label
- for (IElement e : label.getChildren()) {
- if (e.getName().equals("input") || e.getName().equals("textarea") || e.getName().equals("select")) {
- fields.add(e);
- }
- }
- }
-
- return fields;
+ List<IElement> fields = new java.util.ArrayList<IElement>();
+ // a direct "for" attribute
+ if (label.getAttribute("for") != null) {
+ IElement e = getTestingEngine().getElementByID(label.getAttribute("for"));
+ if (e != null)
+ fields.add(e);
+ }
+
+ // implicitly the elements inside the label
+ if (fields.isEmpty()) {
+ // get elements inside the label
+ for (IElement e : label.getChildren()) {
+ if (e.getName().equals("input") || e.getName().equals("textarea") || e.getName().equals("select")) {
+ fields.add(e);
+ }
+ }
+ }
+
+ return fields;
}
-
-
+
+
/**
* Private method - test the value of a field connected to a particular IElement label.
- *
+ *
* @param identifier the HTML ID for the given labelled field
* @param label the label found for the given HTML field
* @param fieldText the value to check is equal
*/
private void assertLabeledFieldEquals(String identifier, IElement label, String fieldText) {
- String value = getLabeledFieldValue(identifier, label);
- assertEquals("unexpected value of field for label [" + identifier + "]", fieldText, value == null ? "" : value);
+ String value = getLabeledFieldValue(identifier, label);
+ assertEquals("unexpected value of field for label [" + identifier + "]", fieldText, value == null ? "" : value);
}
-
+
/**
- * Get the current value of a given labelled field.
- *
+ * Get the current value of a given labelled field.
+ *
* @param identifier the HTML ID for the given labelled field
* @param label the label found for the given HTML ID
- * @return the value found in a field for the given label/ID, or
+ * @return the value found in a field for the given label/ID, or
* <code>null</code> if none was found
*/
public String getLabeledFieldValue(String identifier, IElement label) {
- List<IElement> fields = getFieldsForLabel(label);
-
- assertFalse("No field found for label [" + identifier + "]", fields.isEmpty());
- String value = null;
- // cycle through all fields trying to find value
- for (IElement field : fields) {
- if (value != null) // stop at first correct value found
- break;
- if (field == null)
- throw new RuntimeException("unexpected null field");
-
- if ("input".equals(field.getName())) {
- if (field.getAttribute("type") != null) {
- if (field.getAttribute("type").toLowerCase().equals("checkbox")) {
- if (field.getAttribute("checked") != null) {
- value = field.getAttribute("value");
- }
- } else if (field.getAttribute("type").toLowerCase().equals("radio")) {
- if (field.getAttribute("checked") != null) {
- value = field.getAttribute("value");
- }
- } else {
- // any other input type
- value = field.getAttribute("value");
- }
- } else {
- // unspecified input type, default = text
- value = field.getAttribute("value");
- }
- } else if ("textarea".equals(field.getName())) {
- value = field.getTextContent();
- } else if ("select".equals(field.getName())) {
- // get the selected option
+ List<IElement> fields = getFieldsForLabel(label);
+
+ assertFalse("No field found for label [" + identifier + "]", fields.isEmpty());
+ String value = null;
+ // cycle through all fields trying to find value
+ for (IElement field : fields) {
+ if (value != null) // stop at first correct value found
+ break;
+ if (field == null)
+ throw new RuntimeException("unexpected null field");
+
+ if ("input".equals(field.getName())) {
+ if (field.getAttribute("type") != null) {
+ if (field.getAttribute("type").toLowerCase().equals("checkbox")) {
+ if (field.getAttribute("checked") != null) {
+ value = field.getAttribute("value");
+ }
+ } else if (field.getAttribute("type").toLowerCase().equals("radio")) {
+ if (field.getAttribute("checked") != null) {
+ value = field.getAttribute("value");
+ }
+ } else {
+ // any other input type
+ value = field.getAttribute("value");
+ }
+ } else {
+ // unspecified input type, default = text
+ value = field.getAttribute("value");
+ }
+ } else if ("textarea".equals(field.getName())) {
+ value = field.getTextContent();
+ } else if ("select".equals(field.getName())) {
+ // get the selected option
for (IElement child : field.getChildren()) {
if (child.getName().equals("option") && child.getAttribute("selected") != null) {
value = child.getAttribute("value");
@@ -2905,82 +2917,82 @@
}
}
}
- } else {
- throw new RuntimeException("Unexpected field type " + field.getName());
- }
- }
-
- return value;
+ } else {
+ throw new RuntimeException("Unexpected field type " + field.getName());
+ }
+ }
+
+ return value;
}
-
+
/**
* Assert that a labeled field exists (for the given ID) and the
* field that it labels equals the given text
- *
+ *
* @param id the HTML ID for the given labelled field
* @param fieldText the text that the field's value should equal
* @see #getLabeledFieldValue(String, IElement, String)
* @see #getLabel(String)
*/
public void assertLabeledFieldEquals(String id, String fieldText) {
- IElement label = getLabel(id);
- assertNotNull("no label for id [" + id + "] found", label);
-
- assertLabeledFieldEquals(id, label, fieldText);
+ IElement label = getLabel(id);
+ assertNotNull("no label for id [" + id + "] found", label);
+
+ assertLabeledFieldEquals(id, label, fieldText);
}
-
+
public void setLabeledFormElementField(String id, String value) {
- IElement label = getLabel(id);
- assertNotNull("no label for id [" + id + "] found", label);
-
- List<IElement> fields = getFieldsForLabel(label);
- assertFalse("there should be at least one element referenced for label [" + id + "]", fields.size()==0);
-
- // find the first element that we can change
- for (IElement field : fields) {
- if (field == null)
- throw new RuntimeException("unexpected null field");
-
- if ("input".equals(field.getName())) {
- if (field.getAttribute("type") != null) {
- if (field.getAttribute("type").toLowerCase().equals("checkbox")) {
- if (value.equals(field.getAttribute("value"))) {
- field.setAttribute("checked");
- return;
- }
- } else if (field.getAttribute("type").toLowerCase().equals("radio")) {
- if (value.equals(field.getAttribute("value"))) {
- field.setAttribute("checked");
- return;
- }
- } else {
- // any other input type
- field.setAttribute("value", value);
- return;
- }
- } else {
- // unspecified input type, default = text
- field.setAttribute("value", value);
- return;
- }
- } else if ("textarea".equals(field.getName())) {
- field.setTextContent(value);
- return;
- } else if ("select".equals(field.getName())) {
- // get the selected option
- for (IElement children : field.getChildren()) {
- // find the option which matches the given value (we can't specify random values)
- if (children.getName().equals("option") && value.equals(children.getAttribute("value"))) {
- children.setAttribute("selected");
- return;
- }
- }
- } else {
- throw new RuntimeException("Unexpected field type " + field.getName());
- }
- }
-
- fail("could not find any fields for label [" + id + "] to set.");
+ IElement label = getLabel(id);
+ assertNotNull("no label for id [" + id + "] found", label);
+
+ List<IElement> fields = getFieldsForLabel(label);
+ assertFalse("there should be at least one element referenced for label [" + id + "]", fields.size()==0);
+
+ // find the first element that we can change
+ for (IElement field : fields) {
+ if (field == null)
+ throw new RuntimeException("unexpected null field");
+
+ i...
[truncated message content] |