Revision: 731
          http://jwebunit.svn.sourceforge.net/jwebunit/?rev=731&view=rev
Author:   henryju
Date:     2008-07-08 06:47:10 -0700 (Tue, 08 Jul 2008)

Log Message:
-----------
[2007985,2009776] Some improvements to Selenium plugin. Patch from Josh Lane.

Modified Paths:
--------------
    
trunk/jwebunit-selenium-plugin/src/main/java/net/sourceforge/jwebunit/selenium/SeleniumTestingEngineImpl.java
    trunk/pom.xml
    trunk/src/changes/changes.xml

Modified: 
trunk/jwebunit-selenium-plugin/src/main/java/net/sourceforge/jwebunit/selenium/SeleniumTestingEngineImpl.java
===================================================================
--- 
trunk/jwebunit-selenium-plugin/src/main/java/net/sourceforge/jwebunit/selenium/SeleniumTestingEngineImpl.java
       2008-04-25 09:27:44 UTC (rev 730)
+++ 
trunk/jwebunit-selenium-plugin/src/main/java/net/sourceforge/jwebunit/selenium/SeleniumTestingEngineImpl.java
       2008-07-08 13:47:10 UTC (rev 731)
@@ -6,6 +6,7 @@
 
 
 import java.io.InputStream;
+import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.LinkedList;
 import java.util.List;
@@ -302,15 +303,21 @@
 
     public boolean hasSelectOptionValue(String selectName, String optionValue) 
{
         try {
-            getSelectOptionLabelForValue(selectName, optionValue);
-            return true;
+            return getSelectOptionLabelForValue(selectName, optionValue) != 
null;
         } catch (SeleniumException e) {
             return false;
         }
     }
 
     public boolean hasSelectOption(String selectName, int index, String 
optionLabel) {
-        return false;
+        boolean equals;
+        try {
+            equals = getSelectedOptions(selectName)[index].equals(optionLabel);
+        } catch (RuntimeException e) {
+            logger.error("", e);
+            equals = false;
+        }
+        return equals;
     }
 
     public boolean hasSelectOptionValue(String selectName, int index, String 
optionValue) {
@@ -388,13 +395,31 @@
 
 
     public boolean isMatchInElement(String elementID, String regexp) {
-        //TODO Implement isMatchInElement in SeleniumDialog
-        throw new UnsupportedOperationException("isMatchInElement");
+        boolean match;
+        try {
+            String locator = "id=" + elementID;
+            String elementText = selenium.getText(locator);
+            if (elementText == null || elementText.equals("")) elementText = 
selenium.getValue(locator);
+            match = (elementText != null ? elementText.matches(regexp) : 
false);
+        } catch (RuntimeException e) {
+            logger.error("", e);
+            match = false;
+        }
+        return match;
     }
 
     public boolean isTextInElement(String elementID, String text) {
-        // TODO Implement isTextInElement in SeleniumDialog
-        throw new UnsupportedOperationException("isTextInElement");
+        boolean contains;
+        try {
+            String locator = "id=" + elementID;
+            String elementText = selenium.getText(locator);
+            if (elementText == null || elementText.equals("")) elementText = 
selenium.getValue(locator);
+            contains = (elementText != null ? elementText.contains(text) : 
false);
+        } catch (RuntimeException e) {
+            logger.error("", e);
+            contains = false;
+        }
+        return contains;
     }
 
     public void refresh() {
@@ -408,11 +433,17 @@
     }
 
     public void selectOptions(String selectName, String[] optionsValue) {
-        for (int i=0; i<optionsValue.length; i++) {
-            selenium.addSelection("xpath=" + formSelector() + "//[EMAIL 
PROTECTED]'"+selectName+"']","value="+optionsValue[i]);
+        if (optionsValue.length == 1) {
+            selenium.select("xpath=" + formSelector() + "//[EMAIL PROTECTED]'" 
+ selectName + "']",
+                    optionsValue[0]);
+        } else {
+            for (int i = 0; i < optionsValue.length; i++) {
+                selenium.addSelection("xpath=" + formSelector() + "//[EMAIL 
PROTECTED]'" + selectName + "']",
+                        "value=" + optionsValue[i]);
+            }
         }
     }
-
+    
     public void selectOptions(String selectName, int index, String[] 
optionsValue) {
     }
 
@@ -569,12 +600,15 @@
         throw new UnsupportedOperationException("getInputStream");
     }
 
-    /* (non-Javadoc)
-     * @see net.sourceforge.jwebunit.api.ITestingEngine#getPageURL()
-     */
     public URL getPageURL() {
-        // TODO Auto-generated method stub
-        throw new UnsupportedOperationException("getPageURL");
+        URL url;
+        try {
+            url = new URL(selenium.getLocation());
+        } catch (MalformedURLException e) {
+            logger.error("", e);
+            url = null;
+        }
+        return url;
     }
 
     /* (non-Javadoc)

Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml       2008-04-25 09:27:44 UTC (rev 730)
+++ trunk/pom.xml       2008-07-08 13:47:10 UTC (rev 731)
@@ -137,6 +137,16 @@
             <timezone />
             <properties />
         </contributor>
+        <contributor>
+            <name>Josh Lane</name>
+            <email>lane.joshlane at gmail.com</email>
+            <url />
+            <organization />
+            <organizationUrl />
+            <roles />
+            <timezone />
+            <properties />
+        </contributor>
     </contributors>
     <licenses>
         <license>

Modified: trunk/src/changes/changes.xml
===================================================================
--- trunk/src/changes/changes.xml       2008-04-25 09:27:44 UTC (rev 730)
+++ trunk/src/changes/changes.xml       2008-07-08 13:47:10 UTC (rev 731)
@@ -8,6 +8,11 @@
     </properties>
     <body>
         <release version="2.0" date="UNKNOW">
+            <action type="fix" dev="joshlane" issue="2007985,2009776" 
due-to="Josh Lane">
+                selectOptionByValue failed with Selenium Plugin.
+                selectOption always failed, cannot find element.
+                Other improvements to Selenium plugin.
+            </action>
             <action type="update" dev="henryju" issue="1950248" due-to="Agnes 
Ro">
                 Update to HtmlUnit 2.1 and Java 1.5.
             </action>


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

-------------------------------------------------------------------------
Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
Studies have shown that voting for your favorite open source project,
along with a healthy diet, reduces your potential for chronic lameness
and boredom. Vote Now at http://www.sourceforge.net/community/cca08
_______________________________________________
JWebUnit-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jwebunit-development

Reply via email to