Revision: 694
          http://svn.sourceforge.net/jwebunit/?rev=694&view=rev
Author:   henryju
Date:     2007-04-15 11:13:50 -0700 (Sun, 15 Apr 2007)

Log Message:
-----------
Add Selenium plugin (not fully working).

Modified Paths:
--------------
    trunk/jwebunit-commons-tests/pom.xml
    trunk/jwebunit-commons-tests/src/main/resources/testcases/WEB-INF/web.xml
    
trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/junit/WebTester.java
    
trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/util/TestingEngineRegistry.java
    trunk/pom.xml

Added Paths:
-----------
    trunk/jwebunit-selenium-plugin/
    trunk/jwebunit-selenium-plugin/pom.xml
    trunk/jwebunit-selenium-plugin/src/
    trunk/jwebunit-selenium-plugin/src/main/
    trunk/jwebunit-selenium-plugin/src/main/java/
    trunk/jwebunit-selenium-plugin/src/main/java/net/
    trunk/jwebunit-selenium-plugin/src/main/java/net/sourceforge/
    trunk/jwebunit-selenium-plugin/src/main/java/net/sourceforge/jwebunit/
    
trunk/jwebunit-selenium-plugin/src/main/java/net/sourceforge/jwebunit/selenium/
    
trunk/jwebunit-selenium-plugin/src/main/java/net/sourceforge/jwebunit/selenium/SeleniumTestingEngineImpl.java
    trunk/jwebunit-selenium-plugin/src/site/
    trunk/jwebunit-selenium-plugin/src/site/site.xml
    trunk/jwebunit-selenium-plugin/src/site/xdoc/
    trunk/jwebunit-selenium-plugin/src/site/xdoc/index.xml
    trunk/jwebunit-selenium-plugin/src/test/
    trunk/jwebunit-selenium-plugin/src/test/java/
    trunk/jwebunit-selenium-plugin/src/test/java/net/
    trunk/jwebunit-selenium-plugin/src/test/java/net/sourceforge/
    trunk/jwebunit-selenium-plugin/src/test/java/net/sourceforge/jwebunit/
    
trunk/jwebunit-selenium-plugin/src/test/java/net/sourceforge/jwebunit/selenium/
    
trunk/jwebunit-selenium-plugin/src/test/java/net/sourceforge/jwebunit/selenium/JWebUnitTest.java

Modified: trunk/jwebunit-commons-tests/pom.xml
===================================================================
--- trunk/jwebunit-commons-tests/pom.xml        2007-04-14 17:42:35 UTC (rev 
693)
+++ trunk/jwebunit-commons-tests/pom.xml        2007-04-15 18:13:50 UTC (rev 
694)
@@ -31,6 +31,10 @@
             <groupId>commons-fileupload</groupId>
             <artifactId>commons-fileupload</artifactId>
         </dependency>
+        <dependency>
+            <groupId>commons-io</groupId>
+            <artifactId>commons-io</artifactId>
+        </dependency>
     </dependencies>
     <properties>
         <topDirectoryLocation>..</topDirectoryLocation>

Modified: 
trunk/jwebunit-commons-tests/src/main/resources/testcases/WEB-INF/web.xml
===================================================================
--- trunk/jwebunit-commons-tests/src/main/resources/testcases/WEB-INF/web.xml   
2007-04-14 17:42:35 UTC (rev 693)
+++ trunk/jwebunit-commons-tests/src/main/resources/testcases/WEB-INF/web.xml   
2007-04-15 18:13:50 UTC (rev 694)
@@ -29,7 +29,7 @@
     <url-pattern>/redirect.jsp</url-pattern>
 </servlet-mapping>
 
-<security-constraint>
+<!--security-constraint>
    <web-resource-collection>
      <web-resource-name>A Protected Page</web-resource-name>
      <url-pattern>/*</url-pattern>
@@ -45,6 +45,6 @@
   <login-config>
    <auth-method>DIGEST</auth-method>
    <realm-name>MyRealm</realm-name>
-  </login-config>
+  </login-config-->
 
 </web-app>
\ No newline at end of file

Modified: 
trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/junit/WebTester.java
===================================================================
--- 
trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/junit/WebTester.java 
    2007-04-14 17:42:35 UTC (rev 693)
+++ 
trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/junit/WebTester.java 
    2007-04-15 18:13:50 UTC (rev 694)
@@ -715,7 +715,7 @@
         assertFormPresent();
         try {
             Assert.assertTrue("Found form element with name ["
-                    + formElementName + "] when not expected.", !getDialog()
+                    + formElementName + "] when not expected.", 
!getTestingEngine()
                     .hasFormParameterNamed(formElementName));
         } catch (UnableToSetFormException e) {
             // assertFormControlNotPresent
@@ -823,7 +823,7 @@
     public void assertFormElementEquals(String formElementName,
             String expectedValue) {
         assertFormElementPresent(formElementName);
-        Assert.assertEquals(expectedValue, getDialog()
+        Assert.assertEquals(expectedValue, getTestingEngine()
                 .getElementAttributByXPath(
                         "//[EMAIL PROTECTED]'" + formElementName + "']", 
"value"));
     }
@@ -844,7 +844,7 @@
             Assert.fail(e.toString());
         }
         Assert.assertTrue("Unable to match [" + regexp + "] in form element \""
-                + formElementName + "\"", re.match(getDialog()
+                + formElementName + "\"", re.match(getTestingEngine()
                 .getElementAttributByXPath(
                         "//[EMAIL PROTECTED]'" + formElementName + "']", 
"value")));
     }
@@ -1150,7 +1150,7 @@
                 .getSelectedOptions(selectName).length);
         for (int i = 0; i < labels.length; i++)
             Assert.assertEquals(labels[i],
-                    getDialog()
+                    getTestingEngine()
                             .getSelectOptionLabelForValue(
                                     selectName,
                                     getTestingEngine().getSelectedOptions(
@@ -1222,7 +1222,7 @@
      */
     public void assertSubmitButtonPresent() {
         assertFormPresent();
-        Assert.assertTrue("no submit button found.", getDialog()
+        Assert.assertTrue("no submit button found.", getTestingEngine()
                 .hasSubmitButton());
     }
 
@@ -1256,7 +1256,7 @@
      */
     public void assertSubmitButtonNotPresent() {
         assertFormPresent();
-        Assert.assertFalse("Submit Button found.", getDialog()
+        Assert.assertFalse("Submit Button found.", getTestingEngine()
                 .hasSubmitButton());
     }
 
@@ -1306,7 +1306,7 @@
      */
     public void assertResetButtonPresent() {
         assertFormPresent();
-        Assert.assertTrue("no reset button found.", getDialog()
+        Assert.assertTrue("no reset button found.", getTestingEngine()
                 .hasResetButton());
     }
 
@@ -1369,7 +1369,7 @@
      */
     public void assertButtonPresent(String buttonId) {
         assertFormPresent();
-        Assert.assertTrue("Button [" + buttonId + "] not found.", getDialog()
+        Assert.assertTrue("Button [" + buttonId + "] not found.", 
getTestingEngine()
                 .hasButton(buttonId));
     }
 
@@ -1455,7 +1455,7 @@
      */
     public void assertLinkPresentWithText(String linkText, int index) {
         Assert.assertTrue("Link with text [" + linkText + "] and index ["
-                + index + "] not found in response.", getDialog()
+                + index + "] not found in response.", getTestingEngine()
                 .hasLinkWithText(linkText, index));
     }
 
@@ -1503,7 +1503,7 @@
      */
     public void assertLinkPresentWithExactText(String linkText, int index) {
         Assert.assertTrue("Link with Exact text [" + linkText + "] and index ["
-                + index + "] not found in response.", getDialog()
+                + index + "] not found in response.", getTestingEngine()
                 .hasLinkWithExactText(linkText, index));
     }
 
@@ -1515,7 +1515,7 @@
      */
     public void assertLinkNotPresentWithExactText(String linkText, int index) {
         Assert.assertTrue("Link with Exact text [" + linkText + "] and index "
-                + index + " found in response.", !getDialog()
+                + index + " found in response.", !getTestingEngine()
                 .hasLinkWithExactText(linkText, index));
     }
 
@@ -1595,7 +1595,7 @@
         Assert.assertTrue("Unable to locate element with id \"" + elementID
                 + "\"", getTestingEngine().hasElement(elementID));
         Assert.assertTrue("Unable to locate [" + text + "] in element \""
-                + elementID + "\"", getDialog()
+                + elementID + "\"", getTestingEngine()
                 .isTextInElement(elementID, text));
     }
 
@@ -1633,7 +1633,7 @@
         Assert.assertTrue("Unable to locate element with id \"" + elementID
                 + "\"", getTestingEngine().hasElement(elementID));
         Assert.assertFalse("Regexp [" + regexp + "] matched in element ["
-                + elementID + "] when not expected", getDialog()
+                + elementID + "] when not expected", getTestingEngine()
                 .isMatchInElement(elementID, regexp));
     }
 
@@ -1677,7 +1677,7 @@
         Assert
                 .assertTrue("Window count is "
                         + getTestingEngine().getWindowCount() + " but "
-                        + windowCount + " was expected.", getDialog()
+                        + windowCount + " was expected.", getTestingEngine()
                         .getWindowCount() == windowCount);
     }
 

Modified: 
trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/util/TestingEngineRegistry.java
===================================================================
--- 
trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/util/TestingEngineRegistry.java
  2007-04-14 17:42:35 UTC (rev 693)
+++ 
trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/util/TestingEngineRegistry.java
  2007-04-15 18:13:50 UTC (rev 694)
@@ -21,6 +21,11 @@
      */
     public final static String TESTING_ENGINE_HTMLUNIT = 
"TestingEngineHtmlUnit";
 
+    /**
+     * Key of HtmlUnit testing engine.
+     */
+    public final static String TESTING_ENGINE_SELENIUM = 
"TestingEngineSelenium";
+
     private static Hashtable testingEngineMap = new Hashtable();
 
     static {
@@ -31,6 +36,13 @@
         } catch (ClassNotFoundException e) {
             // HtmlUnit Testing Engine is not present in the classpath. 
Nothing to do.
         }
+        cp = "net.sourceforge.jwebunit.selenium.SeleniumTestingEngineImpl";
+        // Try to load Selenium Testing Engine to check if it is present.
+        try {
+            addTestingEngine(TESTING_ENGINE_SELENIUM, cp);
+        } catch (ClassNotFoundException e) {
+            // Selenium Testing Engine is not present in the classpath. 
Nothing to do.
+        }
     }
 
     /**

Added: trunk/jwebunit-selenium-plugin/pom.xml
===================================================================
--- trunk/jwebunit-selenium-plugin/pom.xml                              (rev 0)
+++ trunk/jwebunit-selenium-plugin/pom.xml      2007-04-15 18:13:50 UTC (rev 
694)
@@ -0,0 +1,83 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+    <parent>
+        <artifactId>jwebunit</artifactId>
+        <groupId>net.sourceforge.jwebunit</groupId>
+        <version>1.5-SNAPSHOT</version>
+        <relativePath>..</relativePath>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+    <artifactId>jwebunit-selenium-plugin</artifactId>
+    <name>Selenium Plugin</name>
+    <description>Selenium plugin for JWebUnit.</description>
+    <repositories>
+        <repository>
+            <releases />
+            <snapshots />
+            <id>selenium</id>
+            <name>Selenium repository</name>
+            <url>http://maven.openqa.org/</url>
+        </repository>
+    </repositories>
+    <build>
+        <plugins>
+            <plugin>
+                <artifactId>maven-surefire-plugin</artifactId>
+                <configuration>
+                    <testFailureIgnore>false</testFailureIgnore>
+                    <includes>
+                        <include>**/*Test.java</include>
+                        <include>**/*Tests.java</include>
+                    </includes>
+                    <excludes>
+                        <exclude>**/*AbstractTest.java</exclude>
+                        <exclude>**/*AbstractTests.java</exclude>
+                    </excludes>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+    <dependencies>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.openqa.selenium.client-drivers</groupId>
+            <artifactId>selenium-java-client-driver</artifactId>
+            <version>0.9.2-SNAPSHOT</version>
+            <exclusions>
+                <exclusion>
+                    <groupId>org.openqa.selenium.server</groupId>
+                    <artifactId>selenium-server</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+        <dependency>
+            <groupId>net.sourceforge.jwebunit</groupId>
+            <artifactId>jwebunit-core</artifactId>
+            <version>${pom.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>net.sourceforge.jwebunit</groupId>
+            <artifactId>jwebunit-commons-tests</artifactId>
+            <version>${pom.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-log4j12</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>javax.servlet</groupId>
+            <artifactId>servlet-api</artifactId>
+        </dependency>
+    </dependencies>
+    <properties>
+        <topDirectoryLocation>..</topDirectoryLocation>
+    </properties>
+</project>
\ No newline at end of file

Added: 
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
                               (rev 0)
+++ 
trunk/jwebunit-selenium-plugin/src/main/java/net/sourceforge/jwebunit/selenium/SeleniumTestingEngineImpl.java
       2007-04-15 18:13:50 UTC (rev 694)
@@ -0,0 +1,565 @@
+/******************************************************************************
+ * JWebUnit project (http://jwebunit.sourceforge.net)                         *
+ * Distributed open-source, see full license under LICENCE.txt                *
+ 
******************************************************************************/
+package net.sourceforge.jwebunit.selenium;
+
+
+import java.io.InputStream;
+import java.net.URL;
+import java.util.LinkedList;
+import java.util.List;
+
+import net.sourceforge.jwebunit.api.ITestingEngine;
+import net.sourceforge.jwebunit.exception.ElementNotFoundException;
+import net.sourceforge.jwebunit.exception.ExpectedJavascriptAlertException;
+import net.sourceforge.jwebunit.exception.ExpectedJavascriptConfirmException;
+import net.sourceforge.jwebunit.exception.ExpectedJavascriptPromptException;
+import net.sourceforge.jwebunit.exception.TestingEngineResponseException;
+import net.sourceforge.jwebunit.html.Table;
+import net.sourceforge.jwebunit.javascript.JavascriptAlert;
+import net.sourceforge.jwebunit.javascript.JavascriptConfirm;
+import net.sourceforge.jwebunit.javascript.JavascriptPrompt;
+import net.sourceforge.jwebunit.util.TestContext;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.thoughtworks.selenium.DefaultSelenium;
+import com.thoughtworks.selenium.Selenium;
+import com.thoughtworks.selenium.SeleniumException;
+
+/**
+ * Acts as the wrapper for Selenium access. A testing engine is initialized 
with a given URL, and maintains conversational state
+ * as the dialog progresses through link navigation, form submission, etc.
+ * 
+ * @author Julien Henry
+ * 
+ */
+public class SeleniumTestingEngineImpl implements ITestingEngine {
+
+    /**
+     * Logger for this class.
+     */
+    private final Logger logger = 
LoggerFactory.getLogger(SeleniumTestingEngineImpl.class);
+
+    private Selenium selenium;
+
+    // Timeout in milliseconds.  It's a string 'cause Selenium wants a string.
+    private static final String timeout = "3000";
+    private static final int port = 4444;
+
+    private TestContext testContext;
+
+    // The xpath string that identifie the current form
+    // ie : @name='myForm'
+    private String formIdent;
+
+    // The xpath prefix that identifie the current frame
+    // ie : /html/frameset/[EMAIL PROTECTED]'myFrame']
+    private String currentFrame;
+
+    public SeleniumTestingEngineImpl() {
+    }
+
+    public void beginAt(URL aInitialURL, TestContext aTestContext)
+            throws TestingEngineResponseException {
+        this.setTestContext(aTestContext);
+        selenium = new DefaultSelenium("localhost", port, "*chrome",
+                aInitialURL.toString());
+        selenium.start();
+        gotoPage(aInitialURL);
+    }
+
+    public void checkCheckbox(String checkBoxName, String value) {
+        selenium.check("xpath=//[EMAIL PROTECTED]'checkbox' and @name='"
+                + checkBoxName + "' and @value='" + value + "']");
+    }
+
+    public void checkCheckbox(String checkBoxName) {
+        selenium.check("xpath=//[EMAIL PROTECTED]'checkbox' and @name='"
+                + checkBoxName + "']");
+    }
+
+    public void clickButton(String buttonId) {
+        selenium.click("id=buttonId");
+        selenium.waitForPageToLoad(timeout);
+    }
+
+    public void clickButtonWithText(String buttonValueText) {
+        selenium.click("xpath=" + formSelector() + "//button[contains(.,'" + 
buttonValueText + "')]");
+        selenium.waitForPageToLoad(timeout);
+    }
+
+    public void clickElementByXPath(String xpath) {
+        selenium.click("xpath=" + xpath);
+        selenium.waitForPageToLoad(timeout);
+    }
+
+    public void clickLink(String anID) {
+        selenium.click("xpath=//[EMAIL PROTECTED]'" + anID + "']");
+        selenium.waitForPageToLoad(timeout);
+    }
+
+    public void clickLinkWithExactText(String linkText, int index) {
+        selenium.click("xpath=//a[.//*='" + linkText + "'][" + index + 1 + 
"]");
+        selenium.waitForPageToLoad(timeout);
+    }
+
+    public void clickLinkWithImage(String imageFileName, int index) {
+        selenium.click("xpath=//a[contains(img/@src,'" + imageFileName + 
"')]");
+        selenium.waitForPageToLoad(timeout);
+    }
+
+    public void clickLinkWithText(String linkText, int index) {
+        selenium.click("xpath=//a[contains(.,'" + linkText + "')][" + index + 1
+                + "]");
+        selenium.waitForPageToLoad(timeout);
+    }
+
+    public void clickRadioOption(String radioGroup, String radioOptionValue) {
+        selenium.click("xpath=" + formSelector() + "//[EMAIL PROTECTED]'" + 
radioGroup + "' and @value='"
+                + radioOptionValue + "']");
+    }
+
+    public void closeBrowser() throws TestingEngineResponseException {
+        selenium.stop();
+    }
+
+    public void closeWindow() {
+        selenium.close();
+    }
+
+    public String getPageSource() {
+        return selenium.getHtmlSource();
+    }
+
+    public String getPageText() {
+        return selenium.getBodyText();
+    }
+
+    public String getPageTitle() {
+        return selenium.getTitle();
+    }
+    
+    /* (non-Javadoc)
+     * @see net.sourceforge.jwebunit.api.ITestingEngine#getCookies()
+     */
+    public List getCookies() {
+        List l = new LinkedList();
+        //FIXME How to parse this String in Cookie
+        l.add(selenium.getCookie());
+        return l;
+    }
+
+
+    public String[] getSelectedOptions(String selectName) {
+        return selenium.getSelectedValues("xpath=" + formSelector()
+                + "//[EMAIL PROTECTED]'" + selectName + "']");
+    }
+
+    public String getSelectOptionLabelForValue(String selectName,
+            String optionValue) {
+        return selenium.getText("xpath=" + formSelector()
+                + "//select/[EMAIL PROTECTED]'" + optionValue + "']");
+    }
+
+    public String getSelectOptionValueForLabel(String selectName,
+            String optionLabel) {
+        return selenium.getValue("xpath=" + formSelector()
+                + "//select/option[contains(.,'" + optionLabel + "']");
+    }
+
+    public String[] getSelectOptionValues(String selectName) {
+        String[] labels = selenium.getSelectOptions("xpath=" + formSelector()
+                + "//[EMAIL PROTECTED]'" + selectName + "']");
+        String[] values = new String[labels.length];
+        for (int i = 0; i < values.length; i++) {
+            values[i] = getSelectOptionValueForLabel(selectName, labels[i]);
+        }
+        return values;
+    }
+
+    public String getServerResponse() {
+        throw new UnsupportedOperationException("getServerResponse");
+    }
+
+    public void goBack() {
+        selenium.goBack();
+        selenium.waitForPageToLoad(timeout);
+    }
+
+    public void gotoFrame(String frameName) {
+        currentFrame = "/html/frameset/[EMAIL PROTECTED]'" + frameName + "']";
+    }
+
+    public void gotoPage(URL url) throws TestingEngineResponseException {
+        selenium.open(url.toString());
+        // selenium.waitForPageToLoad(timeout); implicit after open() 
+    }
+
+    public void gotoRootWindow() {
+        selenium.selectWindow("null");
+    }
+
+    public void gotoWindow(String windowName) {
+        selenium.selectWindow(windowName);
+    }
+
+    public void gotoWindowByTitle(String title) {
+        // TODO Implement gotoWindowByTitle in SeleniumDialog
+        throw new UnsupportedOperationException("gotoWindowByTitle");
+    }
+
+    public boolean hasButton(String buttonId) {
+        // Not bothering with formSelector here because we're using an ID
+        // to identify the element.  Is this the right thing to do?
+        return selenium.isElementPresent("xpath=//[EMAIL PROTECTED]'" + 
buttonId
+                + "']");
+    }
+
+    public boolean hasButtonWithText(String text) {
+        return selenium.isElementPresent("xpath=" + formSelector() + 
"//button[contains(.,'" + text
+                + "')]");
+    }
+
+    public boolean hasElement(String anID) {
+        return selenium.isElementPresent("xpath=//[EMAIL PROTECTED]'" + anID + 
"']");
+    }
+
+    public boolean hasElementByXPath(String xpath) {
+        return selenium.isElementPresent("xpath=" + xpath);
+    }
+
+    public boolean hasForm() {
+        return selenium.isElementPresent("xpath=//form");
+    }
+
+    public boolean hasForm(String nameOrID) {
+        return selenium.isElementPresent("xpath=//[EMAIL PROTECTED]'" + 
nameOrID
+                + "' or @id='" + nameOrID + "']");
+    }
+
+    public boolean hasFormParameterNamed(String paramName) {
+        return selenium.isElementPresent("xpath=" + formSelector()
+                + "//[EMAIL PROTECTED]'" + paramName + "']");
+    }
+
+    public boolean hasFrame(String frameName) {
+        return selenium.isElementPresent("xpath=//[EMAIL PROTECTED]'" + 
frameName + "']");
+    }
+
+    public boolean hasLink(String anId) {
+        return selenium.isElementPresent("xpath=//[EMAIL PROTECTED]'" + anId + 
"']");
+    }
+
+    public boolean hasLinkWithExactText(String linkText, int index) {
+        return selenium.isElementPresent("xpath=//a[.//*='" + linkText + "']["
+                + index + 1 + "]");
+    }
+
+    public boolean hasLinkWithImage(String imageFileName, int index) {
+        return selenium.isElementPresent("xpath=//a[contains(img/@src,'"
+                + imageFileName + "')]");
+    }
+
+    public boolean hasLinkWithText(String linkText, int index) {
+        return selenium.isElementPresent("xpath=//a[contains(.,'" + linkText
+                + "')][" + index + 1 + "]");
+    }
+
+    public boolean hasRadioOption(String radioGroup, String radioOptionValue) {
+        return selenium.isElementPresent("xpath=" + formSelector() + "//[EMAIL 
PROTECTED]'" + radioGroup
+                + "' and @value='" + radioOptionValue + "']");
+    }
+
+    public boolean hasSelectOption(String selectName, String optionLabel) {
+        try {
+            getSelectOptionValueForLabel(selectName, optionLabel);
+            return true;
+        } catch (SeleniumException e) {
+            return false;
+        }
+    }
+
+    public boolean hasSelectOptionValue(String selectName, String optionValue) 
{
+        try {
+            getSelectOptionLabelForValue(selectName, optionValue);
+            return true;
+        } catch (SeleniumException e) {
+            return false;
+        }
+    }
+    
+    public boolean hasSubmitButton() {
+        return selenium
+        .isElementPresent("xpath=" + formSelector() + "(//[EMAIL 
PROTECTED]'submit' or @type='image']|//[EMAIL PROTECTED]'submit'])");
+    }
+
+    public boolean hasSubmitButton(String nameOrID, String value) {
+        return selenium
+                .isElementPresent("xpath=" + formSelector() + 
"(//input[(@type='submit' or @type='image') and (@id='"
+                        + nameOrID + "' or @name='" + nameOrID
+                        + "') and @value='" + value + "']|//[EMAIL 
PROTECTED]'submit' and (@id='"
+                        + nameOrID + "' or @name='" + nameOrID
+                        + "') and @value='" + value + "'])");
+    }
+
+    public boolean hasSubmitButton(String nameOrID) {
+        return selenium
+        .isElementPresent("xpath=" + formSelector() + 
"(//input[(@type='submit' or @type='image') and (@id='"
+                + nameOrID + "' or @name='" + nameOrID
+                + "')]|//[EMAIL PROTECTED]'submit' and (@id='"
+                + nameOrID + "' or @name='" + nameOrID
+                + "')])");
+    }
+
+    public boolean hasResetButton() {
+        return selenium
+        .isElementPresent("xpath=" + formSelector() + "//[EMAIL 
PROTECTED]'reset']");
+    }
+
+    public boolean hasResetButton(String nameOrID) {
+        return selenium
+                .isElementPresent("xpath=" + formSelector() + "//[EMAIL 
PROTECTED]'reset' and (@id='"
+                        + nameOrID + "' or @name='" + nameOrID + "')]");
+    }
+
+    public boolean hasTable(String tableSummaryNameOrId) {
+        return selenium.isElementPresent("xpath=//[EMAIL 
PROTECTED]'"+tableSummaryNameOrId+"' or @name='"+tableSummaryNameOrId+"' or 
@summary='"+tableSummaryNameOrId+"']");
+    }
+
+    public boolean hasWindow(String windowName) {
+        // TODO Implement hasWindow in SeleniumDialog
+        throw new UnsupportedOperationException("hasWindow");
+    }
+
+    public boolean hasWindowByTitle(String title) {
+        // TODO Implement hasWindowByTitle in SeleniumDialog
+        throw new UnsupportedOperationException("hasWindowByTitle");
+    }
+
+    public boolean isCheckboxSelected(String checkBoxName) {
+        return selenium.isChecked("xpath=" + formSelector() + "//[EMAIL 
PROTECTED]'checkbox' and @name='"
+                + checkBoxName + "']");
+    }
+    
+    /* (non-Javadoc)
+     * @see 
net.sourceforge.jwebunit.api.ITestingEngine#isCheckboxSelected(java.lang.String,
 java.lang.String)
+     */
+    public boolean isCheckboxSelected(String checkBoxName, String 
checkBoxValue) {
+        return selenium.isChecked("xpath=" + formSelector() + "//[EMAIL 
PROTECTED]'checkbox' and @name='"
+                + checkBoxName + "' and @value='" + checkBoxValue + "']");
+    }
+
+
+    public boolean isMatchInElement(String elementID, String regexp) {
+        //TODO Implement isMatchInElement in SeleniumDialog
+        throw new UnsupportedOperationException("isMatchInElement");
+    }
+
+    public boolean isTextInElement(String elementID, String text) {
+        // TODO Implement isTextInElement in SeleniumDialog
+        throw new UnsupportedOperationException("isTextInElement");
+    }
+
+    public void refresh() {
+        selenium.refresh();
+        selenium.waitForPageToLoad(timeout);
+    }
+
+    public void reset() {
+        selenium.click("xpath=" + formSelector() + "//[EMAIL 
PROTECTED]'reset']");
+        selenium.waitForPageToLoad(timeout);
+    }
+
+    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]);
+        }
+    }
+
+    public void setScriptingEnabled(boolean value) {
+        if (value==false)
+            throw new UnsupportedOperationException("setScriptingEnabled");
+    }
+
+    public void setTextField(String inputName, String text) {
+        selenium.type("xpath=" + formSelector() + "(//[EMAIL 
PROTECTED]'"+inputName+"' and (@type='text' or @type='password' or 
@type='file')]|//[EMAIL PROTECTED]'"+inputName+"'])", text);
+    }
+
+    public void setWorkingForm(String nameOrId, int index) {
+        if (nameOrId != null)
+            formIdent="(@name='"+nameOrId+"' or @id='"+nameOrId+"') and 
position()="+index;
+        else
+            formIdent=null;
+    }
+
+    public void submit() {
+        selenium.click("xpath=" + formSelector() + "(//[EMAIL 
PROTECTED]'submit' or @type='image']|//[EMAIL PROTECTED]'submit'])");
+        selenium.waitForPageToLoad(timeout);
+    }
+
+    public void submit(String buttonName, String buttonValue) {
+        selenium.click("xpath=" + formSelector() + "(//input[(@type='submit' 
or @type='image') and (@id='"
+                        + buttonName + "' or @name='" + buttonName
+                        + "') and @value='" + buttonValue + "']|//[EMAIL 
PROTECTED]'submit' and (@id='"
+                        + buttonName + "' or @name='" + buttonName
+                        + "') and @value='" + buttonValue + "'])");
+        selenium.waitForPageToLoad(timeout);
+    }
+
+    public void submit(String buttonName) {
+        selenium.click("xpath=" + formSelector() + "(//input[(@type='submit' 
or @type='image') and (@id='"
+                        + buttonName + "' or @name='" + buttonName
+                        + "')]|//[EMAIL PROTECTED]'submit' and (@id='"
+                        + buttonName + "' or @name='" + buttonName
+                        + "')])");
+        selenium.waitForPageToLoad(timeout);
+    }
+
+    public void uncheckCheckbox(String checkBoxName, String value) {
+        selenium.uncheck("xpath=" + formSelector() + "//[EMAIL 
PROTECTED]'checkbox' and @name='"
+                + checkBoxName + "' and @value='" + value + "']");
+    }
+
+    public void uncheckCheckbox(String checkBoxName) {
+        selenium.uncheck("xpath=" + formSelector() + "//[EMAIL 
PROTECTED]'checkbox' and @name='"
+                + checkBoxName + "']");
+    }
+
+    public void unselectOptions(String selectName, String[] options) {
+        for (int i=0; i<options.length; i++) {
+            selenium.removeSelection("xpath=" + formSelector() + "//[EMAIL 
PROTECTED]'"+selectName+"']","value="+options[i]);
+        }
+    }
+
+    public TestContext getTestContext() {
+        return testContext;
+    }
+
+    public void setTestContext(TestContext testContext) {
+        this.testContext = testContext;
+    }
+
+    public Table getTable(String tableSummaryNameOrId) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    protected String formSelector() {
+        if (formIdent == null)
+            return "";
+        return "//form[" + formIdent + "]";
+    }
+
+    public int getWindowCount() {
+        //TODO implement getWindowCount in SeleniumDialog
+        throw new UnsupportedOperationException("getWindowCount");
+    }
+
+    public void gotoWindow(int windowID) {
+        selenium.selectWindow(""+windowID);
+    }
+
+    public String getTextFieldValue(String paramName) {
+        //TODO implement getTextFieldValue in SeleniumDialog
+        throw new UnsupportedOperationException("getTextFieldValue");
+    }
+
+    public String getHiddenFieldValue(String paramName) {
+        //TODO implement getHiddenFieldValue in SeleniumDialog
+        throw new UnsupportedOperationException("getHiddenFieldValue");
+    }
+    
+    public String getJavascriptAlert() throws ElementNotFoundException {
+        if (selenium.isAlertPresent()) {
+            return selenium.getAlert(); 
+        }
+        else {
+            throw new 
net.sourceforge.jwebunit.exception.ElementNotFoundException("There is no 
pending alert.");
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see 
net.sourceforge.jwebunit.api.ITestingEngine#getElementAttributByXPath(java.lang.String,
 java.lang.String)
+     */
+    public String getElementAttributByXPath(String xpath, String attribut) {
+        // TODO Auto-generated method stub
+        throw new UnsupportedOperationException("getElementAttributByXPath");
+    }
+
+    /* (non-Javadoc)
+     * @see 
net.sourceforge.jwebunit.api.ITestingEngine#getElementTextByXPath(java.lang.String)
+     */
+    public String getElementTextByXPath(String xpath) {
+        // TODO Auto-generated method stub
+        throw new UnsupportedOperationException("getElementTextByXPath");
+    }
+
+    /* (non-Javadoc)
+     * @see net.sourceforge.jwebunit.api.ITestingEngine#getInputStream()
+     */
+    public InputStream getInputStream() {
+        // TODO Auto-generated method stub
+        throw new UnsupportedOperationException("getInputStream");
+    }
+
+    /* (non-Javadoc)
+     * @see 
net.sourceforge.jwebunit.api.ITestingEngine#getInputStream(java.net.URL)
+     */
+    public InputStream getInputStream(URL url) throws 
TestingEngineResponseException {
+        // TODO Auto-generated method stub
+        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");
+    }
+
+    /* (non-Javadoc)
+     * @see 
net.sourceforge.jwebunit.api.ITestingEngine#getSelectedRadio(java.lang.String)
+     */
+    public String getSelectedRadio(String radioGroup) {
+        throw new UnsupportedOperationException("getSelectedRadio");
+    }
+
+    /* (non-Javadoc)
+     * @see 
net.sourceforge.jwebunit.api.ITestingEngine#setExpectedJavaScriptAlert(net.sourceforge.jwebunit.javascript.JavascriptAlert[])
+     */
+    public void setExpectedJavaScriptAlert(JavascriptAlert[] alerts) throws 
ExpectedJavascriptAlertException {
+        // TODO Auto-generated method stub
+        throw new UnsupportedOperationException("setExpectedJavaScriptAlert");
+        
+    }
+
+    /* (non-Javadoc)
+     * @see 
net.sourceforge.jwebunit.api.ITestingEngine#setExpectedJavaScriptConfirm(net.sourceforge.jwebunit.javascript.JavascriptConfirm[])
+     */
+    public void setExpectedJavaScriptConfirm(JavascriptConfirm[] confirms) 
throws ExpectedJavascriptConfirmException {
+        // TODO Auto-generated method stub
+        throw new 
UnsupportedOperationException("setExpectedJavaScriptConfirm");
+        
+    }
+
+    /* (non-Javadoc)
+     * @see 
net.sourceforge.jwebunit.api.ITestingEngine#setExpectedJavaScriptPrompt(net.sourceforge.jwebunit.javascript.JavascriptPrompt[])
+     */
+    public void setExpectedJavaScriptPrompt(JavascriptPrompt[] prompts) throws 
ExpectedJavascriptPromptException {
+        // TODO Auto-generated method stub
+        throw new 
UnsupportedOperationException("setExpectedJavaScriptPrompt");        
+    }
+
+    /* (non-Javadoc)
+     * @see net.sourceforge.jwebunit.api.ITestingEngine#setWorkingForm(int)
+     */
+    public void setWorkingForm(int index) {
+        // TODO Auto-generated method stub
+        throw new UnsupportedOperationException("setWorkingForm");
+    }
+
+}

Added: trunk/jwebunit-selenium-plugin/src/site/site.xml
===================================================================
--- trunk/jwebunit-selenium-plugin/src/site/site.xml                            
(rev 0)
+++ trunk/jwebunit-selenium-plugin/src/site/site.xml    2007-04-15 18:13:50 UTC 
(rev 694)
@@ -0,0 +1,13 @@
+<?xml version="1.0"?>
+<project name="JWebUnit">
+    <body>
+        <menu ref="parent" />
+        <menu name="Sourceforge">
+            <item name="Project page"
+                href="http://sourceforge.net/projects/jwebunit"; />
+            <item name="Download"
+                href="http://sourceforge.net/projects/jwebunit/files"; />
+        </menu>
+        <menu ref="reports" />
+    </body>
+</project>

Added: trunk/jwebunit-selenium-plugin/src/site/xdoc/index.xml
===================================================================
--- trunk/jwebunit-selenium-plugin/src/site/xdoc/index.xml                      
        (rev 0)
+++ trunk/jwebunit-selenium-plugin/src/site/xdoc/index.xml      2007-04-15 
18:13:50 UTC (rev 694)
@@ -0,0 +1,102 @@
+<?xml version="1.0"?>
+<document>
+    <properties>
+        <author email="dashorst.at.users.sourceforge.net">Martijn 
Dashorst</author>
+        <title>JWebUnit</title>
+    </properties>
+    <meta name="keyword" content="jwebunit, java, junit, htmlunit, jacobie, 
httpunit, integration, test, automated, html, webtest"/>
+       <head>
+               <link rel="shortcut icon" href="../favicon.ico" 
type="image/x-icon" />
+       </head>
+<body>
+<section name="HtmlUnit plugin">
+    <p>
+        The following sample testcases illustrate the conciseness of JWebUnit 
versus HtmlUnit
+        and JUnit alone.  The tests perform a google search
+        for the HtmlUnit home page, navigate to that page from Google, and 
validate that
+        there is a link to the user manual on the HtmlUnit home page.  The 
code in the
+        first column is pure HtmlUnit / JUnit, while the second column uses 
the JWebUnit framework.
+    </p>
+    <p>
+<table cellspacing="2" border="0">
+<tr><th>JUnit/HtmlUnit Test</th><th>JWebUnit Test</th></tr>
+<tr>
+<td valign="top" nowrap="nowrap">
+<source>
+import java.net.URL;
+
+import com.gargoylesoftware.htmlunit.WebClient;
+import com.gargoylesoftware.htmlunit.html.HtmlAnchor;
+import com.gargoylesoftware.htmlunit.html.HtmlForm;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
+import com.gargoylesoftware.htmlunit.html.HtmlTextInput;
+
+import junit.framework.TestCase;
+
+public class SearchExample extends TestCase {
+    
+    public void testSearch() throws Exception {
+        final WebClient webClient = new WebClient();
+        final URL url = new URL("http://www.google.com";);
+        final HtmlPage page = (HtmlPage)webClient.getPage(url);
+        HtmlForm form = (HtmlForm) page.getForms().get(0);
+        HtmlTextInput text = (HtmlTextInput) form.getInputByName("q");
+        text.setValueAttribute("HtmlUnit");
+        HtmlSubmitInput btn = (HtmlSubmitInput) form.getInputByName("btnG");
+        HtmlPage page2 = (HtmlPage) btn.click();
+        HtmlAnchor link = 
page2.getAnchorByHref("http://htmlunit.sourceforge.net/";);
+        HtmlPage page3 = (HtmlPage) link.click();
+        assertEquals(page3.getTitleText(), "htmlunit - Welcome to HtmlUnit");
+        assertNotNull(page3.getAnchorByHref("gettingStarted.html"));
+     }
+}
+</source>
+</td>
+<td valign="top" nowrap="nowrap">
+<source>
+import net.sourceforge.jwebunit.util.TestingEngineRegistry;
+import net.sourceforge.jwebunit.junit.WebTestCase;
+
+public class SearchExample extends WebTestCase {
+    
+    public void setUp() {
+        setTestingEngineKey(TestingEngineRegistry.TESTING_ENGINE_HTMLUNIT);
+        getTestContext().setBaseUrl("http://www.google.com";);
+     }
+    
+    public void testSearch() throws Exception {
+        beginAt("/");
+        setTextField("q", "htmlunit");
+        submit("btnG");
+        clickLinkWithText("HtmlUnit");
+        assertTitleEquals("htmlunit - Welcome to HtmlUnit");
+        assertLinkPresentWithText("Get started");
+     }
+}
+</source>
+</td>
+</tr>
+</table>
+</p>
+</section>
+<section name="HowTo manage dependencies with Maven 2">
+       <p>
+               Just add the following dependency to your pom:
+               <source><pre>
+...
+&lt;dependencies&gt;
+    ...
+    &lt;dependency&gt;
+        &lt;groupId&gt;net.sourceforge.jwebunit&lt;/groupId&gt;
+        &lt;artifactId&gt;jwebunit-htmlunit-plugin&lt;/artifactId&gt;
+        &lt;version&gt;1.4&lt;/version&gt;
+    &lt;/dependency&gt;
+    ...
+&lt;/dependencies&gt;
+...
+               </pre></source>
+       </p>
+</section>
+</body>    
+</document>

Added: 
trunk/jwebunit-selenium-plugin/src/test/java/net/sourceforge/jwebunit/selenium/JWebUnitTest.java
===================================================================
--- 
trunk/jwebunit-selenium-plugin/src/test/java/net/sourceforge/jwebunit/selenium/JWebUnitTest.java
                            (rev 0)
+++ 
trunk/jwebunit-selenium-plugin/src/test/java/net/sourceforge/jwebunit/selenium/JWebUnitTest.java
    2007-04-15 18:13:50 UTC (rev 694)
@@ -0,0 +1,58 @@
+/******************************************************************************
+ * JWebUnit project (http://jwebunit.sourceforge.net)                         *
+ * Distributed open-source, see full license under LICENCE.txt                *
+ 
******************************************************************************/
+package net.sourceforge.jwebunit.selenium;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import net.sourceforge.jwebunit.tests.util.JettySetup;
+import net.sourceforge.jwebunit.tests.*;
+
+/**
+ * Test Suite for JWebUnit.
+ * 
+ * @author Julien Henry
+ */
+public class JWebUnitTest extends TestCase {
+
+    /**
+     * Runs all the tests for JWebUnit. Add each new TestCase by using the 
<code>addTestSuite(Class)</code> method, so
+     * that the TestCase's <code>suite</code> method <strong>isn't called 
</strong>. This prevents
+     * <code>JettySetup</code> from starting the Jetty server twice and 
consequently the error 'port 80xx is already
+     * in use'.
+     * 
+     * @return the <code>TestSuite</code> containing all the tests for 
JWebUnit ready to run utilizing Jetty as
+     *         testserver.
+     */
+    public static Test suite() {
+        TestSuite suite = new TestSuite("Test for net.sourceforge.jwebunit");
+        // $JUnit-BEGIN$
+        suite.addTestSuite(FormSubmissionTest.class);
+        suite.addTestSuite(WebAssertionsTest.class);
+        suite.addTestSuite(FramesAndWindowsTest.class);
+        suite.addTestSuite(TableAssertionsTest.class);
+        suite.addTestSuite(ExpectedTableAssertionsHtmlTest.class);
+        suite.addTestSuite(ExpectedTableAssertionsXHtmlTest.class);
+        suite.addTestSuite(JavaScriptEventsTest.class);
+        suite.addTestSuite(JavaScriptTest.class);
+        suite.addTestSuite(HelloWorldTest.class);
+        suite.addTestSuite(HtmlParsingTest.class);
+        suite.addTestSuite(WebCookieTest.class);
+        suite.addTestSuite(TestContextTest.class);
+        suite.addTestSuite(FormAssertionsTest.class);
+        suite.addTestSuite(NavigationTest.class);
+        suite.addTestSuite(XPathTest.class);
+        suite.addTestSuite(CharsetTest.class);
+        suite.addTestSuite(ButtonAssertionsTest.class);
+        suite.addTestSuite(NonHtmlContentTest.class);
+        suite.addTestSuite(RedirectionTest.class);
+        suite.addTestSuite(ImageTest.class);
+        suite.addTestSuite(ResourceBundleAssertionsTest.class);
+        suite.addTest(JUnitPerfTest.suite());
+        // $JUnit-END$
+        return new JettySetup(suite);
+    }
+
+}

Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml       2007-04-14 17:42:35 UTC (rev 693)
+++ trunk/pom.xml       2007-04-15 18:13:50 UTC (rev 694)
@@ -23,6 +23,7 @@
         <module>jwebunit-core</module>
         <module>jwebunit-commons-tests</module>
         <module>jwebunit-htmlunit-plugin</module>
+       <module>jwebunit-selenium-plugin</module>
     </modules>
     <mailingLists>
         <mailingList>
@@ -276,6 +277,11 @@
                 <version>1.2</version>
             </dependency>
             <dependency>
+                <groupId>commons-io</groupId>
+                <artifactId>commons-io</artifactId>
+                <version>1.3.1</version>
+            </dependency>
+            <dependency>
                 <groupId>htmlunit</groupId>
                 <artifactId>htmlunit</artifactId>
                 <version>1.11</version>


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

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
JWebUnit-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jwebunit-development

Reply via email to