Revision: 536
Author:   henryju
Date:     2006-07-27 00:36:46 -0700 (Thu, 27 Jul 2006)
ViewCVS:  http://svn.sourceforge.net/jwebunit/?rev=536&view=rev

Log Message:
-----------
Add assertTextFieldEquals and assertHiddenFieldPresent (patch from Fred)
assertFormParameterValue is now deprecated
Update tests and add some new.
Update changes.xml

Modified Paths:
--------------
    
branches/1.x/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/CharsetTest.java
    
branches/1.x/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/FormAssertionsTest.java
    
branches/1.x/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/JavaScriptEventsTest.java
    
branches/1.x/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/WebAssertionsTest.java
    
branches/1.x/jwebunit-commons-tests/src/main/resources/testcases/FormAssertionsTest/testPage.html
    
branches/1.x/jwebunit-core/src/main/java/net/sourceforge/jwebunit/IJWebUnitDialog.java
    
branches/1.x/jwebunit-core/src/main/java/net/sourceforge/jwebunit/WebTestCase.java
    
branches/1.x/jwebunit-core/src/main/java/net/sourceforge/jwebunit/WebTester.java
    
branches/1.x/jwebunit-htmlunit-plugin/src/main/java/net/sourceforge/jwebunit/htmlunit/HtmlUnitDialog.java
    branches/1.x/src/changes/changes.xml
Modified: 
branches/1.x/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/CharsetTest.java
===================================================================
--- 
branches/1.x/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/CharsetTest.java
   2006-07-26 09:04:57 UTC (rev 535)
+++ 
branches/1.x/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/CharsetTest.java
   2006-07-27 07:36:46 UTC (rev 536)
@@ -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");
-        }
-}
\ No newline at end of file
+    public void testPound() {
+        assertTextFieldEquals("gbp", "\u00A3");
+    }
+}

Modified: 
branches/1.x/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/FormAssertionsTest.java
===================================================================
--- 
branches/1.x/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/FormAssertionsTest.java
    2006-07-26 09:04:57 UTC (rev 535)
+++ 
branches/1.x/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/FormAssertionsTest.java
    2006-07-27 07:36:46 UTC (rev 536)
@@ -57,10 +57,17 @@
 
     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("assertHiddenFieldPresent", new Object[]{"hiddenelement", 
"hiddenvalue"});
+        assertFail("assertTextFieldEquals", new Object[]{"testInputElement", 
"noSuchValue"});
+        assertFail("assertTextFieldEquals", new Object[]{"noSuchElement", 
"testValue"});
+        assertFail("assertHiddenFieldPresent", new Object[]{"noSuchElement", 
"testValue"});
+        assertFail("assertHiddenFieldPresent", new Object[]{"hiddenelement", 
"notThisValue"});
+        assertFail("assertTextFieldEquals", new Object[]{"passwordelement", 
"noSuchValue"});
+        assertPass("assertTextFieldEquals", new Object[]{"passwordelement", 
"password"});
     }
 
     public void testCheckboxSelected() throws Throwable {

Modified: 
branches/1.x/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/JavaScriptEventsTest.java
===================================================================
--- 
branches/1.x/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/JavaScriptEventsTest.java
  2006-07-26 09:04:57 UTC (rev 535)
+++ 
branches/1.x/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/JavaScriptEventsTest.java
  2006-07-27 07:36:46 UTC (rev 536)
@@ -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() {

Modified: 
branches/1.x/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/WebAssertionsTest.java
===================================================================
--- 
branches/1.x/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/WebAssertionsTest.java
     2006-07-26 09:04:57 UTC (rev 535)
+++ 
branches/1.x/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/WebAssertionsTest.java
     2006-07-27 07:36:46 UTC (rev 536)
@@ -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 testAssertHiddenFieldPresent() throws Throwable {
+        assertHiddenFieldPresent("hidden", "h");
+        assertFail("assertHiddenFieldPresent", new Object[] {"hidden", 
"AnotherValue"});
+    }
 
     public void testAssertFormElementMatch() throws Throwable {
         assertFormElementMatch("testInputElement", "test[Vv]alue");
@@ -169,4 +182,4 @@
     }
 
 
-}
\ No newline at end of file
+}

Modified: 
branches/1.x/jwebunit-commons-tests/src/main/resources/testcases/FormAssertionsTest/testPage.html
===================================================================
--- 
branches/1.x/jwebunit-commons-tests/src/main/resources/testcases/FormAssertionsTest/testPage.html
   2006-07-26 09:04:57 UTC (rev 535)
+++ 
branches/1.x/jwebunit-commons-tests/src/main/resources/testcases/FormAssertionsTest/testPage.html
   2006-07-27 07:36:46 UTC (rev 536)
@@ -36,6 +36,9 @@
                        <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"/>
+               <input type="password" name="passwordelement" 
value="password"></form>
                </td>
        </tr>
 </table>

Modified: 
branches/1.x/jwebunit-core/src/main/java/net/sourceforge/jwebunit/IJWebUnitDialog.java
===================================================================
--- 
branches/1.x/jwebunit-core/src/main/java/net/sourceforge/jwebunit/IJWebUnitDialog.java
      2006-07-26 09:04:57 UTC (rev 535)
+++ 
branches/1.x/jwebunit-core/src/main/java/net/sourceforge/jwebunit/IJWebUnitDialog.java
      2006-07-27 07:36:46 UTC (rev 536)
@@ -175,8 +175,26 @@
      * 
      * @param paramName
      *            name of the input element.
+     * @deprecated
      */
     String getFormParameterValue(String paramName);
+    
+    /**
+     * 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.
+     */
+    String getTextFieldValue(String paramName);
+    
+    /**
+     * Return the current value of a hidden input element with name 
<code>paramName</code>.
+     * 
+     * @param paramName
+     *            name of the hidden input element.
+     */
+    String getHiddenFieldValue(String paramName);
 
     /**
      * Fill a text, password or textarea field with the provided text.
@@ -647,4 +665,4 @@
      *            regexp to match.
      */
     boolean isMatchInElement(String elementID, String regexp);
-}
\ No newline at end of file
+}

Modified: 
branches/1.x/jwebunit-core/src/main/java/net/sourceforge/jwebunit/WebTestCase.java
===================================================================
--- 
branches/1.x/jwebunit-core/src/main/java/net/sourceforge/jwebunit/WebTestCase.java
  2006-07-26 09:04:57 UTC (rev 535)
+++ 
branches/1.x/jwebunit-core/src/main/java/net/sourceforge/jwebunit/WebTestCase.java
  2006-07-27 07:36:46 UTC (rev 536)
@@ -265,6 +265,9 @@
         getTester().assertFormNotPresent(formName);
     }
 
+    /**
+     * @deprecated 
+     */
     public void assertFormElementEquals(String formElementName,
             String expectedValue) {
         getTester().assertFormElementEquals(formElementName, expectedValue);
@@ -277,6 +280,14 @@
     public void assertFormElementEmpty(String formElementName) {
         getTester().assertFormElementEmpty(formElementName);
     }
+    
+    public void assertTextFieldEquals(String formElementName, String 
expectedValue) {
+        getTester().assertTextFieldEquals(formElementName, expectedValue);
+    }
+    
+    public void assertHiddenFieldPresent(String formElementName, String 
expectedValue) {
+        getTester().assertHiddenFieldPresent(formElementName, expectedValue);
+    }
 
     public void assertCheckboxSelected(String checkBoxName) {
         getTester().assertCheckboxSelected(checkBoxName);
@@ -805,4 +816,4 @@
         getTester().setFormElement(formElementName, value);
     }
 
-}
\ No newline at end of file
+}

Modified: 
branches/1.x/jwebunit-core/src/main/java/net/sourceforge/jwebunit/WebTester.java
===================================================================
--- 
branches/1.x/jwebunit-core/src/main/java/net/sourceforge/jwebunit/WebTester.java
    2006-07-26 09:04:57 UTC (rev 535)
+++ 
branches/1.x/jwebunit-core/src/main/java/net/sourceforge/jwebunit/WebTester.java
    2006-07-27 07:36:46 UTC (rev 536)
@@ -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().getTextFieldValue(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 assertHiddenFieldPresent(String formElementName, String 
expectedValue) {
+        assertFormElementPresent(formElementName);
+        Assert.assertEquals(expectedValue, 
getDialog().getHiddenFieldValue(formElementName));
+    }
+        
+    /**
      * Assert that a specific checkbox is selected.
      * 
      * @param checkBoxName
@@ -2147,7 +2176,7 @@
                     returned[i]);
         }
     }
-    
+
     /**
      * Set the value of a form input element.
      * 
@@ -2162,4 +2191,4 @@
         getDialog().setTextField(formElementName, value);
     }
 
-}
\ No newline at end of file
+}

Modified: 
branches/1.x/jwebunit-htmlunit-plugin/src/main/java/net/sourceforge/jwebunit/htmlunit/HtmlUnitDialog.java
===================================================================
--- 
branches/1.x/jwebunit-htmlunit-plugin/src/main/java/net/sourceforge/jwebunit/htmlunit/HtmlUnitDialog.java
   2006-07-26 09:04:57 UTC (rev 535)
+++ 
branches/1.x/jwebunit-htmlunit-plugin/src/main/java/net/sourceforge/jwebunit/htmlunit/HtmlUnitDialog.java
   2006-07-27 07:36:46 UTC (rev 536)
@@ -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;
@@ -308,6 +309,7 @@
      * 
      * @param paramName
      *            name of the input element.
+     * @deprecated
      */
     public String getFormParameterValue(String paramName) {
         checkFormStateWithInput(paramName);
@@ -328,8 +330,58 @@
         }
         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 getTextFieldValue(String paramName) {
+        checkFormStateWithInput(paramName);
+        List textFieldElements = getForm().getHtmlElementsByAttribute("input", 
"type", "text");
+        textFieldElements.addAll(getForm().getHtmlElementsByAttribute("input", 
"type", "password"));
+        Iterator it = textFieldElements.iterator();
+        while(it.hasNext()) {
+            HtmlInput input = (HtmlInput) it.next();
+            if (paramName.equals(input.getNameAttribute())) {
+                return input.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 getHiddenFieldValue(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

Modified: branches/1.x/src/changes/changes.xml
===================================================================
--- branches/1.x/src/changes/changes.xml        2006-07-26 09:04:57 UTC (rev 
535)
+++ branches/1.x/src/changes/changes.xml        2006-07-27 07:36:46 UTC (rev 
536)
@@ -6,6 +6,16 @@
        </properties>
        <body>
         <release version="1.3-SNAPSHOT" date="UNKNOW">
+            <action type="remove" dev="Julien Henry" due-to="Fred Burlet">
+                assertFormParameterValue is now deprecated. Please use more 
specific method, like
+                assertTextFieldEquals, assertSelectedValueEqual, ...
+            </action>
+            <action type="add" dev="Julien Henry" due-to="Fred Burlet">
+                Add assertHiddenFieldPresent method to check presence of an 
hidden field with given value.
+            </action>
+            <action type="add" dev="Julien Henry" due-to="Fred Burlet">
+                Add assertTextFieldEquals method to check content of a text 
field (text input, password input, textarea).
+            </action>
             <action type="fix" dev="Julien Henry" due-to="Fred Burlet">
                 setTextField is now working with TextArea.
             </action>


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


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