Hi,
I found it nice to add assertTextFieldMatch and assertHiddenFieldMatch.
Maybe, the method assertFormElementMatch could be deprecated as well... But
maybe this method is still usefull for radio buttons and select boxes: reason
why I didn't deprecate the method.
You will find enclosed a patch for the implementation of the two mentioned
methods.
As usual... any remarks and suggestions are welcome :o)
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 536)
+++ jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/FormAssertionsTest.java (working copy)
@@ -70,6 +70,19 @@
assertPass("assertTextFieldEquals", new Object[]{"passwordelement", "password"});
}
+ public void testAssertFormElementMatches() throws Throwable {
+ beginAt("/testPage.html");
+ assertPass("assertTextFieldMatch", new Object[]{"passwordelement", "p[aA]s*word"});
+ assertFail("assertTextFieldMatch", new Object[]{"passwordelement", "pa*s*w0rd"});
+ assertFail("assertTextFieldMatch", new Object[]{"noSuchElement", "p[aA]s*word"});
+ assertPass("assertHiddenFieldMatch", new Object[]{"hiddenelement", "hid*en[vV]"});
+ assertFail("assertHiddenFieldMatch", new Object[]{"noSuchElement", "hid*en[vV]"});
+ assertFail("assertHiddenFieldMatch", new Object[]{"hiddenelement", "[Hh]iden"});
+ assertPass("assertTextFieldMatch", new Object[]{"textarea", "some.*here"});
+ assertFail("assertTextFieldMatch", new Object[]{"noSuchElement", "some.*here"});
+ assertFail("assertTextFieldMatch", new Object[]{"textarea", "som[eh]ere"});
+ }
+
public void testCheckboxSelected() throws Throwable {
beginAt("/testPage.html");
assertPassFail("assertCheckboxSelected", "checkboxselected", "checkboxnotselected");
Index: jwebunit-core/src/main/java/net/sourceforge/jwebunit/WebTester.java
===================================================================
--- jwebunit-core/src/main/java/net/sourceforge/jwebunit/WebTester.java (revision 536)
+++ jwebunit-core/src/main/java/net/sourceforge/jwebunit/WebTester.java (working copy)
@@ -206,12 +206,7 @@
* expected title regexp
*/
public void assertTitleMatch(String regexp) {
- RE re = null;
- try {
- re = new RE(regexp, RE.MATCH_SINGLELINE);
- } catch (RESyntaxException e) {
- Assert.fail(e.toString());
- }
+ RE re = getRE(regexp);
Assert.assertTrue("Unable to match [" + regexp + "] in title", re
.match(getDialog().getPageTitle()));
}
@@ -735,12 +730,7 @@
*/
public void assertFormElementMatch(String formElementName, String regexp) {
assertFormElementPresent(formElementName);
- RE re = null;
- try {
- re = new RE(regexp, RE.MATCH_SINGLELINE);
- } catch (RESyntaxException e) {
- Assert.fail(e.toString());
- }
+ RE re = getRE(regexp);
Assert.assertTrue("Unable to match [" + regexp + "] in form element \""
+ formElementName + "\"", re.match(getDialog()
.getFormParameterValue(formElementName)));
@@ -770,8 +760,23 @@
assertFormElementPresent(formElementName);
Assert.assertEquals(expectedValue, getDialog().getTextFieldValue(formElementName));
}
-
+
/**
+ * Assert that the value of an input text element with name <code>formElementName</code>
+ * matches the regular expression <code>regexp</code>.
+ *
+ * @param formElementName
+ * the value of the name attribute of the element
+ * @param regexp
+ * the regular expression representation of the value attribute
+ */
+ public void assertTextFieldMatch(String formElementName, String regexp) {
+ assertFormElementPresent(formElementName);
+ RE re = getRE(regexp);
+ Assert.assertTrue(re.match(getDialog().getTextFieldValue(formElementName)));
+ }
+
+ /**
* Assert that an input hidden element with name <code>formElementName</code> has
* the <code>expectedValue</code> value.
*
@@ -784,8 +789,23 @@
assertFormElementPresent(formElementName);
Assert.assertEquals(expectedValue, getDialog().getHiddenFieldValue(formElementName));
}
-
+
/**
+ * Assert that the value of an input hidden element with name <code>formElementName</code>
+ * matches the regular expression <code>regexp</code>.
+ *
+ * @param formElementName
+ * the value of the name attribute of the element
+ * @param regexp
+ * the regular expression representation of the value attribute
+ */
+ public void assertHiddenFieldMatch(String formElementName, String regexp) {
+ assertFormElementPresent(formElementName);
+ RE re = getRE(regexp);
+ Assert.assertTrue(re.match(getDialog().getHiddenFieldValue(formElementName)));
+ }
+
+ /**
* Assert that a specific checkbox is selected.
*
* @param checkBoxName
@@ -1581,12 +1601,7 @@
public void assertCookieValueMatch(String cookieName, String regexp) {
assertCookiePresent(cookieName);
- RE re = null;
- try {
- re = new RE(regexp, RE.MATCH_SINGLELINE);
- } catch (RESyntaxException e) {
- Assert.fail(e.toString());
- }
+ RE re = getRE(regexp);
Assert.assertTrue("Unable to match [" + regexp + "] in cookie \""
+ cookieName + "\"", re.match(getDialog().getCookieValue(
cookieName)));
Index: jwebunit-core/src/main/java/net/sourceforge/jwebunit/WebTestCase.java
===================================================================
--- jwebunit-core/src/main/java/net/sourceforge/jwebunit/WebTestCase.java (revision 536)
+++ jwebunit-core/src/main/java/net/sourceforge/jwebunit/WebTestCase.java (working copy)
@@ -280,15 +280,23 @@
public void assertFormElementEmpty(String formElementName) {
getTester().assertFormElementEmpty(formElementName);
}
-
+
public void assertTextFieldEquals(String formElementName, String expectedValue) {
getTester().assertTextFieldEquals(formElementName, expectedValue);
}
-
+
+ public void assertTextFieldMatch(String formElementName, String regexp) {
+ getTester().assertTextFieldMatch(formElementName, regexp);
+ }
+
public void assertHiddenFieldPresent(String formElementName, String expectedValue) {
getTester().assertHiddenFieldPresent(formElementName, expectedValue);
}
+ public void assertHiddenFieldMatch(String formElementName, String regexp) {
+ getTester().assertHiddenFieldMatch(formElementName, regexp);
+ }
+
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