Yes, it's a good idea... until we found a better way to locate element (I think about a system of locator, like in Selenium). Just don't forget to document in Javadoc what is the first attribut you check (I think it should be id).

As you are doing important changes to the API, I will wait until 1.3 final is release before applying your patchs (perhaps this evening).

++

Julien

----- Message d'origine ----
De : Fred <[EMAIL PROTECTED]>
À : Julien HENRY <[EMAIL PROTECTED]>; [email protected]
Envoyé le : Jeudi, 27 Juillet 2006, 3h13mn 42s
Objet : Re: assertTextFieldMatch and assertHiddenFieldMatch


Hi again :o)

Er... I'm thinking about something else.

Probably it could be a good idea to extend the scope of
assertTextFieldPresent(String name) by providing "String nameOrId" as
parameter ? (which will look up a textfield by the value of the name or id
attribute).

This will give:
assertTextFieldPresent(String nameOrId) {
   assertTrue(getDialog().hasTextField(nameOrId));
}

assertTextFieldEquals(String nameOrId, String value) {    
   assertTextFieldPresent(nameOrId);
   assertEquals(value, getDialog().getTextFieldValue(nameOrId));
}

(And... same for the rest.)

Does this make sense ?

Cheers,

Fred.

On Thursday 27 July 2006 14:26, Julien HENRY wrote:
> Hi,
>
> assertTextFieldMatch and assertHiddenFieldMatch are a good idea. The should
> lead to deprecate assertFormElementMatch (you can already deprecate it). We
> already have assertSelectedOptionMatches, and if someone need such a method
> for RadioBoxes, it's very easy to add.
>
> Therefore, I think there is a problem (not only in your patch, but in other
> methods too). For example, in assertTextFieldMatch, you are using
> assertFormElementPresent(). To keep logic and to enforce stability, you
> should write the following methods :
>
> assertTextFieldPresent(String name) {
>   assertTrue(getDialog().hasTextField(name));
> }
>
> assertHiddenFieldPresent(String name)  {  //instead of
> assertHiddenFieldPresent(String name, String value)
> assertTrue(getDialog().hasHiddenField(name));
> }
>
> assertHiddenFieldEquals(String name, String value) {
>    assertHiddenFieldPresent(name);
>    assertEquals(value, getDialog().getHiddenFieldValue(name));
> }
>
> After that, we could deprecate hasFormParameterNamed, which is totally no
> user-friendly.
>
> What do you think about that ?
>
> ++
>
> Julien
>
>
> ----- Message d'origine ----
> De : Fred <[EMAIL PROTECTED]>
> À : Julien HENRY <[EMAIL PROTECTED]>;
> [email protected] Envoyé le : Jeudi, 27 Juillet
> 2006, 12h33mn 23s
> Objet : assertTextFieldMatch and assertHiddenFieldMatch
>
>
> 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/FormAss
>ertionsTest.java
> =================================================================== ---
> jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/FormAss
>ertionsTest.java    (revision 536) +++
> jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/FormAss
>ertionsTest.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);
>      }

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

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

Reply via email to