On Wednesday 26 July 2006 14:48, Julien HENRY wrote:
> There is no validation on dev ml. Sometimes, sourceforge is very slow. Do
> not forget to check your spam directory.
>
> assertTextInElement find all XML text node in a given element.
>
> For example :
> <textarea>toto</textarea>
> can be checked with assertTextInElement(id, toto)
>
> But I think it will not work if the content of textarea is dynamically
> updated (for example thanks to Javascript). You should check valueParameter
> of textarea for checking current content.
Mmmh, not sure about that. As far as I know, there is no value attribute in
the textarea html tag.
Check the following patch... should be ok. Any remarks or suggestions are
welcome.
Cheers,
Fred.
*DISCLAIMER*
This e-mail (including any attachments) may contain information which is
privileged or confidential or constitute non-public information.It is to be
conveyed only to the intended recipient(s).If you received this e-mail in
error, please notify the sender immediately by e-mail or telephone and delete
the e-mail from your system without reading, copying or disclosing its contents
to any other person.
Index: jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/FormAssertionsTest.java
===================================================================
--- jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/FormAssertionsTest.java (revision 535)
+++ jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/FormAssertionsTest.java (working copy)
@@ -57,10 +57,15 @@
public void testAssertFormElementEquals() throws Throwable {
beginAt("/testPage.html");
- assertPass("assertFormElementEquals", new Object[]{"testInputElement", "testValue"});
- assertPass("assertFormElementEquals", new Object[]{"submitButton", "buttonLabel"});
- assertFail("assertFormElementEquals", new Object[]{"testInputElement", "noSuchValue"});
- assertFail("assertFormElementEquals", new Object[]{"noSuchElement", "testValue"});
+ assertPass("assertTextFieldEquals", new Object[]{"testInputElement", "testValue"});
+ assertPass("assertSubmitButtonPresent", new Object[]{"submitButton", "buttonLabel"});
+ assertPass("assertTextFieldEquals", new Object[]{"textarea", "sometexthere"});
+ assertPass("assertRadioOptionSelected", new Object[]{"cool", "dog"});
+ assertPass("assertHiddenFieldEquals", new Object[]{"hiddenelement", "hiddenvalue"});
+ assertFail("assertTextFieldEquals", new Object[]{"testInputElement", "noSuchValue"});
+ assertFail("assertTextFieldEquals", new Object[]{"noSuchElement", "testValue"});
+ assertFail("assertHiddenFieldEquals", new Object[]{"noSuchElement", "testValue"});
+ assertFail("assertHiddenFieldEquals", new Object[]{"hiddenelement", "notThisValue"});
}
public void testCheckboxSelected() throws Throwable {
Index: jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/WebAssertionsTest.java
===================================================================
--- jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/WebAssertionsTest.java (revision 535)
+++ jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/WebAssertionsTest.java (working copy)
@@ -148,10 +148,23 @@
assertMatchInElement("outer_id", "Inner.*Text");
}
+ /**
+ * @deprecated
+ */
public void testAssertFormElementEquals() throws Throwable {
assertFormElementEquals("testInputElement", "testValue");
assertFail("assertFormElementEquals", new Object[] {"testInputElement", "AnotherValue"});
}
+
+ public void testAssertTextFieldEquals() throws Throwable {
+ assertTextFieldEquals("testInputElement", "testValue");
+ assertFail("assertTextFieldEquals", new Object[] {"testInputElement", "AnotherValue"});
+ }
+
+ public void testAssertHiddenFieldEquals() throws Throwable {
+ assertHiddenFieldEquals("hidden", "h");
+ assertFail("assertHiddenFieldEquals", new Object[] {"hidden", "AnotherValue"});
+ }
public void testAssertFormElementMatch() throws Throwable {
assertFormElementMatch("testInputElement", "test[Vv]alue");
Index: jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/CharsetTest.java
===================================================================
--- jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/CharsetTest.java (revision 535)
+++ jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/CharsetTest.java (working copy)
@@ -14,33 +14,33 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Jesse Wilson</a>
*/
public class CharsetTest extends JWebUnitAPITestCase {
- public CharsetTest(String name) {
- super(name);
- }
+ public CharsetTest(String name) {
+ super(name);
+ }
- public static Test suite() {
- return new JettySetup(new TestSuite(CharsetTest.class));
- }
+ public static Test suite() {
+ return new JettySetup(new TestSuite(CharsetTest.class));
+ }
- public void setUp() throws Exception {
- super.setUp();
- getTestContext().setBaseUrl(HOST_PATH+"/CharsetTest");
- beginAt("/charset.html_utf-8");
- }
+ public void setUp() throws Exception {
+ super.setUp();
+ getTestContext().setBaseUrl(HOST_PATH+"/CharsetTest");
+ beginAt("/charset.html_utf-8");
+ }
- public void testEuro() {
- assertFormElementEquals("eur", "\u20AC");
- }
+ public void testEuro() {
+ assertTextFieldEquals("eur", "\u20AC");
+ }
- public void testDollar() {
- assertFormElementEquals("usd", "$");
- }
+ public void testDollar() {
+ assertTextFieldEquals("usd", "$");
+ }
- public void testYen() {
- assertFormElementEquals("yen", "\u00A5");
- }
+ public void testYen() {
+ assertTextFieldEquals("yen", "\u00A5");
+ }
- public void testPound() {
- assertFormElementEquals("gbp", "\u00A3");
- }
+ public void testPound() {
+ assertTextFieldEquals("gbp", "\u00A3");
+ }
}
\ No newline at end of file
Index: jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/JavaScriptEventsTest.java
===================================================================
--- jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/JavaScriptEventsTest.java (revision 535)
+++ jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/JavaScriptEventsTest.java (working copy)
@@ -99,9 +99,9 @@
public void testGreenLink() {
beginAt("index.html");
- assertFormElementEquals("color", "blue");
+ assertTextFieldEquals("color", "blue");
clickLink("SetColorGreen");
- assertFormElementEquals("color", "green");
+ assertTextFieldEquals("color", "green");
}
public void testFormOnSubmitSetTarget() {
Index: jwebunit-commons-tests/src/main/resources/testcases/FormAssertionsTest/testPage.html
===================================================================
--- jwebunit-commons-tests/src/main/resources/testcases/FormAssertionsTest/testPage.html (revision 535)
+++ jwebunit-commons-tests/src/main/resources/testcases/FormAssertionsTest/testPage.html (working copy)
@@ -36,6 +36,8 @@
<option value="3">three</option>
<option value="4">four</option>
</select> <input type="reset" name="resetButton" /></form>
+ <form id="form5"><textarea name="textarea">sometexthere</textarea>
+ <input type="hidden" name="hiddenelement" value="hiddenvalue"/></form>
</td>
</tr>
</table>
Index: jwebunit-htmlunit-plugin/src/main/java/net/sourceforge/jwebunit/htmlunit/HtmlUnitDialog.java
===================================================================
--- jwebunit-htmlunit-plugin/src/main/java/net/sourceforge/jwebunit/htmlunit/HtmlUnitDialog.java (revision 535)
+++ jwebunit-htmlunit-plugin/src/main/java/net/sourceforge/jwebunit/htmlunit/HtmlUnitDialog.java (working copy)
@@ -40,6 +40,7 @@
import com.gargoylesoftware.htmlunit.WebWindowListener;
import com.gargoylesoftware.htmlunit.WebWindowNotFoundException;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
+import com.gargoylesoftware.htmlunit.html.HtmlHiddenInput;
import com.gargoylesoftware.htmlunit.html.HtmlInput;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlButtonInput;
@@ -57,6 +58,7 @@
import com.gargoylesoftware.htmlunit.html.ClickableElement;
import com.gargoylesoftware.htmlunit.html.HtmlRadioButtonInput;
import com.gargoylesoftware.htmlunit.html.HtmlTextArea;
+import com.gargoylesoftware.htmlunit.html.HtmlTextInput;
import com.gargoylesoftware.htmlunit.ElementNotFoundException;
import com.gargoylesoftware.htmlunit.html.HtmlTableRow.CellIterator;
import com.gargoylesoftware.htmlunit.html.xpath.HtmlUnitXPath;
@@ -308,6 +310,7 @@
*
* @param paramName
* name of the input element.
+ * @deprecated
*/
public String getFormParameterValue(String paramName) {
checkFormStateWithInput(paramName);
@@ -328,8 +331,57 @@
}
throw new RuntimeException("getFormParameterValue failed");
}
+
+ /**
+ * Return the current value of a text input element with name <code>paramName</code>.
+ *
+ * @param paramName
+ * name of the input element.
+ * TODO: Find a way to handle multiple text input element with same name.
+ */
+ public String getTextFieldParameterValue(String paramName) {
+ checkFormStateWithInput(paramName);
+ List textFieldElements = getForm().getHtmlElementsByAttribute("input", "type", "text");
+ Iterator it = textFieldElements.iterator();
+ while(it.hasNext()) {
+ HtmlTextInput textInput = (HtmlTextInput) it.next();
+ if (paramName.equals(textInput.getNameAttribute())) {
+ return textInput.getValueAttribute();
+ }
+ }
+ // If no text field with the name paramName then try with textareas.
+ textFieldElements = getForm().getTextAreasByName(paramName);
+ it = textFieldElements.iterator();
+ while(it.hasNext()) {
+ HtmlTextArea textInput = (HtmlTextArea) it.next();
+ if (paramName.equals(textInput.getNameAttribute())) {
+ return textInput.getText();
+ }
+ }
+ throw new RuntimeException("getTextFieldParameterValue failed, text field with name [" + paramName + "] does not exist.");
+ }
/**
+ * Return the current value of a hidden input element with name <code>paramName</code>.
+ *
+ * @param paramName
+ * name of the input element.
+ * TODO: Find a way to handle multiple hidden input element with same name.
+ */
+ public String getHiddenFieldParameterValue(String paramName) {
+ checkFormStateWithInput(paramName);
+ List textFieldElements = getForm().getHtmlElementsByAttribute("input", "type", "hidden");
+ Iterator it = textFieldElements.iterator();
+ while(it.hasNext()) {
+ HtmlHiddenInput textInput = (HtmlHiddenInput) it.next();
+ if (paramName.equals(textInput.getNameAttribute())) {
+ return textInput.getValueAttribute();
+ }
+ }
+ throw new RuntimeException("getHiddenFieldParameterValue failed, hidden field with name [" + paramName + "] does not exist.");
+ }
+
+ /**
* Set a form text, password input element or textarea to the provided value.
*
* @param fieldName
Index: pom.xml
===================================================================
--- pom.xml (revision 535)
+++ pom.xml (working copy)
@@ -311,13 +311,11 @@
</url>
</site>
<repository>
- <id>jwebunit-m2-repo</id>
- <url>
- scpexe://shell.sourceforge.net/home/groups/j/jw/jwebunit/htdocs/m2-repo
- </url>
+ <id>maven2.dev.kiala.com</id>
+ <url>scp://dev.kiala.com/var/www/maven2.dev.kiala.com</url>
<name>
jWebUnit Maven 2 Repository
</name>
</repository>
</distributionManagement>
-</project>
\ No newline at end of file
+</project>
Index: jwebunit-core/src/main/java/net/sourceforge/jwebunit/IJWebUnitDialog.java
===================================================================
--- jwebunit-core/src/main/java/net/sourceforge/jwebunit/IJWebUnitDialog.java (revision 535)
+++ jwebunit-core/src/main/java/net/sourceforge/jwebunit/IJWebUnitDialog.java (working copy)
@@ -175,8 +175,25 @@
*
* @param paramName
* name of the input element.
+ * @deprecated
*/
String getFormParameterValue(String paramName);
+
+ /**
+ * Return the current value of a text input element with name <code>paramName</code>.
+ *
+ * @param paramName
+ * name of the input element.
+ */
+ String getTextFieldParameterValue(String paramName);
+
+ /**
+ * Return the current value of a hidden input element with name <code>paramName</code>.
+ *
+ * @param paramName
+ * name of the input element.
+ */
+ String getHiddenFieldParameterValue(String paramName);
/**
* Fill a text, password or textarea field with the provided text.
Index: jwebunit-core/src/main/java/net/sourceforge/jwebunit/WebTester.java
===================================================================
--- jwebunit-core/src/main/java/net/sourceforge/jwebunit/WebTester.java (revision 535)
+++ jwebunit-core/src/main/java/net/sourceforge/jwebunit/WebTester.java (working copy)
@@ -718,6 +718,7 @@
*
* @param formElementName
* @param expectedValue
+ * @deprecated
*/
public void assertFormElementEquals(String formElementName,
String expectedValue) {
@@ -757,6 +758,34 @@
}
/**
+ * Assert that an input text element with name <code>formElementName</code> has
+ * the <code>expectedValue</code> value.
+ *
+ * @param formElementName
+ * the value of the name attribute of the element
+ * @param expectedValue
+ * the expected value of the given input element
+ */
+ public void assertTextFieldEquals(String formElementName, String expectedValue) {
+ assertFormElementPresent(formElementName);
+ Assert.assertEquals(expectedValue, getDialog().getTextFieldParameterValue(formElementName));
+ }
+
+ /**
+ * Assert that an input hidden element with name <code>formElementName</code> has
+ * the <code>expectedValue</code> value.
+ *
+ * @param formElementName
+ * the value of the name attribute of the element
+ * @param expectedValue
+ * the expected value of the given input element
+ */
+ public void assertHiddenFieldEquals(String formElementName, String expectedValue) {
+ assertFormElementPresent(formElementName);
+ Assert.assertEquals(expectedValue, getDialog().getHiddenFieldParameterValue(formElementName));
+ }
+
+ /**
* Assert that a specific checkbox is selected.
*
* @param checkBoxName
@@ -2147,7 +2176,7 @@
returned[i]);
}
}
-
+
/**
* Set the value of a form input element.
*
Index: jwebunit-core/src/main/java/net/sourceforge/jwebunit/WebTestCase.java
===================================================================
--- jwebunit-core/src/main/java/net/sourceforge/jwebunit/WebTestCase.java (revision 535)
+++ jwebunit-core/src/main/java/net/sourceforge/jwebunit/WebTestCase.java (working copy)
@@ -277,6 +277,14 @@
public void assertFormElementEmpty(String formElementName) {
getTester().assertFormElementEmpty(formElementName);
}
+
+ public void assertTextFieldEquals(String formElementName, String expectedValue) {
+ getTester().assertTextFieldEquals(formElementName, expectedValue);
+ }
+
+ public void assertHiddenFieldEquals(String formElementName, String expectedValue) {
+ getTester().assertHiddenFieldEquals(formElementName, expectedValue);
+ }
public void assertCheckboxSelected(String checkBoxName) {
getTester().assertCheckboxSelected(checkBoxName);
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Jwebunit-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jwebunit-development