Revision: 460
Author: henryju
Date: 2006-05-22 08:26:46 -0700 (Mon, 22 May 2006)
ViewCVS: http://svn.sourceforge.net/jwebunit/?rev=460&view=rev
Log Message:
-----------
Refactor API concerning getSelect* and select* to allow option identification
by value or by label.
Modified Paths:
--------------
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/FormAssertionsTest.java
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/FormSubmissionTest.java
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/JavaScriptEventsTest.java
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/WebAssertionsTest.java
trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/IJWebUnitDialog.java
trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/WebTestCase.java
trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/WebTester.java
trunk/jwebunit-htmlunit-plugin/src/main/java/net/sourceforge/jwebunit/htmlunit/HtmlUnitDialog.java
trunk/jwebunit-httpunit-plugin/src/main/java/net/sourceforge/jwebunit/httpunit/HttpUnitDialog.java
trunk/jwebunit-jacobie-plugin/src/main/java/net/sourceforge/jwebunit/jacobie/JacobieDialog.java
trunk/jwebunit-selenium-plugin/src/main/java/net/sourceforge/jwebunit/selenium/SeleniumDialog.java
Modified:
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/FormAssertionsTest.java
===================================================================
---
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/FormAssertionsTest.java
2006-05-22 12:58:33 UTC (rev 459)
+++
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/FormAssertionsTest.java
2006-05-22 15:26:46 UTC (rev 460)
@@ -131,51 +131,70 @@
public void testAssertSelectOptionPresent() throws Throwable {
beginAt("/testPage.html");
- assertPassFail("assertOptionPresent",
+ assertPassFail("assertSelectOptionPresent",
new String[]{"selectOption", "One"},
new String[]{"selectOption", "NoSuchOption"});
}
public void testAssertSelectOptionNotPresent() throws Throwable {
beginAt("/testPage.html");
- assertPassFail("assertOptionNotPresent",
+ assertPassFail("assertSelectOptionNotPresent",
new String[]{"selectOption", "NoSuchOption"},
new String[]{"selectOption", "One"});
}
- public void testAssertOptionsEqual() throws Throwable {
+ public void testAssertSelectOptionValuePresent() throws Throwable {
beginAt("/testPage.html");
- assertPass("assertOptionsEqual", new Object[]{"select1", new
String[]{"one", "two", "three", "four"}});
- assertFail("assertOptionsEqual", new Object[]{"select1", new
String[]{"one", "four", "three", "two"}});
- assertFail("assertOptionsEqual", new Object[]{"select1", new
String[]{"one", "two", "three", "four", "five"}});
+ assertPassFail("assertSelectOptionValuePresent",
+ new String[]{"selectOption", "1"},
+ new String[]{"selectOption", "NoSuchOption"});
}
+
+ public void testAssertSelectOptionValueNotPresent() throws Throwable {
+ beginAt("/testPage.html");
+ assertPassFail("assertSelectOptionValueNotPresent",
+ new String[]{"selectOption", "NoSuchOption"},
+ new String[]{"selectOption", "1"});
+ }
- public void testAssertOptionsNotEqual() throws Throwable {
+ public void testAssertSelectOptionsEqual() throws Throwable {
beginAt("/testPage.html");
- assertFail("assertOptionsNotEqual", new Object[]{"select1", new
String[]{"one", "two", "three", "four"}});
- assertPass("assertOptionsNotEqual", new Object[]{"select1", new
String[]{"one", "four", "three", "two"}});
- assertPass("assertOptionsNotEqual", new Object[]{"select1", new
String[]{"one", "two", "three", "four", "five"}});
+ assertPass("assertSelectOptionsEqual", new Object[]{"select1", new
String[]{"one", "two", "three", "four"}});
+ assertFail("assertSelectOptionsEqual", new Object[]{"select1", new
String[]{"one", "four", "three", "two"}});
+ assertFail("assertSelectOptionsEqual", new Object[]{"select1", new
String[]{"one", "two", "three", "four", "five"}});
}
- public void testAssertOptionValuesEqual() throws Throwable {
+ public void testAssertSelectOptionsNotEqual() throws Throwable {
beginAt("/testPage.html");
- assertPass("assertOptionValuesEqual", new Object[]{"select1", new
String[]{"1", "2", "3", "4"}});
- assertFail("assertOptionValuesEqual", new Object[]{"select1", new
String[]{"1", "4", "3", "2"}});
- assertFail("assertOptionValuesEqual", new Object[]{"select1", new
String[]{"1", "2", "3", "4", "5"}});
+ assertFail("assertSelectOptionsNotEqual", new Object[]{"select1", new
String[]{"one", "two", "three", "four"}});
+ assertPass("assertSelectOptionsNotEqual", new Object[]{"select1", new
String[]{"one", "four", "three", "two"}});
+ assertPass("assertSelectOptionsNotEqual", new Object[]{"select1", new
String[]{"one", "two", "three", "four", "five"}});
}
- public void testAssertOptionValuesNotEqual() throws Throwable {
+ public void testAssertSelectOptionValuesEqual() throws Throwable {
beginAt("/testPage.html");
- assertFail("assertOptionValuesNotEqual", new Object[]{"select1", new
String[]{"1", "2", "3", "4"}});
- assertPass("assertOptionValuesNotEqual", new Object[]{"select1", new
String[]{"1", "4", "3", "2"}});
- assertPass("assertOptionValuesNotEqual", new Object[]{"select1", new
String[]{"1", "2", "3", "4", "5"}});
+ assertPass("assertSelectOptionValuesEqual", new Object[]{"select1",
new String[]{"1", "2", "3", "4"}});
+ assertFail("assertSelectOptionValuesEqual", new Object[]{"select1",
new String[]{"1", "4", "3", "2"}});
+ assertFail("assertSelectOptionValuesEqual", new Object[]{"select1",
new String[]{"1", "2", "3", "4", "5"}});
}
+ public void testAssertSelectOptionValuesNotEqual() throws Throwable {
+ beginAt("/testPage.html");
+ assertFail("assertSelectOptionValuesNotEqual", new Object[]{"select1",
new String[]{"1", "2", "3", "4"}});
+ assertPass("assertSelectOptionValuesNotEqual", new Object[]{"select1",
new String[]{"1", "4", "3", "2"}});
+ assertPass("assertSelectOptionValuesNotEqual", new Object[]{"select1",
new String[]{"1", "2", "3", "4", "5"}});
+ }
+
public void testAssertSelectedOptionEquals() throws Throwable {
beginAt("/testPage.html");
assertPassFail("assertSelectedOptionEquals", new String[]{"select1",
"one"}, new String[]{"select1", "two"});
}
+ public void testAssertSelectedOptionValueEquals() throws Throwable {
+ beginAt("/testPage.html");
+ assertPassFail("assertSelectedOptionValueEquals", new
String[]{"select1", "1"}, new String[]{"select1", "2"});
+ }
+
public void testAssertButtonPresent() throws Throwable {
beginAt("/testPage.html");
assertPassFail("assertButtonPresent", "b1", "nobutton");
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
2006-05-22 12:58:33 UTC (rev 459)
+++
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/FormSubmissionTest.java
2006-05-22 15:26:46 UTC (rev 460)
@@ -163,7 +163,14 @@
assertSelectedOptionEquals("select1", "two");
}
- public void testSimpleLabeledForm() {
+ public void testSelectOptionByValue() {
+ beginAt("/MultiFormPage.html");
+ assertSelectedOptionValueEquals("select1", "1");
+ selectOptionByValue("select1", "2");
+ assertSelectedOptionValueEquals("select1", "2");
+ }
+
+ public void testSimpleLabeledForm() {
beginAt("/QueryFormSimple.html");
setFormElementWithLabel("First", "oneValue");
setFormElementWithLabel("Second", "anotherValue");
Modified:
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/JavaScriptEventsTest.java
===================================================================
---
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/JavaScriptEventsTest.java
2006-05-22 12:58:33 UTC (rev 459)
+++
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/JavaScriptEventsTest.java
2006-05-22 15:26:46 UTC (rev 460)
@@ -93,7 +93,7 @@
public void testOnChangeSetsWindowLocation() throws Exception {
beginAt("onchange.html");
assertTitleEquals("The Title");
- selectOptions("testSelect", new String[] {"Value2"});
+ selectOption("testSelect", "Value2");
assertTitleEquals("Submitted parameters");
assertTextPresent(" testSelect=V2 ");
}
Modified:
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/WebAssertionsTest.java
===================================================================
---
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/WebAssertionsTest.java
2006-05-22 12:58:33 UTC (rev 459)
+++
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/WebAssertionsTest.java
2006-05-22 15:26:46 UTC (rev 460)
@@ -154,12 +154,12 @@
assertFail("assertFormElementMatch", new Object[] {"testInputElement",
"Another[Vv]alue"});
}
- public void testAssertOptionEquals() throws Throwable {
+ public void testAssertSelectedOptionEquals() throws Throwable {
assertSelectedOptionEquals("testSelect", "Value1");
assertFail("assertSelectedOptionEquals", new Object[] {"testSelect",
"AnotherValue"});
}
- public void testAssertOptionMatch() throws Throwable {
+ public void testAssertSelectedOptionMatch() throws Throwable {
assertSelectedOptionMatches("testSelect", "[Vv]alue1");
assertFail("assertSelectedOptionMatches", new Object[] {"testSelect",
"Another[Vv]alue"});
}
Modified:
trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/IJWebUnitDialog.java
===================================================================
---
trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/IJWebUnitDialog.java
2006-05-22 12:58:33 UTC (rev 459)
+++
trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/IJWebUnitDialog.java
2006-05-22 15:26:46 UTC (rev 460)
@@ -180,7 +180,7 @@
void setTextField(String inputName, String text);
/**
- * Return a string array of select box option labels. <br/>
+ * Return a string array of select box option values.
*
* Exemple: <br/>
*
@@ -199,49 +199,31 @@
* </FORM>
* </pre>
*
- * Should return [Component_1, Component_2, Component_3, Component_4,
+ * Should return [Component_1_a, Component_1_b, Component_3, Component_4,
* Component_5]
*
* @param selectName
* name of the select box.
*/
- String[] getOptionsFor(String selectName);
+ String[] getSelectOptionValues(String selectName);
/**
- * Return a string array of select box option values.
+ * Return the values of the currently selected items in a select box.
*
- * Exemple: <br/>
- *
- * <pre>
- * <FORM action="http://my_host/doit"
method="post">
- * <P>
- * <SELECT multiple size="4"
name="component-select">
- * <OPTION selected
value="Component_1_a">Component_1</OPTION>
- * <OPTION selected
value="Component_1_b">Component_2</OPTION>
- * <OPTION>Component_3</OPTION>
- * <OPTION>Component_4</OPTION>
- * <OPTION>Component_5</OPTION>
- * </SELECT>
- * <INPUT type="submit"
value="Send"><INPUT type="reset">
- * </P>
- * </FORM>
- * </pre>
- *
- * Should return [Component_1_a, Component_1_b, Component_3, Component_4,
- * Component_5]
- *
* @param selectName
* name of the select box.
*/
- String[] getOptionValuesFor(String selectName);
+ String[] getSelectedOptions(String selectName);
/**
- * Return the label of the currently selected items in a select box.
+ * Get the label for a given option of a select box.
*
* @param selectName
* name of the select box.
+ * @param optionValue
+ * label of the option.
*/
- String[] getSelectedOptions(String selectName);
+ String getSelectOptionLabelForValue(String selectName, String optionValue);
/**
* Get the value for a given option of a select box.
@@ -251,15 +233,15 @@
* @param optionLabel
* label of the option.
*/
- String getValueForOption(String selectName, String optionLabel);
+ String getSelectOptionValueForLabel(String selectName, String optionLabel);
/**
* Select option(s) of a select box by value.
*
* @param selectName
* name of the select box.
- * @param options
- * labels of the options to select.
+ * @param optionsValue
+ * values of the options to select.
*/
void selectOptions(String selectName, String[] optionsValue);
@@ -268,8 +250,8 @@
*
* @param selectName
* name of the select box.
- * @param options
- * labels of the options to unselect.
+ * @param optionsValue
+ * vaules of the options to unselect.
*/
void unselectOptions(String selectName, String[] options);
@@ -285,6 +267,17 @@
boolean hasSelectOption(String selectName, String optionLabel);
/**
+ * 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).
+ */
+ boolean hasSelectOptionValue(String selectName, String optionValue);
+
+ /**
* Determines if the checkbox is selected.
*
* @param checkBoxName
Modified:
trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/WebTestCase.java
===================================================================
--- trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/WebTestCase.java
2006-05-22 12:58:33 UTC (rev 459)
+++ trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/WebTestCase.java
2006-05-22 15:26:46 UTC (rev 460)
@@ -303,38 +303,54 @@
getTester().assertRadioOptionNotSelected(radioGroup, radioOption);
}
- public void assertOptionPresent(String selectName, String optionLabel) {
- getTester().assertOptionPresent(selectName, optionLabel);
+ public void assertSelectOptionPresent(String selectName, String
optionLabel) {
+ getTester().assertSelectOptionPresent(selectName, optionLabel);
}
- public void assertOptionNotPresent(String selectName, String optionLabel) {
- getTester().assertOptionNotPresent(selectName, optionLabel);
+ public void assertSelectOptionNotPresent(String selectName, String
optionLabel) {
+ getTester().assertSelectOptionNotPresent(selectName, optionLabel);
}
- public void assertOptionsEqual(String selectName, String[] options) {
- getTester().assertOptionsEqual(selectName, options);
+ public void assertSelectOptionValuePresent(String selectName, String
optionValue) {
+ getTester().assertSelectOptionValuePresent(selectName, optionValue);
}
- public void assertOptionsNotEqual(String selectName, String[] options) {
- getTester().assertOptionsNotEqual(selectName, options);
+ public void assertSelectOptionValueNotPresent(String selectName, String
optionValue) {
+ getTester().assertSelectOptionValueNotPresent(selectName, optionValue);
}
- public void assertOptionValuesEqual(String selectName, String[] options) {
- getTester().assertOptionValuesEqual(selectName, options);
+ public void assertSelectOptionsEqual(String selectName, String[] options) {
+ getTester().assertSelectOptionsEqual(selectName, options);
}
- public void assertOptionValuesNotEqual(String selectName, String[]
options) {
- getTester().assertOptionValuesNotEqual(selectName, options);
+ public void assertSelectOptionsNotEqual(String selectName, String[]
options) {
+ getTester().assertSelectOptionsNotEqual(selectName, options);
}
- public void assertSelectedOptionEquals(String selectName, String option) {
- getTester().assertSelectedOptionEquals(selectName, option);
+ public void assertSelectOptionValuesEqual(String selectName, String[]
options) {
+ getTester().assertSelectOptionValuesEqual(selectName, options);
}
- public void assertSelectedOptionsEqual(String selectName, String[]
options) {
- getTester().assertSelectedOptionsEqual(selectName, options);
+ public void assertSelectOptionValuesNotEqual(String selectName, String[]
options) {
+ getTester().assertSelectOptionValuesNotEqual(selectName, options);
}
+ public void assertSelectedOptionEquals(String selectName, String label) {
+ getTester().assertSelectedOptionEquals(selectName, label);
+ }
+
+ public void assertSelectedOptionsEqual(String selectName, String[] labels)
{
+ getTester().assertSelectedOptionsEqual(selectName, labels);
+ }
+
+ public void assertSelectedOptionValueEquals(String selectName, String
value) {
+ getTester().assertSelectedOptionValueEquals(selectName, value);
+ }
+
+ public void assertSelectedOptionValuesEqual(String selectName, String[]
values) {
+ getTester().assertSelectedOptionValuesEqual(selectName, values);
+ }
+
public void assertSelectedOptionMatches(String selectName, String regexp) {
tester.assertSelectedOptionMatches(selectName, regexp);
}
@@ -535,14 +551,29 @@
getTester().uncheckCheckbox(checkBoxName, value);
}
- public void selectOption(String selectName, String option) {
- getTester().selectOption(selectName, option);
+ /**
+ * Select an option with a given display label in a select element.
+ *
+ * @param selectName
+ * name of select element.
+ * @param label
+ * label of option to be selected.
+ */
+ public void selectOption(String selectName, String label) {
+ getTester().selectOption(selectName, label);
}
- public void selectOptions(String selectName, String[] options) {
- getTester().selectOptions(selectName, options);
+ public void selectOptions(String selectName, String[] labels) {
+ getTester().selectOptions(selectName, labels);
}
+ public void selectOptionByValue(String selectName, String value) {
+ getTester().selectOptionByValue(selectName, value);
+ }
+
+ public void selectOptionsByValues(String selectName, String[] values) {
+ getTester().selectOptionsByValues(selectName, values);
+ }
// Form submission and link navigation methods
public void submit() {
Modified:
trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/WebTester.java
===================================================================
--- trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/WebTester.java
2006-05-22 12:58:33 UTC (rev 459)
+++ trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/WebTester.java
2006-05-22 15:26:46 UTC (rev 460)
@@ -866,26 +866,78 @@
}
/**
- * Assert that a specific option is present in a select box.
+ * Assert that given options are present in a select box (by label).
*
* @param selectName
* name of the select element.
* @param optionLabels
* option labels.
*/
- public void assertOptionsPresent(String selectName, String[] optionLabels)
{
+ public void assertSelectOptionsPresent(String selectName,
+ String[] optionLabels) {
assertFormElementPresent(selectName);
- for (int i=0; i<optionLabels.length; i++)
- Assert.assertTrue("Option [" + optionLabels[i]
- + "] not found in select element " + selectName, getDialog()
- .hasSelectOption(selectName, optionLabels[i]));
+ for (int i = 0; i < optionLabels.length; i++)
+ Assert.assertTrue("Option [" + optionLabels[i]
+ + "] not found in select element " + selectName,
+ getDialog().hasSelectOption(selectName, optionLabels[i]));
}
-
- public void assertOptionPresent(String selectName, String optionLabel) {
- assertOptionsPresent(selectName, new String[]{optionLabel});
+
+ /**
+ * Assert that a specific option is present in a select box (by label).
+ *
+ * @param selectName
+ * name of the select element.
+ * @param optionLabel
+ * option label.
+ */
+ public void assertSelectOptionPresent(String selectName, String
optionLabel) {
+ assertSelectOptionsPresent(selectName, new String[] { optionLabel });
}
/**
+ * Assert that given options are present in a select box (by value).
+ *
+ * @param selectName
+ * name of the select element.
+ * @param optionValues
+ * option labels.
+ */
+ public void assertSelectOptionValuesPresent(String selectName,
+ String[] optionValues) {
+ assertFormElementPresent(selectName);
+ for (int i = 0; i < optionValues.length; i++)
+ Assert.assertTrue("Option [" + optionValues[i]
+ + "] not found in select element " + selectName,
+ getDialog().hasSelectOptionValue(selectName,
+ optionValues[i]));
+ }
+
+ /**
+ * Assert that a specific option is present in a select box (by value).
+ *
+ * @param selectName
+ * name of the select element.
+ * @param optionValue
+ * option value.
+ */
+ public void assertSelectOptionValuePresent(String selectName,
+ String optionValue) {
+ assertSelectOptionValuesPresent(selectName,
+ new String[] { optionValue });
+ }
+
+ public void assertSelectOptionValueNotPresent(String selectName,
+ String optionValue) {
+ try {
+ assertSelectOptionValuePresent(selectName, optionValue);
+ } catch (AssertionFailedError e) {
+ return;
+ }
+ Assert.fail("Option value" + optionValue + " found in select element "
+ + selectName + " when not expected.");
+ }
+
+ /**
* Assert that a specific option is not present in a select box.
*
* @param selectName
@@ -893,11 +945,15 @@
* @param expectedOption
* option label.
*/
- public void assertOptionNotPresent(String selectName, String optionLabel) {
- assertFormElementPresent(selectName);
- Assert.assertTrue("Option " + optionLabel + " found in select element "
- + selectName + " when not expected.", !getDialog()
- .hasSelectOption(selectName, optionLabel));
+ public void assertSelectOptionNotPresent(String selectName,
+ String optionLabel) {
+ try {
+ assertSelectOptionPresent(selectName, optionLabel);
+ } catch (AssertionFailedError e) {
+ return;
+ }
+ Assert.fail("Option " + optionLabel + " found in select element "
+ + selectName + " when not expected.");
}
/**
@@ -907,12 +963,12 @@
* @param selectName
* name of the select element.
* @param expectedOptions
- * expected display values for the select box.
+ * expected labels for the select box.
*/
- public void assertOptionsEqual(String selectName, String[]
expectedOptions) {
+ public void assertSelectOptionsEqual(String selectName,
+ String[] expectedOptions) {
assertFormElementPresent(selectName);
- assertArraysEqual(expectedOptions, getDialog()
- .getOptionsFor(selectName));
+ assertArraysEqual(expectedOptions, getOptionsFor(selectName));
}
/**
@@ -924,11 +980,11 @@
* @param expectedOptions
* expected display values for the select box.
*/
- public void assertOptionsNotEqual(String selectName,
+ public void assertSelectOptionsNotEqual(String selectName,
String[] expectedOptions) {
assertFormElementPresent(selectName);
try {
- assertOptionsEqual(selectName, expectedOptions);
+ assertSelectOptionsEqual(selectName, expectedOptions);
} catch (AssertionFailedError e) {
return;
}
@@ -944,23 +1000,14 @@
* @param expectedValues
* expected values for the select box.
*/
- public void assertOptionValuesEqual(String selectName,
+ public void assertSelectOptionValuesEqual(String selectName,
String[] expectedValues) {
assertFormElementPresent(selectName);
- assertArraysEqual(expectedValues, getDialog().getOptionValuesFor(
+ assertArraysEqual(expectedValues, getDialog().getSelectOptionValues(
selectName));
}
- private void assertArraysEqual(String[] exptected, String[] returned) {
- Assert.assertEquals("Arrays not same length", exptected.length,
- returned.length);
- for (int i = 0; i < returned.length; i++) {
- Assert.assertEquals("Elements " + i + "not equal", exptected[i],
- returned[i]);
- }
- }
-
/**
* Assert that the values of a select element's options do not match a
given
* array of strings.
@@ -970,11 +1017,11 @@
* @param optionValues
* expected values for the select box.
*/
- public void assertOptionValuesNotEqual(String selectName,
+ public void assertSelectOptionValuesNotEqual(String selectName,
String[] optionValues) {
assertFormElementPresent(selectName);
try {
- assertOptionValuesEqual(selectName, optionValues);
+ assertSelectOptionValuesEqual(selectName, optionValues);
} catch (AssertionFailedError e) {
return;
}
@@ -982,28 +1029,61 @@
}
/**
- * Assert that the currently selected display value(s) of a select box
- * matches given value(s).
+ * Assert that the currently selected display label(s) of a select box
+ * matches given label(s).
*
* @param selectName
* name of the select element.
- * @param options
- * expected display value(s) of the selected option.
+ * @param labels
+ * expected display label(s) of the selected option.
*/
- public void assertSelectedOptionsEqual(String selectName, String[]
options) {
+ public void assertSelectedOptionsEqual(String selectName, String[] labels)
{
assertFormElementPresent(selectName);
- Assert.assertEquals(options.length, getDialog().getSelectedOptions(
+ Assert.assertEquals(labels.length, getDialog().getSelectedOptions(
selectName).length);
- for (int i = 0; i < options.length; i++)
- Assert.assertEquals(options[i], getDialog().getSelectedOptions(
- selectName)[i]);
+ for (int i = 0; i < labels.length; i++)
+ Assert.assertEquals(labels[i], getDialog()
+ .getSelectOptionLabelForValue(selectName,
+ getDialog().getSelectedOptions(selectName)[i]));
}
-
+
public void assertSelectedOptionEquals(String selectName, String option) {
- assertSelectedOptionsEqual(selectName, new String[]{option});
+ assertSelectedOptionsEqual(selectName, new String[] { option });
}
/**
+ * Assert that the currently selected value(s) of a select box matches
given
+ * value(s).
+ *
+ * @param selectName
+ * name of the select element.
+ * @param values
+ * expected value(s) of the selected option.
+ */
+ public void assertSelectedOptionValuesEqual(String selectName,
+ String[] values) {
+ assertFormElementPresent(selectName);
+ Assert.assertEquals(values.length, getDialog().getSelectedOptions(
+ selectName).length);
+ for (int i = 0; i < values.length; i++)
+ Assert.assertEquals(values[i], getDialog().getSelectedOptions(
+ selectName)[i]);
+ }
+
+ /**
+ * Assert that the currently selected value of a select box matches given
+ * value.
+ *
+ * @param selectName
+ * name of the select element.
+ * @param value
+ * expected value of the selected option.
+ */
+ public void assertSelectedOptionValueEquals(String selectName, String
value) {
+ assertSelectedOptionValuesEqual(selectName, new String[] { value });
+ }
+
+ /**
* Assert that the currently selected display value(s) of a select box
* matches a given value(s).
*
@@ -1024,9 +1104,9 @@
.match(getDialog().getSelectedOptions(selectName)[i]));
}
}
-
+
public void assertSelectedOptionMatches(String selectName, String regexp) {
- assertSelectedOptionsMatch(selectName, new String[]{regexp});
+ assertSelectedOptionsMatch(selectName, new String[] { regexp });
}
/**
@@ -1133,8 +1213,8 @@
*/
public void assertLinkPresentWithText(String linkText) {
Assert.assertTrue("Link with text [" + linkText
- + "] not found in response.", getDialog()
- .hasLinkWithText(linkText, 0));
+ + "] not found in response.", getDialog().hasLinkWithText(
+ linkText, 0));
}
/**
@@ -1172,8 +1252,8 @@
*/
public void assertLinkNotPresentWithText(String linkText, int index) {
Assert.assertTrue("Link with text [" + linkText + "] and index "
- + index + " found in response.", !getDialog()
- .hasLinkWithText(linkText, index));
+ + index + " found in response.", !getDialog().hasLinkWithText(
+ linkText, index));
}
// BEGIN RFE 996031...
@@ -1185,8 +1265,8 @@
*/
public void assertLinkPresentWithExactText(String linkText) {
Assert.assertTrue("Link with Exact text [" + linkText
- + "] not found in response.", getDialog()
- .hasLinkWithExactText(linkText, 0));
+ + "] not found in response.", getDialog().hasLinkWithExactText(
+ linkText, 0));
}
/**
@@ -1196,8 +1276,8 @@
*/
public void assertLinkNotPresentWithExactText(String linkText) {
Assert.assertTrue("Link with Exact text [" + linkText
- + "] found in response.", !getDialog()
- .hasLinkWithExactText(linkText, 0));
+ + "] found in response.", !getDialog().hasLinkWithExactText(
+ linkText, 0));
}
/**
@@ -1240,8 +1320,8 @@
*/
public void assertLinkPresentWithImage(String imageFileName) {
Assert.assertTrue("Link with image file [" + imageFileName
- + "] not found in response.", getDialog()
- .hasLinkWithImage(imageFileName, 0));
+ + "] not found in response.", getDialog().hasLinkWithImage(
+ imageFileName, 0));
}
/**
@@ -1564,21 +1644,55 @@
}
/**
- * Select an option with a given display value in a select element.
+ * Select options with given display labels in a select element.
*
* @param selectName
* name of select element.
- * @param option
- * display value of option to be selected.
+ * @param labels
+ * labels of options to be selected.
*/
- public void selectOptions(String selectName, String[] options) {
- assertOptionsPresent(selectName, options);
- getDialog().selectOptions(selectName, options);
+ public void selectOptions(String selectName, String[] labels) {
+ assertSelectOptionsPresent(selectName, labels);
+ selectOptionsByLabel(selectName, labels);
}
- public void selectOption(String selectName, String option) {
- selectOptions(selectName, new String[] {option});
+ /**
+ * Select an option with a given display label in a select element.
+ *
+ * @param selectName
+ * name of select element.
+ * @param label
+ * label of option to be selected.
+ */
+ public void selectOption(String selectName, String label) {
+ selectOptions(selectName, new String[] { label });
}
+
+ /**
+ * Select options with given values in a select element.
+ *
+ * @param selectName
+ * name of select element.
+ * @param values
+ * values of options to be selected.
+ */
+ public void selectOptionsByValues(String selectName, String[] values) {
+ assertSelectOptionValuesPresent(selectName, values);
+ getDialog().selectOptions(selectName, values);
+ }
+
+ /**
+ * Select an option with a given value in a select element.
+ *
+ * @param selectName
+ * name of select element.
+ * @param values
+ * values of options to be selected.
+ */
+ public void selectOptionByValue(String selectName, String value) {
+ selectOptionsByValues(selectName, new String[] { value });
+ }
+
// Form submission and link navigation methods
/**
@@ -1798,13 +1912,13 @@
+ ExceptionUtility
.stackTraceToString(aTestingEngineResponseException));
}
-
+
public void dumpCookies() {
String[][] cookies = getDialog().getCookies();
- for (int i=0;i<cookies.length;i++) {
- System.out.println(cookies[i][0]+"="+cookies[i][1]);
+ for (int i = 0; i < cookies.length; i++) {
+ System.out.println(cookies[i][0] + "=" + cookies[i][1]);
}
-
+
}
// Debug methods
@@ -1916,8 +2030,15 @@
*/
public String getTestingEngineKey() {
if (testingEngineKey == null) {
- // default to using the httpunit testing engine.
- setTestingEngineKey(TestingEngineRegistry.TESTING_ENGINE_HTTPUNIT);
+ // use first available dialog
+ if (TestingEngineRegistry.getTestingEngineMap().keys()
+ .hasMoreElements()) {
+ setTestingEngineKey((String) TestingEngineRegistry
+ .getTestingEngineMap().keys().nextElement());
+ } else {
+ throw new RuntimeException(
+ "TestingEngineRegistry contains no dialog. Check you
put at least one plugin in the classpath.");
+ }
}
return testingEngineKey;
}
@@ -1973,4 +2094,67 @@
}
return false;
}
+
+ /**
+ * Return a string array of select box option labels. <br/>
+ *
+ * Exemple: <br/>
+ *
+ * <pre>
+ * <FORM action="http://my_host/doit"
method="post">
+ * <P>
+ * <SELECT multiple size="4"
name="component-select">
+ * <OPTION selected
value="Component_1_a">Component_1</OPTION>
+ * <OPTION selected
value="Component_1_b">Component_2</OPTION>
+ * <OPTION>Component_3</OPTION>
+ * <OPTION>Component_4</OPTION>
+ * <OPTION>Component_5</OPTION>
+ * </SELECT>
+ * <INPUT type="submit"
value="Send"><INPUT type="reset">
+ * </P>
+ * </FORM>
+ * </pre>
+ *
+ * Should return [Component_1, Component_2, Component_3, Component_4,
+ * Component_5]
+ *
+ * @param selectName
+ * name of the select box.
+ */
+ private String[] getOptionsFor(String selectName) {
+ String[] values = getDialog().getSelectOptionValues(selectName);
+ String[] result = new String[values.length];
+ for (int i = 0; i < values.length; i++) {
+ result[i] = getDialog().getSelectOptionLabelForValue(selectName,
+ values[i]);
+ }
+ return result;
+ }
+
+ /**
+ * Select options by given labels in a select box
+ *
+ * @param selectName
+ * name of the select
+ * @param labels
+ * labels of options to be selected
+ */
+ private void selectOptionsByLabel(String selectName, String[] labels) {
+ String[] values = new String[labels.length];
+ for (int i = 0; i < values.length; i++) {
+ values[i] = getDialog().getSelectOptionValueForLabel(selectName,
+ labels[i]);
+ }
+ getDialog().selectOptions(selectName, values);
+ }
+
+ private void assertArraysEqual(String[] exptected, String[] returned) {
+ Assert.assertEquals("Arrays not same length", exptected.length,
+ returned.length);
+ for (int i = 0; i < returned.length; i++) {
+ Assert.assertEquals("Elements " + i + "not equal", exptected[i],
+ returned[i]);
+ }
+ }
+
}
\ No newline at end of file
Modified:
trunk/jwebunit-htmlunit-plugin/src/main/java/net/sourceforge/jwebunit/htmlunit/HtmlUnitDialog.java
===================================================================
---
trunk/jwebunit-htmlunit-plugin/src/main/java/net/sourceforge/jwebunit/htmlunit/HtmlUnitDialog.java
2006-05-22 12:58:33 UTC (rev 459)
+++
trunk/jwebunit-htmlunit-plugin/src/main/java/net/sourceforge/jwebunit/htmlunit/HtmlUnitDialog.java
2006-05-22 15:26:46 UTC (rev 460)
@@ -336,22 +336,22 @@
getForm().getInputByName(fieldName).setValueAttribute(paramValue);
}
- /**
- * Return a string array of select box option labels.
- *
- * @param selectName
- * name of the select box.
- */
- public String[] getOptionsFor(String selectName) {
- HtmlSelect sel = getForm().getSelectByName(selectName);
- ArrayList result = new ArrayList();
- List opts = sel.getOptions();
- for (int i = 0; i < opts.size(); i++) {
- HtmlOption opt = (HtmlOption) opts.get(i);
- result.add(opt.asText());
- }
- return (String[]) result.toArray(new String[0]);
- }
+// /**
+// * Return a string array of select box option labels.
+// *
+// * @param selectName
+// * name of the select box.
+// */
+// public String[] getOptionsFor(String selectName) {
+// HtmlSelect sel = getForm().getSelectByName(selectName);
+// ArrayList result = new ArrayList();
+// List opts = sel.getOptions();
+// for (int i = 0; i < opts.size(); i++) {
+// HtmlOption opt = (HtmlOption) opts.get(i);
+// result.add(opt.asText());
+// }
+// return (String[]) result.toArray(new String[0]);
+// }
/**
* Return a string array of select box option values.
@@ -359,7 +359,7 @@
* @param selectName
* name of the select box.
*/
- public String[] getOptionValuesFor(String selectName) {
+ public String[] getSelectOptionValues(String selectName) {
HtmlSelect sel = getForm().getSelectByName(selectName);
ArrayList result = new ArrayList();
List opts = sel.getOptions();
@@ -375,28 +375,34 @@
List opts = sel.getSelectedOptions();
String[] result = new String[opts.size()];
for (int i = 0; i < result.length; i++)
- result[i] = ((HtmlOption) opts.get(i)).asText();
+ result[i] = ((HtmlOption) opts.get(i)).getValueAttribute();
return result;
}
- /**
- * Get the value for a given option of a select box.
- *
- * @param selectName
- * name of the select box.
- * @param option
- * label of the option.
- */
- public String getValueForOption(String selectName, String option) {
- String[] opts = getOptionsFor(selectName);
- for (int i = 0; i < opts.length; i++) {
- if (opts[i].equals(option))
- return getOptionValuesFor(selectName)[i];
+ public String getSelectOptionValueForLabel(String selectName, String
label) {
+ HtmlSelect sel = getForm().getSelectByName(selectName);
+ List opts = sel.getOptions();
+ for (int i = 0; i < opts.size(); i++) {
+ HtmlOption opt = (HtmlOption) opts.get(i);
+ if (opt.asText().equals(label))
+ return opt.getValueAttribute();
}
- throw new RuntimeException("Unable to find option " + option + " for "
+ throw new RuntimeException("Unable to find option " + label + " for "
+ selectName);
}
+ public String getSelectOptionLabelForValue(String selectName, String
value) {
+ HtmlSelect sel = getForm().getSelectByName(selectName);
+ List opts = sel.getOptions();
+ for (int i = 0; i < opts.size(); i++) {
+ HtmlOption opt = (HtmlOption) opts.get(i);
+ if (opt.getValueAttribute().equals(value))
+ return opt.asText();
+ }
+ throw new RuntimeException("Unable to find option " + value + " for "
+ + selectName);
+ }
+
public String getPageSource() {
return getCurrentPage().getWebResponse().getContentAsString();
}
@@ -1265,10 +1271,10 @@
* label of the option.
*/
public boolean hasSelectOption(String selectName, String optionLabel) {
- String[] opts = getOptionsFor(selectName);
+ String[] opts = getSelectOptionValues(selectName);
for (int i = 0; i < opts.length; i++) {
- String opt = opts[i];
- if (opt.equals(optionLabel))
+ String label = getSelectOptionLabelForValue(selectName, opts[i]);
+ if (label.equals(optionLabel))
return true;
}
return false;
@@ -1282,8 +1288,8 @@
* @param optionValue
* value of the option.
*/
- public boolean hasSelectOptionByValue(String selectName, String
optionValue) {
- String[] opts = getOptionValuesFor(selectName);
+ public boolean hasSelectOptionValue(String selectName, String optionValue)
{
+ String[] opts = getSelectOptionValues(selectName);
for (int i = 0; i < opts.length; i++) {
if (opts[i].equals(optionValue))
return true;
Modified:
trunk/jwebunit-httpunit-plugin/src/main/java/net/sourceforge/jwebunit/httpunit/HttpUnitDialog.java
===================================================================
---
trunk/jwebunit-httpunit-plugin/src/main/java/net/sourceforge/jwebunit/httpunit/HttpUnitDialog.java
2006-05-22 12:58:33 UTC (rev 459)
+++
trunk/jwebunit-httpunit-plugin/src/main/java/net/sourceforge/jwebunit/httpunit/HttpUnitDialog.java
2006-05-22 15:26:46 UTC (rev 460)
@@ -1258,15 +1258,15 @@
return false;
}
- /**
- * Return a string array of select box option labels.
- *
- * @param selectName
- * name of the select box.
- */
- public String[] getOptionsFor(String selectName) {
- return getForm().getOptions(selectName);
- }
+// /**
+// * Return a string array of select box option labels.
+// *
+// * @param selectName
+// * name of the select box.
+// */
+// public String[] getOptionsFor(String selectName) {
+// return getForm().getOptions(selectName);
+// }
/**
* Return a string array of select box option values.
@@ -1274,7 +1274,7 @@
* @param selectName
* name of the select box.
*/
- public String[] getOptionValuesFor(String selectName) {
+ public String[] getSelectOptionValues(String selectName) {
return getForm().getOptionValues(selectName);
}
@@ -1285,14 +1285,8 @@
* name of the select box.
*/
public String[] getSelectedOptions(String selectName) {
- String val = getFormParameterValue(selectName);
- String[] vals = getOptionValuesFor(selectName);
// TODO Manage multi-select in getSelectedOptions
- for (int i = 0; i < vals.length; i++) {
- if (vals[i].equals(val))
- return new String[] { getOptionsFor(selectName)[i] };
- }
- return null;
+ return new String[]{getFormParameterValue(selectName)};
}
/**
@@ -1300,22 +1294,22 @@
*
* @param selectName
* name of the select box.
- * @param option
+ * @param label
* label of the option.
*/
- public String getValueForOption(String selectName, String option) {
- String[] opts = getOptionsFor(selectName);
+ public String getSelectOptionValueForLabel(String selectName, String
label) {
+ String[] opts = getForm().getOptions(selectName);
for (int i = 0; i < opts.length; i++) {
- if (opts[i].equals(option))
- return getOptionValuesFor(selectName)[i];
+ if (opts[i].equals(label))
+ return getSelectOptionValues(selectName)[i];
}
- throw new RuntimeException("Unable to find option " + option + " for "
+ throw new RuntimeException("Unable to find option " + label + " for "
+ selectName);
}
- public String getLabelForOption(String selectName, String optionValue) {
- String[] opts = getOptionsFor(selectName);
- String[] optsValues = getOptionValuesFor(selectName);
+ public String getSelectOptionLabelForValue(String selectName, String
optionValue) {
+ String[] opts = getForm().getOptions(selectName);
+ String[] optsValues = getSelectOptionValues(selectName);
for (int i = 0; i < opts.length; i++) {
if (optsValues[i].equals(optionValue))
return opts[i];
@@ -1334,25 +1328,43 @@
* @return
*/
public boolean hasSelectOption(String selectName, String optionLabel) {
- String[] opts = getOptionsFor(selectName);
- for (int i = 0; i < opts.length; i++) {
- if (opts[i].equals(optionLabel))
+ String[] optLabels = getForm().getOptions(selectName);
+ for (int i = 0; i < optLabels.length; i++) {
+ if (optLabels[i].equals(optionLabel))
return true;
}
return false;
}
/**
- * Select an option of a select box by display label.
+ * Return true if a select box has the given option (by value).
*
* @param selectName
* name of the select box.
- * @param options
- * label of the option(s) to select.
+ * @param optionValue
+ * value of the option.
+ * @return
*/
- public void selectOptions(String selectName, String[] options) {
+ public boolean hasSelectOptionValue(String selectName, String optionValue)
{
+ String[] optValues = getSelectOptionValues(selectName);
+ for (int i = 0; i < optValues.length; i++) {
+ if (optValues[i].equals(optionValue))
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Select an option of a select box by value.
+ *
+ * @param selectName
+ * name of the select box.
+ * @param values
+ * value(s) of the option(s) to select.
+ */
+ public void selectOptions(String selectName, String[] values) {
// TODO Manage multi-select in selectOptions
- setFormParameter(selectName, options[0]);
+ setFormParameter(selectName, values[0]);
}
public void unselectOptions(String selectName, String[] options) {
Modified:
trunk/jwebunit-jacobie-plugin/src/main/java/net/sourceforge/jwebunit/jacobie/JacobieDialog.java
===================================================================
---
trunk/jwebunit-jacobie-plugin/src/main/java/net/sourceforge/jwebunit/jacobie/JacobieDialog.java
2006-05-22 12:58:33 UTC (rev 459)
+++
trunk/jwebunit-jacobie-plugin/src/main/java/net/sourceforge/jwebunit/jacobie/JacobieDialog.java
2006-05-22 15:26:46 UTC (rev 460)
@@ -1358,4 +1358,36 @@
}
+ /* (non-Javadoc)
+ * @see
net.sourceforge.jwebunit.IJWebUnitDialog#getSelectOptionLabelForValue(java.lang.String,
java.lang.String)
+ */
+ public String getSelectOptionLabelForValue(String selectName, String
optionValue) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see
net.sourceforge.jwebunit.IJWebUnitDialog#getSelectOptionValueForLabel(java.lang.String,
java.lang.String)
+ */
+ public String getSelectOptionValueForLabel(String selectName, String
optionLabel) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see
net.sourceforge.jwebunit.IJWebUnitDialog#getSelectOptionValues(java.lang.String)
+ */
+ public String[] getSelectOptionValues(String selectName) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see
net.sourceforge.jwebunit.IJWebUnitDialog#hasSelectOptionValue(java.lang.String,
java.lang.String)
+ */
+ public boolean hasSelectOptionValue(String selectName, String optionValue)
{
+ // TODO Auto-generated method stub
+ return false;
+ }
+
}
\ No newline at end of file
Modified:
trunk/jwebunit-selenium-plugin/src/main/java/net/sourceforge/jwebunit/selenium/SeleniumDialog.java
===================================================================
---
trunk/jwebunit-selenium-plugin/src/main/java/net/sourceforge/jwebunit/selenium/SeleniumDialog.java
2006-05-22 12:58:33 UTC (rev 459)
+++
trunk/jwebunit-selenium-plugin/src/main/java/net/sourceforge/jwebunit/selenium/SeleniumDialog.java
2006-05-22 15:26:46 UTC (rev 460)
@@ -563,6 +563,10 @@
throw new UnsupportedOperationException("hasSelectOption");
}
+ public boolean hasSelectOptionValue(String selectName, String optionValue)
{
+ throw new UnsupportedOperationException("hasSelectOption");
+ }
+
/**
* Return true if a select box contains the indicated option.
*
@@ -1273,4 +1277,28 @@
}
+ /* (non-Javadoc)
+ * @see
net.sourceforge.jwebunit.IJWebUnitDialog#getSelectOptionLabelForValue(java.lang.String,
java.lang.String)
+ */
+ public String getSelectOptionLabelForValue(String selectName, String
optionValue) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see
net.sourceforge.jwebunit.IJWebUnitDialog#getSelectOptionValueForLabel(java.lang.String,
java.lang.String)
+ */
+ public String getSelectOptionValueForLabel(String selectName, String
optionLabel) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see
net.sourceforge.jwebunit.IJWebUnitDialog#getSelectOptionValues(java.lang.String)
+ */
+ public String[] getSelectOptionValues(String selectName) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Jwebunit-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jwebunit-development