Revision: 461
Author:   henryju
Date:     2006-05-23 01:42:30 -0700 (Tue, 23 May 2006)
ViewCVS:  http://svn.sourceforge.net/jwebunit/?rev=461&view=rev

Log Message:
-----------
Add XPath methods : clickElementByXPath, assertElementPresentByXPath
Add XPath tests

Modified Paths:
--------------
    
trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/IJWebUnitDialog.java
    trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/WebTestCase.java
    trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/WebTester.java
    
trunk/jwebunit-htmlunit-plugin/src/main/java/net/sourceforge/jwebunit/htmlunit/HtmlUnitDialog.java
    
trunk/jwebunit-htmlunit-plugin/src/test/java/net/sourceforge/jwebunit/htmlunit/JWebUnitTest.java
    
trunk/jwebunit-httpunit-plugin/src/main/java/net/sourceforge/jwebunit/httpunit/HttpUnitDialog.java
    
trunk/jwebunit-jacobie-plugin/src/main/java/net/sourceforge/jwebunit/jacobie/JacobieDialog.java
    
trunk/jwebunit-selenium-plugin/src/main/java/net/sourceforge/jwebunit/selenium/SeleniumDialog.java
    
trunk/jwebunit-selenium-plugin/src/test/java/net/sourceforge/jwebunit/selenium/JWebUnitTest.java

Added Paths:
-----------
    
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/JavaScriptTest.java
    
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/XPathTest.java
    trunk/jwebunit-commons-tests/src/main/resources/testcases/XPathTest/
    
trunk/jwebunit-commons-tests/src/main/resources/testcases/XPathTest/next.html
    
trunk/jwebunit-commons-tests/src/main/resources/testcases/XPathTest/testPage.html
Added: 
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/JavaScriptTest.java
===================================================================
--- 
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/JavaScriptTest.java
                               (rev 0)
+++ 
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/JavaScriptTest.java
       2006-05-23 08:42:30 UTC (rev 461)
@@ -0,0 +1,32 @@
+/********************************************************************************
+ * Copyright (c) 2001, ThoughtWorks, Inc.
+ * Distributed open-source, see full license under 
licenses/jwebunit_license.txt
+ **********************************/
+package net.sourceforge.jwebunit.tests;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import net.sourceforge.jwebunit.tests.util.JettySetup;
+
+/**
+ * @author henryju
+ */
+
+public class JavaScriptTest  extends JWebUnitAPITestCase {
+
+    public static Test suite() {
+        Test suite = new TestSuite(JavaScriptTest.class);
+        return new JettySetup(suite);
+    }   
+    
+    public void setUp() throws Exception {
+        super.setUp();
+        getTestContext().setBaseUrl(HOST_PATH + "/JavaScriptTest");
+    }
+    
+    public void testDocumentWrite() {
+        beginAt("DocumentWrite.html");
+        assertTextPresent("Hello World");
+    }
+
+}

Added: 
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/XPathTest.java
===================================================================
--- 
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/XPathTest.java
                            (rev 0)
+++ 
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/XPathTest.java
    2006-05-23 08:42:30 UTC (rev 461)
@@ -0,0 +1,42 @@
+/**
+ * Test all methods that use XPath
+ * @author Julien Henry
+ */
+package net.sourceforge.jwebunit.tests;
+
+import net.sourceforge.jwebunit.tests.util.JettySetup;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+public class XPathTest extends JWebUnitAPITestCase {
+
+    public static Test suite() {
+        Test suite = new TestSuite(XPathTest.class);
+        return new JettySetup(suite);
+    }
+
+    public void setUp() throws Exception {
+        super.setUp();
+        getTestContext().setBaseUrl(HOST_PATH + "/XPathTest");
+    }
+
+    public void testAssertElementPresentByXPath() throws Throwable {
+        beginAt("/testPage.html");
+        assertPassFail(
+                "assertElementPresentByXPath",
+                "//tr[contains(.//a/@href,\"next\") and 
contains(string(),\"test link\")]",
+                "//InvalidXPath");
+    }
+
+    public void testAssertElementNotPresentByXPath() throws Throwable {
+        beginAt("/testPage.html");
+        assertPassFail("assertElementNotPresentByXPath", "//InvalidXPath",
+                "//tr[contains(.//a/@href,\"next\") and 
contains(string(),\"test link\")]");
+    }
+
+    public void testClickElementByXPath() throws Throwable {
+        beginAt("/testPage.html");
+        clickElementByXPath("//tr//a[contains(@href,\"next\") and 
contains(string(),\"test link\")]");
+        assertTitleEquals("Next");
+    }
+}

Added: 
trunk/jwebunit-commons-tests/src/main/resources/testcases/XPathTest/next.html
===================================================================
--- 
trunk/jwebunit-commons-tests/src/main/resources/testcases/XPathTest/next.html   
                            (rev 0)
+++ 
trunk/jwebunit-commons-tests/src/main/resources/testcases/XPathTest/next.html   
    2006-05-23 08:42:30 UTC (rev 461)
@@ -0,0 +1,8 @@
+<html>
+       <head>
+               <title>Next</title>
+       </head>
+       <body>
+               Good Morning...
+       </body>
+</html>
\ No newline at end of file

Added: 
trunk/jwebunit-commons-tests/src/main/resources/testcases/XPathTest/testPage.html
===================================================================
--- 
trunk/jwebunit-commons-tests/src/main/resources/testcases/XPathTest/testPage.html
                           (rev 0)
+++ 
trunk/jwebunit-commons-tests/src/main/resources/testcases/XPathTest/testPage.html
   2006-05-23 08:42:30 UTC (rev 461)
@@ -0,0 +1,16 @@
+<html>
+       <head>
+               <title>This is a test page.</title>
+       </head>
+<body>
+<table summary="testTable">
+       <tr>
+               <td><a href="next.html">test link</a></td>
+       </tr>
+       <tr>
+               <td>table text row 2</td>
+       </tr>
+</table>
+<a href="next.html">test link</a>
+</body>
+</html>
\ No newline at end of file

Modified: 
trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/IJWebUnitDialog.java
===================================================================
--- 
trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/IJWebUnitDialog.java 
    2006-05-22 15:26:46 UTC (rev 460)
+++ 
trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/IJWebUnitDialog.java 
    2006-05-23 08:42:30 UTC (rev 461)
@@ -575,8 +575,11 @@
      *            A suffix of the image's filename; for example, to match
      *            <tt>"images/my_icon.png"<tt>, you could just pass in
      *                      <tt>"my_icon.png"<tt>.
+     * @param index
+     *            The 0-based index, when more than one link with the same text
+     *            is expected.
      */
-    void clickLinkWithImage(String imageFileName);
+    void clickLinkWithImage(String imageFileName, int index);
 
     /**
      * Test if element with given id exists.
@@ -587,6 +590,22 @@
     boolean hasElement(String anID);
 
     /**
+     * Test if element with given xpath exists.
+     * 
+     * @param xpath
+     *            xpath of the element.
+     */
+    boolean hasElementByXPath(String xpath);
+    
+    /**
+     * Click element with given xpath.
+     * 
+     * @param xpath
+     *            xpath of the element.
+     */
+    void clickElementByXPath(String xpath);
+
+    /**
      * Return true if a given string is contained within the specified element.
      * 
      * @param elementID

Modified: 
trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/WebTestCase.java
===================================================================
--- trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/WebTestCase.java 
2006-05-22 15:26:46 UTC (rev 460)
+++ trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/WebTestCase.java 
2006-05-23 08:42:30 UTC (rev 461)
@@ -1,8 +1,3 @@
-/********************************************************************************
- * Copyright (c) 2001, ThoughtWorks, Inc.
- * Distributed open-source, see full license under 
licenses/jwebunit_license.txt
- **********************************/
-
 package net.sourceforge.jwebunit;
 
 import java.io.PrintStream;
@@ -14,14 +9,15 @@
  * Junit assertions. This class uses [EMAIL PROTECTED] 
net.sourceforge.jwebunit.WebTester}
  * as a mixin - See that class for method documentation.
  * 
+ * @author Julien Henry
  * @author Jim Weaver
  * @author Wilkes Joiner
  */
 public class WebTestCase extends TestCase {
     private WebTester tester = null;
 
-    //BEGIN CONSTRUCTORS....
-    
+    // BEGIN CONSTRUCTORS....
+
     public WebTestCase(String name) {
         super(name);
     }
@@ -29,21 +25,21 @@
     public WebTestCase() {
     }
 
-    //END CONSTRUCTORS....
-    
-    //BEGIN JUNIT SETUP / TEARDOWN / RUNBARE OVERRIDES....
-    
+    // END CONSTRUCTORS....
+
+    // BEGIN JUNIT SETUP / TEARDOWN / RUNBARE OVERRIDES....
+
     public void setUp() throws Exception {
-       super.setUp();
+        super.setUp();
 
-        //New implementation on choosing a testing engine (dialog).
-        //setTestingEngineKey(TestingEngineRegistry.TESTING_ENGINE_JACOBIE);
-        //setTestingEngineKey(TestingEngineRegistry.TESTING_ENGINE_HTTPUNIT);
+        // New implementation on choosing a testing engine (dialog).
+        // setTestingEngineKey(TestingEngineRegistry.TESTING_ENGINE_JACOBIE);
+        // setTestingEngineKey(TestingEngineRegistry.TESTING_ENGINE_HTTPUNIT);
     }
-    
+
     public void tearDown() throws Exception {
-       closeBrowser();
-       super.tearDown();
+        closeBrowser();
+        super.tearDown();
     }
 
     /**
@@ -62,27 +58,27 @@
         }
     }
 
-    //END JUNIT SETUP / TEARDOWN / RUNBARE OVERRIDES....  
+    // END JUNIT SETUP / TEARDOWN / RUNBARE OVERRIDES....
 
     /**
-     * Select the Testing Engine that you want to use for the tests. 
-     * If this isn't called, then jWebUnit will default to using
-     * httpunit as the testing engine.
+     * Select the Testing Engine that you want to use for the tests. If this
+     * isn't called, then jWebUnit will default to using httpunit as the 
testing
+     * engine.
      */
     public void setTestingEngineKey(String aTestingEngineKey) {
-       getTester().setTestingEngineKey(aTestingEngineKey);
+        getTester().setTestingEngineKey(aTestingEngineKey);
     }
-    
+
     public void setScriptingEnabled(boolean value) {
         getTester().setScriptingEnabled(value);
     }
-    
+
     public WebTester getTester() {
         return tester;
     }
 
     public void setTester(WebTester aWebTester) {
-               this.tester = aWebTester;
+        this.tester = aWebTester;
     }
 
     public IJWebUnitDialog getDialog() {
@@ -195,20 +191,27 @@
         tester.assertNoMatchInTable(tableSummaryOrId, regexp);
     }
 
-    public void assertTableEquals(String tableSummaryOrId, ExpectedTable 
expectedTable) {
-        getTester().assertTableEquals(tableSummaryOrId, 
expectedTable.getExpectedStrings());
+    public void assertTableEquals(String tableSummaryOrId,
+            ExpectedTable expectedTable) {
+        getTester().assertTableEquals(tableSummaryOrId,
+                expectedTable.getExpectedStrings());
     }
 
-    public void assertTableEquals(String tableSummaryOrId, String[][] 
expectedCellValues) {
+    public void assertTableEquals(String tableSummaryOrId,
+            String[][] expectedCellValues) {
         getTester().assertTableEquals(tableSummaryOrId, expectedCellValues);
     }
 
-    public void assertTableRowsEqual(String tableSummaryOrId, int startRow, 
ExpectedTable expectedTable) {
-        getTester().assertTableRowsEqual(tableSummaryOrId, startRow, 
expectedTable);
+    public void assertTableRowsEqual(String tableSummaryOrId, int startRow,
+            ExpectedTable expectedTable) {
+        getTester().assertTableRowsEqual(tableSummaryOrId, startRow,
+                expectedTable);
     }
 
-    public void assertTableRowsEqual(String tableSummaryOrId, int startRow, 
String[][] expectedCellValues) {
-        getTester().assertTableRowsEqual(tableSummaryOrId, startRow, 
expectedCellValues);
+    public void assertTableRowsEqual(String tableSummaryOrId, int startRow,
+            String[][] expectedCellValues) {
+        getTester().assertTableRowsEqual(tableSummaryOrId, startRow,
+                expectedCellValues);
     }
 
     public void assertTableMatch(String tableSummaryOrId,
@@ -270,8 +273,7 @@
         getTester().assertFormElementEquals(formElementName, expectedValue);
     }
 
-    public void assertFormElementMatch(String formElementName,
-            String regexp) {
+    public void assertFormElementMatch(String formElementName, String regexp) {
         tester.assertFormElementMatch(formElementName, regexp);
     }
 
@@ -291,7 +293,8 @@
         getTester().assertRadioOptionPresent(radioGroup, radioOption);
     }
 
-    public void assertRadioOptionNotPresent(String radioGroup, String 
radioOption) {
+    public void assertRadioOptionNotPresent(String radioGroup,
+            String radioOption) {
         getTester().assertRadioOptionNotPresent(radioGroup, radioOption);
     }
 
@@ -299,7 +302,8 @@
         getTester().assertRadioOptionSelected(radioGroup, radioOption);
     }
 
-    public void assertRadioOptionNotSelected(String radioGroup, String 
radioOption) {
+    public void assertRadioOptionNotSelected(String radioGroup,
+            String radioOption) {
         getTester().assertRadioOptionNotSelected(radioGroup, radioOption);
     }
 
@@ -307,15 +311,18 @@
         getTester().assertSelectOptionPresent(selectName, optionLabel);
     }
 
-    public void assertSelectOptionNotPresent(String selectName, String 
optionLabel) {
+    public void assertSelectOptionNotPresent(String selectName,
+            String optionLabel) {
         getTester().assertSelectOptionNotPresent(selectName, optionLabel);
     }
 
-    public void assertSelectOptionValuePresent(String selectName, String 
optionValue) {
+    public void assertSelectOptionValuePresent(String selectName,
+            String optionValue) {
         getTester().assertSelectOptionValuePresent(selectName, optionValue);
     }
 
-    public void assertSelectOptionValueNotPresent(String selectName, String 
optionValue) {
+    public void assertSelectOptionValueNotPresent(String selectName,
+            String optionValue) {
         getTester().assertSelectOptionValueNotPresent(selectName, optionValue);
     }
 
@@ -327,11 +334,13 @@
         getTester().assertSelectOptionsNotEqual(selectName, options);
     }
 
-    public void assertSelectOptionValuesEqual(String selectName, String[] 
options) {
+    public void assertSelectOptionValuesEqual(String selectName,
+            String[] options) {
         getTester().assertSelectOptionValuesEqual(selectName, options);
     }
 
-    public void assertSelectOptionValuesNotEqual(String selectName, String[] 
options) {
+    public void assertSelectOptionValuesNotEqual(String selectName,
+            String[] options) {
         getTester().assertSelectOptionValuesNotEqual(selectName, options);
     }
 
@@ -347,7 +356,8 @@
         getTester().assertSelectedOptionValueEquals(selectName, value);
     }
 
-    public void assertSelectedOptionValuesEqual(String selectName, String[] 
values) {
+    public void assertSelectedOptionValuesEqual(String selectName,
+            String[] values) {
         getTester().assertSelectedOptionValuesEqual(selectName, values);
     }
 
@@ -367,7 +377,8 @@
         getTester().assertSubmitButtonNotPresent(buttonName);
     }
 
-    public void assertSubmitButtonPresent(String buttonName, String 
expectedValue) {
+    public void assertSubmitButtonPresent(String buttonName,
+            String expectedValue) {
         getTester().assertSubmitButtonPresent(buttonName, expectedValue);
     }
 
@@ -411,29 +422,26 @@
         getTester().assertLinkNotPresentWithText(linkText, index);
     }
 
-    //SF.NET RFE: 996031
+    // SF.NET RFE: 996031
     public void assertLinkPresentWithExactText(String linkText) {
         getTester().assertLinkPresentWithExactText(linkText);
     }
 
-    //SF.NET RFE: 996031
+    // SF.NET RFE: 996031
     public void assertLinkNotPresentWithExactText(String linkText) {
         getTester().assertLinkNotPresentWithExactText(linkText);
     }
 
-    //SF.NET RFE: 996031
+    // SF.NET RFE: 996031
     public void assertLinkPresentWithExactText(String linkText, int index) {
         getTester().assertLinkPresentWithExactText(linkText, index);
     }
 
-    //SF.NET RFE: 996031
+    // SF.NET RFE: 996031
     public void assertLinkNotPresentWithExactText(String linkText, int index) {
         getTester().assertLinkNotPresentWithExactText(linkText, index);
     }
-    
-    
-    
-    
+
     public void assertLinkPresentWithImage(String imageFileName) {
         getTester().assertLinkPresentWithImage(imageFileName);
     }
@@ -450,6 +458,26 @@
         getTester().assertElementNotPresent(anID);
     }
 
+    /**
+     * Assert that an element with a given xpath is present.
+     * 
+     * @param xpath
+     *            element xpath to test for.
+     */
+    public void assertElementPresentByXPath(String xpath) {
+        getTester().assertElementPresentByXPath(xpath);
+    }
+
+    /**
+     * Assert that an element with a given xpath is not present.
+     * 
+     * @param xpath
+     *            element xpath to test for.
+     */
+    public void assertElementNotPresentByXPath(String xpath) {
+        getTester().assertElementNotPresentByXPath(xpath);
+    }
+
     public void assertTextInElement(String elID, String text) {
         getTester().assertTextInElement(elID, text);
     }
@@ -488,23 +516,24 @@
     public void assertCookieValueEquals(String cookieName, String 
expectedValue) {
         getTester().assertCookieValueEquals(cookieName, expectedValue);
     }
-    
+
     public void assertCookieValueMatch(String cookieName, String regexp) {
         tester.assertCookieValueMatch(cookieName, regexp);
     }
 
     // Form interaction methods
-    
+
     /**
-     * Gets the value of a form input element.  Allows getting information 
from a form element.
-     * Also, checks assertions as well.
-     *
-     * @param formElementName name of form element.
+     * Gets the value of a form input element. Allows getting information from 
a
+     * form element. Also, checks assertions as well.
+     * 
+     * @param formElementName
+     *            name of form element.
      * @param value
      */
     public String getFormElementValue(String formElementName) {
         return getTester().getFormElementValue(formElementName);
-    }    
+    }
 
     public void setWorkingForm(String nameOrId) {
         getTester().setWorkingForm(nameOrId);
@@ -518,7 +547,7 @@
     public void setFormElement(String formElementName, String value) {
         getTester().setFormElement(formElementName, value);
     }
-    
+
     public void setTextField(String textFieldName, String value) {
         getTester().setTextField(textFieldName, value);
     }
@@ -527,10 +556,26 @@
         getTester().setFormElementWithLabel(formElementLabel, value);
     }
 
+    /**
+     * Select a specified checkbox. If the checkbox is already checked then the
+     * checkbox will stay checked.
+     * 
+     * @param checkBoxName
+     *            name of checkbox to be selected.
+     */
     public void checkCheckbox(String checkBoxName) {
         getTester().checkCheckbox(checkBoxName);
     }
 
+    /**
+     * Select a specified checkbox. If the checkbox is already checked then the
+     * checkbox will stay checked.
+     * 
+     * @param checkBoxName
+     *            name of checkbox to be selected.
+     * @param value
+     *            value of checkbox to be selected.
+     */
     public void checkCheckbox(String checkBoxName, String value) {
         getTester().checkCheckbox(checkBoxName, value);
     }
@@ -538,15 +583,31 @@
     public void checkCheckboxWithLabel(String formElementLabel) {
         getTester().checkCheckboxWithLabel(formElementLabel);
     }
-    
+
     public void checkCheckboxBeforeLabel(String formElementLabel) {
         getTester().checkCheckboxBeforeLabel(formElementLabel);
-    }    
-    
+    }
+
+    /**
+     * Deselect a specified checkbox. If the checkbox is already unchecked then
+     * the checkbox will stay unchecked.
+     * 
+     * @param checkBoxName
+     *            name of checkbox to be deselected.
+     */
     public void uncheckCheckbox(String checkBoxName) {
         getTester().uncheckCheckbox(checkBoxName);
     }
 
+    /**
+     * Deselect a specified checkbox. If the checkbox is already unchecked then
+     * the checkbox will stay unchecked.
+     * 
+     * @param checkBoxName
+     *            name of checkbox to be deselected.
+     * @param value
+     *            value of checkbox to be deselected.
+     */
     public void uncheckCheckbox(String checkBoxName, String value) {
         getTester().uncheckCheckbox(checkBoxName, value);
     }
@@ -574,6 +635,7 @@
     public void selectOptionsByValues(String selectName, String[] values) {
         getTester().selectOptionsByValues(selectName, values);
     }
+
     // Form submission and link navigation methods
 
     public void submit() {
@@ -583,7 +645,7 @@
     public void submit(String buttonName) {
         getTester().submit(buttonName);
     }
-    
+
     public void submit(String buttonName, String buttonValue) {
         getTester().submit(buttonName, buttonValue);
     }
@@ -593,9 +655,9 @@
      * the current form is established.
      */
     public void reset() {
-       getTester().reset();
-    }    
-    
+        getTester().reset();
+    }
+
     public void clickLinkWithText(String linkText) {
         getTester().clickLinkWithText(linkText);
     }
@@ -616,6 +678,14 @@
         getTester().clickLinkWithTextAfterText(linkText, labelText);
     }
 
+    /**
+     * Navigate by selection of a link with a given image.
+     * 
+     * @param imageFileName
+     *            A suffix of the image's filename; for example, to match
+     *            <tt>"images/my_icon.png"</tt>, you could just pass in
+     *            <tt>"my_icon.png"</tt>.
+     */
     public void clickLinkWithImage(String imageFileName) {
         getTester().clickLinkWithImage(imageFileName);
     }
@@ -627,17 +697,28 @@
     public void clickButton(String buttonId) {
         getTester().clickButton(buttonId);
     }
-    
+
     public void clickButtonWithText(String buttonValueText) {
         getTester().clickButtonWithText(buttonValueText);
     }
-    
+
     protected void clickRadioOption(String radioGroup, String radioOption) {
         getTester().clickRadioOption(radioGroup, radioOption);
     }
+    
+    /**
+     * Click element with given xpath.
+     * 
+     * @param xpath
+     *            xpath of the element.
+     */
+    protected void clickElementByXPath(String xpath) {
+        getTester().clickElementByXPath(xpath);
+    }
 
-    //Window and Frame Navigation Methods
 
+    // Window and Frame Navigation Methods
+
     public void gotoRootWindow() {
         getTester().gotoRootWindow();
     }
@@ -653,7 +734,7 @@
     public void gotoFrame(String frameName) {
         getTester().gotoFrame(frameName);
     }
-    
+
     protected void dumpCookies() {
         getTester().dumpCookies();
     }
@@ -682,9 +763,9 @@
     protected void dumpTable(String tableNameOrId) {
         getTester().dumpTable(tableNameOrId);
     }
-    
-    //Settings
-    
+
+    // Settings
+
     public void setTableEmptyCellCompression(boolean bool) {
         getTester().setTableEmptyCellCompression(bool);
     }

Modified: 
trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/WebTester.java
===================================================================
--- trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/WebTester.java   
2006-05-22 15:26:46 UTC (rev 460)
+++ trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/WebTester.java   
2006-05-23 08:42:30 UTC (rev 461)
@@ -1,7 +1,3 @@
-/********************************************************************************
- * Copyright (c) 2001, ThoughtWorks, Inc.
- * Distributed open-source, see full license under 
licenses/jwebunit_license.txt
- **********************************/
 package net.sourceforge.jwebunit;
 
 import java.io.PrintStream;
@@ -23,6 +19,7 @@
  * property file for web resources (a la Struts), though a resource file for 
the
  * app is not required.
  * 
+ * @author Julien Henry
  * @author Jim Weaver
  * @author Wilkes Joiner
  */
@@ -34,12 +31,6 @@
     private boolean tableEmptyCellCompression = false;
 
     /**
-     * This is the reference to the testing engine registry that contains the
-     * list of known testing engines for jWebUnit to use for testing.
-     */
-    private TestingEngineRegistry testingEngineRegistry = new 
TestingEngineRegistry();
-
-    /**
      * This is the testing engine key that the webtester will use to find the
      * correct testing engine from the registry.
      */
@@ -76,7 +67,7 @@
         String theTestingEngineKey = getTestingEngineKey();
         Class theClass;
         try {
-            theClass = getTestingEngineRegistry().getTestingEngineClass(
+            theClass = TestingEngineRegistry.getTestingEngineClass(
                     theTestingEngineKey);
         } catch (ClassNotFoundException e1) {
             throw new RuntimeException(e1);
@@ -683,6 +674,7 @@
      * @param formElementLabel
      *            label preceding form element.
      * @see #setFormElementWithLabel(String,String)
+     * @deprecated
      */
     public void assertFormElementPresentWithLabel(String formElementLabel) {
         Assert.assertTrue("Did not find form element with label ["
@@ -696,6 +688,7 @@
      * @param formElementLabel
      *            label preceding form element.
      * @see #setFormElementWithLabel(String,String)
+     * @deprecated
      */
     public void assertFormElementNotPresentWithLabel(String formElementLabel) {
         Assert.assertFalse("Found form element with label [" + formElementLabel
@@ -1361,6 +1354,28 @@
     }
 
     /**
+     * Assert that an element with a given xpath is present.
+     * 
+     * @param xpath
+     *            element xpath to test for.
+     */
+    public void assertElementPresentByXPath(String xpath) {
+        Assert.assertTrue("Unable to locate element with xpath \"" + xpath + 
"\"",
+                getDialog().hasElementByXPath(xpath));
+    }
+
+    /**
+     * Assert that an element with a given xpath is not present.
+     * 
+     * @param xpath
+     *            element xpath to test for.
+     */
+    public void assertElementNotPresentByXPath(String xpath) {
+        Assert.assertFalse("Located element with xpath \"" + xpath + "\"",
+                getDialog().hasElementByXPath(xpath));
+    }
+
+    /**
      * Assert that a given element contains specific text.
      * 
      * @param elementID
@@ -1558,6 +1573,7 @@
      * @param formElementLabel
      *            label preceding form element.
      * @param value
+     * @deprecated
      */
     public void setFormElementWithLabel(String formElementLabel, String value) 
{
         String name = getDialog().getFormElementNameForLabel(formElementLabel);
@@ -1571,13 +1587,22 @@
      * checkbox will stay checked.
      * 
      * @param checkBoxName
-     *            name of checkbox to be deselected.
+     *            name of checkbox to be selected.
      */
     public void checkCheckbox(String checkBoxName) {
         assertFormElementPresent(checkBoxName);
         getDialog().checkCheckbox(checkBoxName);
     }
 
+    /**
+     * Select a specified checkbox. If the checkbox is already checked then the
+     * checkbox will stay checked.
+     * 
+     * @param checkBoxName
+     *            name of checkbox to be selected.
+     * @param value
+     *            value of checkbox to be selected.
+     */
     public void checkCheckbox(String checkBoxName, String value) {
         assertFormElementPresent(checkBoxName);
         getDialog().checkCheckbox(checkBoxName, value);
@@ -1595,6 +1620,7 @@
      * 
      * @param formElementLabel
      *            The text label, appearing after the checkbox
+     * @deprecated
      */
     public void checkCheckboxBeforeLabel(String formElementLabel) {
         assertTextPresent(formElementLabel);
@@ -1617,6 +1643,7 @@
      * 
      * @param formElementLabel
      *            The text label, appearing after the checkbox
+     * @deprecated
      */
     public void checkCheckboxWithLabel(String formElementLabel) {
         assertTextPresent(formElementLabel);
@@ -1638,6 +1665,15 @@
         getDialog().uncheckCheckbox(checkBoxName);
     }
 
+    /**
+     * Deselect a specified checkbox. If the checkbox is already unchecked then
+     * the checkbox will stay unchecked.
+     * 
+     * @param checkBoxName
+     *            name of checkbox to be deselected.
+     * @param value
+     *            value of checkbox to be deselected.
+     */
     public void uncheckCheckbox(String checkBoxName, String value) {
         assertFormElementPresent(checkBoxName);
         getDialog().uncheckCheckbox(checkBoxName, value);
@@ -1791,6 +1827,7 @@
     /**
      * Search for labelText in the document, then search forward until finding 
a
      * link called linkText. Click it.
+     * @deprecated
      */
     public void clickLinkWithTextAfterText(String linkText, String labelText) {
         getDialog().clickLinkWithTextAfterText(linkText, labelText);
@@ -1827,7 +1864,7 @@
      */
     public void clickLinkWithImage(String imageFileName) {
         assertLinkPresentWithImage(imageFileName);
-        getDialog().clickLinkWithImage(imageFileName);
+        getDialog().clickLinkWithImage(imageFileName, 0);
     }
 
     /**
@@ -1853,6 +1890,17 @@
         assertRadioOptionPresent(radioGroup, radioOption);
         getDialog().clickRadioOption(radioGroup, radioOption);
     }
+    
+    /**
+     * Click element with given xpath.
+     * 
+     * @param xpath
+     *            xpath of the element.
+     */
+    public void clickElementByXPath(String xpath) {
+        assertElementPresentByXPath(xpath);
+        getDialog().clickElementByXPath(xpath);
+    }
 
     // Window and Frame Navigation Methods
 
@@ -2043,27 +2091,6 @@
         return testingEngineKey;
     }
 
-    /**
-     * Protected only because consumers outside don't need to set a new
-     * registry.
-     * 
-     * @param testingEngineRegistry
-     *            The testingEngineRegistry to set.
-     */
-    protected void setTestingEngineRegistry(
-            TestingEngineRegistry testingEngineRegistry) {
-        this.testingEngineRegistry = testingEngineRegistry;
-    }
-
-    /**
-     * Gets the Testing Engine Registry.
-     * 
-     * @return Returns the testingEngineRegistry.
-     */
-    public TestingEngineRegistry getTestingEngineRegistry() {
-        return testingEngineRegistry;
-    }
-
     private RE getRE(String regexp) {
         RE re = null;
         try {

Modified: 
trunk/jwebunit-htmlunit-plugin/src/main/java/net/sourceforge/jwebunit/htmlunit/HtmlUnitDialog.java
===================================================================
--- 
trunk/jwebunit-htmlunit-plugin/src/main/java/net/sourceforge/jwebunit/htmlunit/HtmlUnitDialog.java
  2006-05-22 15:26:46 UTC (rev 460)
+++ 
trunk/jwebunit-htmlunit-plugin/src/main/java/net/sourceforge/jwebunit/htmlunit/HtmlUnitDialog.java
  2006-05-23 08:42:30 UTC (rev 461)
@@ -472,14 +472,6 @@
         return wc.getWebWindowByName(windowName);
     }
 
-    public boolean hasElement(String anID) {
-        return getElement(anID) != null;
-    }
-
-    public boolean isXPathElementPresent(String xpath) {
-        return getXPathElement(xpath) != null;
-    }
-
     private HtmlElement getElement(String anID) {
         try {
             return ((HtmlPage) win.getEnclosedPage()).getHtmlElementById(anID);
@@ -488,7 +480,7 @@
         }
     }
 
-    private HtmlElement getXPathElement(String xpath) {
+    private HtmlElement getElementByXPath(String xpath) {
         List l = null;
         try {
             final HtmlUnitXPath xp = new HtmlUnitXPath(xpath);
@@ -1145,38 +1137,15 @@
      *            id of link to be navigated.
      */
     public void clickLink(String anID) {
-        clickXPathElement("//[EMAIL PROTECTED]"" + anID + "\"]");
+        clickElementByXPath("//[EMAIL PROTECTED]"" + anID + "\"]");
     }
 
-    /**
-     * Clicks element by xpath. A RuntimeException is thrown if no such element
-     * can be found or if element is not clickable.
-     * 
-     * @param xpath
-     *            xpath of element to be clicked.
-     */
-    public void clickXPathElement(String xpath) {
-        HtmlElement e = getXPathElement(xpath);
-        if (e == null)
-            throw new RuntimeException("No element found with xpath \"" + xpath
-                    + "\"");
-        try {
-            ClickableElement c = (ClickableElement) e;
-            c.click();
-        } catch (ClassCastException exp) {
-            throw new RuntimeException("Element with xpath \"" + xpath
-                    + "\" is not clickable");
-        } catch (IOException exp) {
-            throw new RuntimeException("Click failed");
-        }
-    }
-
     private HtmlAnchor getLinkWithText(String linkText) {
         return getLinkWithText(linkText, 0);
     }
 
     private HtmlAnchor getLinkWithImage(String filename, int index) {
-        return (HtmlAnchor) getXPathElement("(//a[img[contains(@src,\""
+        return (HtmlAnchor) getElementByXPath("(//a[img[contains(@src,\""
                 + filename + "\")]])[" + index + 1 + "]");
     }
 
@@ -1200,10 +1169,6 @@
      *            <tt>"images/my_icon.png"<tt>, you could just pass in
      *                      <tt>"my_icon.png"<tt>.
      */
-    public void clickLinkWithImage(String imageFileName) {
-        clickLinkWithImage(imageFileName, 0);
-    }
-
     public void clickLinkWithImage(String imageFileName, int index) {
         HtmlAnchor link = getLinkWithImage(imageFileName, index);
         if (link == null)
@@ -1215,7 +1180,31 @@
             throw new RuntimeException("Click failed");
         }
     }
+    
+    public boolean hasElement(String anID) {
+        return getElement(anID) != null;
+    }
 
+    public boolean hasElementByXPath(String xpath) {
+        return getElementByXPath(xpath) != null;
+    }
+    
+    public void clickElementByXPath(String xpath) {
+        HtmlElement e = getElementByXPath(xpath);
+        if (e == null)
+            throw new RuntimeException("No element found with xpath \"" + xpath
+                    + "\"");
+        try {
+            ClickableElement c = (ClickableElement) e;
+            c.click();
+        } catch (ClassCastException exp) {
+            throw new RuntimeException("Element with xpath \"" + xpath
+                    + "\" is not clickable");
+        } catch (IOException exp) {
+            throw new RuntimeException("Click failed");
+        }
+    }
+
     /**
      * Click the indicated button (input type=button).
      * 
@@ -1498,5 +1487,4 @@
                 }
         }
     }
-
 }
\ No newline at end of file

Modified: 
trunk/jwebunit-htmlunit-plugin/src/test/java/net/sourceforge/jwebunit/htmlunit/JWebUnitTest.java
===================================================================
--- 
trunk/jwebunit-htmlunit-plugin/src/test/java/net/sourceforge/jwebunit/htmlunit/JWebUnitTest.java
    2006-05-22 15:26:46 UTC (rev 460)
+++ 
trunk/jwebunit-htmlunit-plugin/src/test/java/net/sourceforge/jwebunit/htmlunit/JWebUnitTest.java
    2006-05-23 08:42:30 UTC (rev 461)
@@ -10,6 +10,7 @@
 /**
  * Test Suite for jWebUnit.
  * 
+ * @author Julien Henry
  * @author Wilkes Joiner
  */
 public class JWebUnitTest extends TestCase {
@@ -42,6 +43,7 @@
         suite.addTestSuite(TestContextTest.class);
         suite.addTestSuite(FormAssertionsTest.class);
         suite.addTestSuite(NavigationTest.class);
+        suite.addTestSuite(XPathTest.class);
         //$JUnit-END$
         return new JettySetup(suite);
     }

Modified: 
trunk/jwebunit-httpunit-plugin/src/main/java/net/sourceforge/jwebunit/httpunit/HttpUnitDialog.java
===================================================================
--- 
trunk/jwebunit-httpunit-plugin/src/main/java/net/sourceforge/jwebunit/httpunit/HttpUnitDialog.java
  2006-05-22 15:26:46 UTC (rev 460)
+++ 
trunk/jwebunit-httpunit-plugin/src/main/java/net/sourceforge/jwebunit/httpunit/HttpUnitDialog.java
  2006-05-23 08:42:30 UTC (rev 461)
@@ -1197,18 +1197,18 @@
      *            <tt>"images/my_icon.png"<tt>, you could just pass in
      *                      <tt>"my_icon.png"<tt>.
      */
-    public void clickLinkWithImage(String imageFileName) {
-        WebLink link = null;
+    public void clickLinkWithImage(String imageFileName, int index) {
+        WebLink[] link = null;
         try {
-            link = resp.getFirstMatchingLink(new LinkImagePredicate(),
+            link = resp.getMatchingLinks(new LinkImagePredicate(),
                     imageFileName);
         } catch (SAXException e) {
             throw new RuntimeException(ExceptionUtility.stackTraceToString(e));
         }
-        if (link == null)
+        if (link == null || link.length<=index)
             throw new RuntimeException("No Link found with imageFileName \""
-                    + imageFileName + "\"");
-        submitRequest(link);
+                    + imageFileName + "\" and index "+index);
+        submitRequest(link[index]);
     }
 
     /**
@@ -1543,15 +1543,20 @@
         return getWebTableBySummaryOrId(tableSummaryOrId).asText();
     }
 
-    /*
-     * (non-Javadoc)
-     * 
-     * @see 
net.sourceforge.jwebunit.IJWebUnitDialog#isElementPresent(java.lang.String)
-     */
     public boolean hasElement(String anID) {
         return getElement(anID) != null;
     }
 
+    public boolean hasElementByXPath(String xpath) {
+        //TODO Implement hasElementByXPath in HttpUnitDialog
+        throw new UnsupportedOperationException("hasElementByXPath");
+    }
+    
+    public void clickElementByXPath(String xpath) {
+        //TODO Implement clickElementByXPath in HttpUnitDialog
+        throw new UnsupportedOperationException("clickElementByXPath");
+    }
+
     /*
      * (non-Javadoc)
      * 

Modified: 
trunk/jwebunit-jacobie-plugin/src/main/java/net/sourceforge/jwebunit/jacobie/JacobieDialog.java
===================================================================
--- 
trunk/jwebunit-jacobie-plugin/src/main/java/net/sourceforge/jwebunit/jacobie/JacobieDialog.java
     2006-05-22 15:26:46 UTC (rev 460)
+++ 
trunk/jwebunit-jacobie-plugin/src/main/java/net/sourceforge/jwebunit/jacobie/JacobieDialog.java
     2006-05-23 08:42:30 UTC (rev 461)
@@ -1390,4 +1390,28 @@
         return false;
     }
 
+    /* (non-Javadoc)
+     * @see 
net.sourceforge.jwebunit.IJWebUnitDialog#clickElementByXPath(java.lang.String)
+     */
+    public void clickElementByXPath(String xpath) {
+        // TODO Auto-generated method stub
+        
+    }
+
+    /* (non-Javadoc)
+     * @see 
net.sourceforge.jwebunit.IJWebUnitDialog#clickLinkWithImage(java.lang.String, 
int)
+     */
+    public void clickLinkWithImage(String imageFileName, int index) {
+        // TODO Auto-generated method stub
+        
+    }
+
+    /* (non-Javadoc)
+     * @see 
net.sourceforge.jwebunit.IJWebUnitDialog#hasElementByXPath(java.lang.String)
+     */
+    public boolean hasElementByXPath(String xpath) {
+        // TODO Auto-generated method stub
+        return false;
+    }
+
 }
\ No newline at end of file

Modified: 
trunk/jwebunit-selenium-plugin/src/main/java/net/sourceforge/jwebunit/selenium/SeleniumDialog.java
===================================================================
--- 
trunk/jwebunit-selenium-plugin/src/main/java/net/sourceforge/jwebunit/selenium/SeleniumDialog.java
  2006-05-22 15:26:46 UTC (rev 460)
+++ 
trunk/jwebunit-selenium-plugin/src/main/java/net/sourceforge/jwebunit/selenium/SeleniumDialog.java
  2006-05-23 08:42:30 UTC (rev 461)
@@ -1301,4 +1301,20 @@
         return null;
     }
 
+    /* (non-Javadoc)
+     * @see 
net.sourceforge.jwebunit.IJWebUnitDialog#clickElementByXPath(java.lang.String)
+     */
+    public void clickElementByXPath(String xpath) {
+        // TODO Auto-generated method stub
+        
+    }
+
+    /* (non-Javadoc)
+     * @see 
net.sourceforge.jwebunit.IJWebUnitDialog#hasElementByXPath(java.lang.String)
+     */
+    public boolean hasElementByXPath(String xpath) {
+        // TODO Auto-generated method stub
+        return false;
+    }
+
 }
\ No newline at end of file

Modified: 
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
    2006-05-22 15:26:46 UTC (rev 460)
+++ 
trunk/jwebunit-selenium-plugin/src/test/java/net/sourceforge/jwebunit/selenium/JWebUnitTest.java
    2006-05-23 08:42:30 UTC (rev 461)
@@ -10,6 +10,7 @@
 /**
  * Test Suite for jWebUnit.
  * 
+ * @author Julien Henry
  * @author Wilkes Joiner
  */
 public class JWebUnitTest extends TestCase {
@@ -42,6 +43,7 @@
         suite.addTestSuite(TestContextTest.class);
         suite.addTestSuite(FormAssertionsTest.class);
         suite.addTestSuite(NavigationTest.class);
+        suite.addTestSuite(XPathTest.class);
         //$JUnit-END$
         return new JettySetup(suite);
     }


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