Revision: 660
          http://svn.sourceforge.net/jwebunit/?rev=660&view=rev
Author:   henryju
Date:     2007-01-21 11:43:49 -0800 (Sun, 21 Jan 2007)

Log Message:
-----------
Add a new test case for radio buttons related function. Fix 
assertRadioOption[Not]Selected. Thanks again to Tom Block.

Modified Paths:
--------------
    
branches/1.x/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/FormSubmissionTest.java
    
branches/1.x/jwebunit-core/src/main/java/net/sourceforge/jwebunit/api/IJWebUnitDialog.java
    
branches/1.x/jwebunit-core/src/main/java/net/sourceforge/jwebunit/junit/WebTester.java
    
branches/1.x/jwebunit-htmlunit-plugin/src/main/java/net/sourceforge/jwebunit/htmlunit/HtmlUnitDialog.java

Added Paths:
-----------
    
branches/1.x/jwebunit-commons-tests/src/main/resources/testcases/FormSubmissionTest/RadioForm.html

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
    2007-01-21 18:51:47 UTC (rev 659)
+++ 
branches/1.x/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/FormSubmissionTest.java
    2007-01-21 19:43:49 UTC (rev 660)
@@ -137,6 +137,23 @@
         submit();
         assertTextPresent("color=blue ");
     }
+    
+    public void testRadioSelection() {
+       beginAt("/RadioForm.html");
+       clickRadioOption("radio", "1");
+       assertRadioOptionSelected("radio", "1");
+       submit();
+       assertTextPresent("radio=1 ");
+       clickLink("return");
+       System.out.println(getPageSource());
+       clickRadioOption("radio", "2");
+       clickRadioOption("radio", "3");
+       assertRadioOptionNotSelected("radio", "1");
+       assertRadioOptionNotSelected("radio", "2");
+       assertRadioOptionSelected("radio", "3");
+       submit();
+       assertTextPresent("radio=3 ");
+    }
 
     public void testSingleFormSingleUnnamedButtonSubmission() {
         beginAt("/SingleUnnamedButtonForm.html");

Added: 
branches/1.x/jwebunit-commons-tests/src/main/resources/testcases/FormSubmissionTest/RadioForm.html
===================================================================
--- 
branches/1.x/jwebunit-commons-tests/src/main/resources/testcases/FormSubmissionTest/RadioForm.html
                          (rev 0)
+++ 
branches/1.x/jwebunit-commons-tests/src/main/resources/testcases/FormSubmissionTest/RadioForm.html
  2007-01-21 19:43:49 UTC (rev 660)
@@ -0,0 +1,12 @@
+<html>
+<head></head>
+<body>
+       <form method="GET" action="../params.jsp">
+               <input type="radio" name="radio" value="1">
+               <input type="radio" name="radio" value="2">
+               <input type="radio" name="radio" value="3">
+               <input type="submit" name="button">
+               <input type="hidden" name="myReferer" 
value="FormSubmissionTest/RadioForm.html">
+       </form>
+</body>
+</html>
\ No newline at end of file

Modified: 
branches/1.x/jwebunit-core/src/main/java/net/sourceforge/jwebunit/api/IJWebUnitDialog.java
===================================================================
--- 
branches/1.x/jwebunit-core/src/main/java/net/sourceforge/jwebunit/api/IJWebUnitDialog.java
  2007-01-21 18:51:47 UTC (rev 659)
+++ 
branches/1.x/jwebunit-core/src/main/java/net/sourceforge/jwebunit/api/IJWebUnitDialog.java
  2007-01-21 19:43:49 UTC (rev 660)
@@ -354,6 +354,13 @@
      * @param radioOptionValue value of the option to check for.
      */
     boolean hasRadioOption(String radioGroup, String radioOptionValue);
+    
+    /**
+     * Return the currently selected radio button.
+     * @param radioGroup name of the radio group.
+     * @return value of the selected radio.
+     */
+    String getSelectedRadio(String radioGroup);
 
     /**
      * Checks if the current form contains a submit button.

Modified: 
branches/1.x/jwebunit-core/src/main/java/net/sourceforge/jwebunit/junit/WebTester.java
===================================================================
--- 
branches/1.x/jwebunit-core/src/main/java/net/sourceforge/jwebunit/junit/WebTester.java
      2007-01-21 18:51:47 UTC (rev 659)
+++ 
branches/1.x/jwebunit-core/src/main/java/net/sourceforge/jwebunit/junit/WebTester.java
      2007-01-21 19:43:49 UTC (rev 660)
@@ -893,9 +893,7 @@
     public void assertRadioOptionSelected(String name, String radioOption) {
         assertRadioOptionPresent(name, radioOption);
         Assert.assertEquals(radioOption, getTestingEngine()
-                .getElementAttributByXPath(
-                        "//[EMAIL PROTECTED]'radio' and @name='" + name + "']",
-                        "value"));
+                       .getSelectedRadio(name));
     }
 
     /**
@@ -908,9 +906,7 @@
         assertRadioOptionPresent(name, radioOption);
         Assert.assertFalse("Radio option [" + radioOption + "] is selected.",
                 radioOption.equals(getTestingEngine()
-                        .getElementAttributByXPath(
-                                "//[EMAIL PROTECTED]'radio' and @name='" + name
-                                        + "']", "value")));
+                        .getSelectedRadio(name)));
     }
 
     /**

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
   2007-01-21 18:51:47 UTC (rev 659)
+++ 
branches/1.x/jwebunit-htmlunit-plugin/src/main/java/net/sourceforge/jwebunit/htmlunit/HtmlUnitDialog.java
   2007-01-21 19:43:49 UTC (rev 660)
@@ -1738,6 +1738,17 @@
         }
         return false;
     }
+    
+    public String getSelectedRadio(String radioGroup) {
+        List radios = getForm().getRadioButtonsByName(radioGroup);
+        for (Iterator i = radios.iterator(); i.hasNext();) {
+               HtmlRadioButtonInput radio = (HtmlRadioButtonInput) i.next();
+               if (radio.isChecked()) {
+                       return radio.getValueAttribute();
+               }
+        }
+        throw new RuntimeException("Unexpected Exception: no radio button was 
selected in radio group ["+radioGroup+"].");
+    }
 
     /**
      * Return true if a select box contains the indicated option.


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