Revision: 521
Author:   henryju
Date:     2006-07-03 02:54:35 -0700 (Mon, 03 Jul 2006)
ViewCVS:  http://svn.sourceforge.net/jwebunit/?rev=521&view=rev

Log Message:
-----------
Allow selection of forms with same name (by index).

Modified Paths:
--------------
    
branches/1.x/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/FormSubmissionTest.java
    
branches/1.x/jwebunit-commons-tests/src/main/resources/testcases/FormSubmissionTest/MultiFormPage.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/FormSubmissionTest.java
===================================================================
--- 
branches/1.x/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/FormSubmissionTest.java
    2006-06-28 15:45:29 UTC (rev 520)
+++ 
branches/1.x/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/FormSubmissionTest.java
    2006-07-03 09:54:35 UTC (rev 521)
@@ -155,6 +155,16 @@
         setWorkingForm("form5");
     }
 
+    public void testSetWorkingFormWithSameName() {
+        beginAt("/MultiFormPage.html");
+        setWorkingForm("myForm", 0);
+        assertSubmitButtonPresent("myInput1");
+        assertSubmitButtonNotPresent("myInput2");
+        setWorkingForm("myForm", 1);
+        assertSubmitButtonNotPresent("myInput1");
+        assertSubmitButtonPresent("myInput2");
+    }
+
     public void testInvalidButton() {
         beginAt("/InvalidActionForm.html");
         try {

Modified: 
branches/1.x/jwebunit-commons-tests/src/main/resources/testcases/FormSubmissionTest/MultiFormPage.html
===================================================================
--- 
branches/1.x/jwebunit-commons-tests/src/main/resources/testcases/FormSubmissionTest/MultiFormPage.html
      2006-06-28 15:45:29 UTC (rev 520)
+++ 
branches/1.x/jwebunit-commons-tests/src/main/resources/testcases/FormSubmissionTest/MultiFormPage.html
      2006-07-03 09:54:35 UTC (rev 521)
@@ -27,12 +27,22 @@
                        <input type="hidden" name="myReferer" 
value="FormSubmissionTest/MultiFormPage.html">
                </form>
                
-               <form id="form5"/><form id="form6">
+               <form id="form5"/>
+               
+               <form id="form6">
                        <select name="select1">
                        <option value="1">one</option>
                        <option value="2">two</option>
                        <option value="3">three</option>
                        </select>
                </form>
+
+               <form name="myForm">
+                       <input type="submit" name="myInput1">
+               </form>
+
+               <form name="myForm">
+                       <input type="submit" name="myInput2">
+               </form>
        </body>
 </html>

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-06-28 15:45:29 UTC (rev 520)
+++ 
branches/1.x/jwebunit-core/src/main/java/net/sourceforge/jwebunit/IJWebUnitDialog.java
      2006-07-03 09:54:35 UTC (rev 521)
@@ -143,8 +143,11 @@
      * 
      * @param nameOrId
      *            name or id of the form to be worked with.
+     * @param index
+     *            The 0-based index, when more than one form with the same name
+     *            is expected.
      */
-    void setWorkingForm(String nameOrId);
+    void setWorkingForm(String nameOrId, int index);
 
     /**
      * Return true if the current page contains a form.

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-06-28 15:45:29 UTC (rev 520)
+++ 
branches/1.x/jwebunit-core/src/main/java/net/sourceforge/jwebunit/WebTestCase.java
  2006-07-03 09:54:35 UTC (rev 521)
@@ -592,6 +592,10 @@
         getTester().setWorkingForm(nameOrId);
     }
 
+    public void setWorkingForm(String nameOrId, int index) {
+        getTester().setWorkingForm(nameOrId, index);
+    }
+
     public void setTextField(String textFieldName, String value) {
         getTester().setTextField(textFieldName, value);
     }

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-06-28 15:45:29 UTC (rev 520)
+++ 
branches/1.x/jwebunit-core/src/main/java/net/sourceforge/jwebunit/WebTester.java
    2006-07-03 09:54:35 UTC (rev 521)
@@ -1589,10 +1589,28 @@
      *            name or id of the form to work with.
      */
     public void setWorkingForm(String nameOrId) {
-        getDialog().setWorkingForm(nameOrId);
+        getDialog().setWorkingForm(nameOrId, 0);
     }
 
     /**
+     * Begin interaction with a specified form. If form interaction methods are
+     * called without explicitly calling this method first, jWebUnit will
+     * attempt to determine itself which form is being manipulated.
+     * 
+     * It is not necessary to call this method if their is only one form on the
+     * current page.
+     * 
+     * @param nameOrId
+     *            name or id of the form to work with.
+     * @param index
+     *            The 0-based index, when more than one form with the same name
+     *            is expected.
+     */
+    public void setWorkingForm(String nameOrId, int index) {
+        getDialog().setWorkingForm(nameOrId, index);
+    }
+
+    /**
      * Set the value of a text or password input field.
      * 
      * @param inputName

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-06-28 15:45:29 UTC (rev 520)
+++ 
branches/1.x/jwebunit-htmlunit-plugin/src/main/java/net/sourceforge/jwebunit/htmlunit/HtmlUnitDialog.java
   2006-07-03 09:54:35 UTC (rev 521)
@@ -14,6 +14,7 @@
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Iterator;
 import java.util.List;
 
 import org.apache.regexp.RE;
@@ -273,8 +274,8 @@
      * @param nameOrId
      *            name or id of the form to be worked with.
      */
-    public void setWorkingForm(String nameOrId) {
-        setWorkingForm(getForm(nameOrId));
+    public void setWorkingForm(String nameOrId, int index) {
+        setWorkingForm(getForm(nameOrId, index));
     }
 
     /**
@@ -324,7 +325,7 @@
         } catch (ElementNotFoundException e) {
 
         }
-        throw new RuntimeException("getFormParameterValue a \xE9chou\xE9");
+        throw new RuntimeException("getFormParameterValue a �chou�");
     }
 
     /**
@@ -562,6 +563,20 @@
         }
         return null;
     }
+    
+    private HtmlForm getForm(String nameOrID, int index) {
+        HtmlForm form = null;
+        Iterator iter = getCurrentPage().getForms().iterator();
+        for (int pos = 0; pos <= index && iter.hasNext();) {
+            HtmlForm curr = (HtmlForm) iter.next();
+            if (nameOrID.equals(curr.getIdAttribute())
+                    || nameOrID.equals(curr.getNameAttribute())) {
+                pos++;
+                form = curr;
+            }
+        }
+        return form;
+    }
 
     private HtmlForm getFormWithButton(String buttonName) {
         if (hasForm()) {

Modified: branches/1.x/src/changes/changes.xml
===================================================================
--- branches/1.x/src/changes/changes.xml        2006-06-28 15:45:29 UTC (rev 
520)
+++ branches/1.x/src/changes/changes.xml        2006-07-03 09:54:35 UTC (rev 
521)
@@ -5,7 +5,12 @@
                <author email="dashorst at users.sourceforge.net">Martijn 
Dashorst</author>
        </properties>
        <body>
-               <release version="1.3" date="UNKNOWN" description="Last 1.x 
before great changes.">
+               <release version="1.3" date="not yet released">
+                       <action type="add" dev="Julien Henry" due-to="Jeffrey 
W. Badorek" issue="1515297">
+                               Allow selection of forms with same name (with 
index). Add setWorkingForm(String nameOrId, int index) to the API.
+                       </action>
+                </release>
+               <release version="1.3-RC1" date="june 27, 2006" 
description="After all these great changes, we need a RC.">
                        <action type="add" dev="Julien Henry" due-to="Buhi 
Mume" >
                                Added ability to navigate to windows / assert 
presence by window id.
                        </action>


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

Reply via email to