Revision: 563
          http://svn.sourceforge.net/jwebunit/?rev=563&view=rev
Author:   henryju
Date:     2006-09-15 02:33:11 -0700 (Fri, 15 Sep 2006)

Log Message:
-----------
Add possibility to give absolute URL to beginAt and gotoPage. 
(https://sourceforge.net/tracker/?func=detail&atid=497984&aid=1554148&group_id=61302)

Modified Paths:
--------------
    
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/NavigationTest.java
    trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/WebTester.java
    trunk/src/changes/changes.xml

Modified: 
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/NavigationTest.java
===================================================================
--- 
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/NavigationTest.java
       2006-09-11 08:09:47 UTC (rev 562)
+++ 
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/NavigationTest.java
       2006-09-15 09:33:11 UTC (rev 563)
@@ -28,9 +28,13 @@
                getTestContext().setBaseUrl(HOST_PATH + "/NavigationTest");
        }
 
-       public void testBeginAt() {
+       public void testBeginAtRelative() {
                beginAt("/blah.html");
        }
+    
+    public void testBeginAtAbsolute() {
+        beginAt(HOST_PATH + "/NavigationTest/blah.html");
+    }
 
        public void testForwardSlashConfusion() throws Exception {
                beginAt("/blah.html");
@@ -77,16 +81,6 @@
                assertTitleEquals("pageWithLink");
        }
 
-//     public void testClickLinkWithTextAfterText() {  
-//             beginAt("/pageWithLinkWithTextAfterText.html");
-//             clickLinkWithTextAfterText("link text", "First:");
-//             assertTitleEquals("targetPage");
-//
-//             beginAt("/pageWithLinkWithTextAfterText.html");
-//             clickLinkWithTextAfterText("link text", "Second:");
-//             assertTitleEquals("targetPage2");
-//     }
-
        public void testClickLinkWithImage() {
                beginAt("/pageWithLink.html");
                assertTitleEquals("pageWithLink");
@@ -115,14 +109,21 @@
                fail("Expected exception");
        }
 
-       public void testGotoPage() {
+       public void testGotoPageRelative() {
                beginAt("/targetPage.html");
                assertTitleEquals("targetPage");
                gotoPage("/targetPage2.html");
                assertTitleEquals("targetPage2");
        }
 
-       //For bug 726143
+    public void testGotoPageAbsolute() {
+        beginAt("/targetPage.html");
+        assertTitleEquals("targetPage");
+        gotoPage(HOST_PATH + "/NavigationTest/targetPage2.html");
+        assertTitleEquals("targetPage2");
+    }
+
+    //For bug 726143
        public void testLinkWithEscapedText() {
                beginAt("/pageWithAmpersandInLink.html");
                assertLinkPresentWithText("Map & Directions");

Modified: 
trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/WebTester.java
===================================================================
--- trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/WebTester.java   
2006-09-11 08:09:47 UTC (rev 562)
+++ trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/WebTester.java   
2006-09-15 09:33:11 UTC (rev 563)
@@ -53,7 +53,7 @@
      * to using the orignal testing engine, which is, htmlunit.
      * 
      * @return IJWebUnitDialog instance used to wrapper htmlunit conversation.
-     * @deprecated You should not use plugin specific fonctionality
+     * @deprecated You should not use specific dialog fonctionality (will 
become protected).
      */
     public IJWebUnitDialog getDialog() {
         if (dialog == null) {
@@ -145,22 +145,30 @@
     }
 
     /**
-     * Begin conversation at a url relative to the application root.
+     * Begin conversation at a URL absolute or relative to base URL. Use
+     * [EMAIL PROTECTED] TestContext#setBaseUrl(String) 
getTestContext().setBaseUrl(String)}
+     * to define base URL. Absolute URL should start with "http://";, 
"https://"; or "www.".
      * 
-     * @param relativeURL
+     * @param url
+     *            absolute or relative URL (relative to base URL).
      */
-    public void beginAt(String aRelativeURL) {
+    public void beginAt(String url) {
         try {
-            getDialog().beginAt(createUrl(aRelativeURL), testContext);
+            getDialog().beginAt(createUrl(url), testContext);
         } catch (TestingEngineResponseException 
aTestingEngineResponseException) {
             
handleTestingEngineResponseException(aTestingEngineResponseException);
         }
 
     }
 
-    private String createUrl(String aSuffix) {
-        aSuffix = aSuffix.startsWith("/") ? aSuffix.substring(1) : aSuffix;
-        return getTestContext().getBaseUrl() + aSuffix;
+    private String createUrl(String url) {
+        if (url.startsWith("http://";) || url.startsWith("https://";)
+                || url.startsWith("www.")) {
+            return url;
+        } else {
+            url = url.startsWith("/") ? url.substring(1) : url;
+            return getTestContext().getBaseUrl() + url;
+        }
     }
 
     /**
@@ -299,7 +307,7 @@
      * 
      * @param tableSummaryNameOrId
      * @return Object that represent a html table in a way independent from
-     * plugin.
+     *         plugin.
      */
     public Table getTable(String tableSummaryNameOrId) {
         return getDialog().getTable(tableSummaryNameOrId);
@@ -715,8 +723,8 @@
     }
 
     /**
-     * Assert that a specific form element has an expected value.
-     * Can be used to check hidden input.
+     * Assert that a specific form element has an expected value. Can be used 
to
+     * check hidden input.
      * 
      * @param formElementName
      * @param expectedValue
@@ -760,33 +768,38 @@
     }
 
     /**
-     * Assert that an input text element with name 
<code>formElementName</code> has 
-     * the <code>expectedValue</code> value.
-     *  
+     * Assert that an input text element with name <code>formElementName</code>
+     * has the <code>expectedValue</code> value.
+     * 
      * @param formElementName
      *            the value of the name attribute of the element
      * @param expectedValue
      *            the expected value of the given input element
      */
-    public void assertTextFieldEquals(String formElementName, String 
expectedValue) {
+    public void assertTextFieldEquals(String formElementName,
+            String expectedValue) {
         assertFormElementPresent(formElementName);
-        Assert.assertEquals(expectedValue, 
getDialog().getTextFieldValue(formElementName));
+        Assert.assertEquals(expectedValue, getDialog().getTextFieldValue(
+                formElementName));
     }
-    
+
     /**
-     * Assert that an input hidden element with name 
<code>formElementName</code> has 
-     * the <code>expectedValue</code> value.
-     *  
+     * Assert that an input hidden element with name
+     * <code>formElementName</code> has the <code>expectedValue</code>
+     * value.
+     * 
      * @param formElementName
      *            the value of the name attribute of the element
      * @param expectedValue
      *            the expected value of the given input element
      */
-    public void assertHiddenFieldPresent(String formElementName, String 
expectedValue) {
+    public void assertHiddenFieldPresent(String formElementName,
+            String expectedValue) {
         assertFormElementPresent(formElementName);
-        Assert.assertEquals(expectedValue, 
getDialog().getHiddenFieldValue(formElementName));
+        Assert.assertEquals(expectedValue, getDialog().getHiddenFieldValue(
+                formElementName));
     }
-        
+
     /**
      * Assert that a specific checkbox is selected.
      * 
@@ -897,7 +910,7 @@
      *            option label.
      */
     public void assertSelectOptionPresent(String selectName, String 
optionLabel) {
-        assertSelectOptionsPresent(selectName, new String[] { optionLabel });
+        assertSelectOptionsPresent(selectName, new String[] {optionLabel});
     }
 
     /**
@@ -928,8 +941,7 @@
      */
     public void assertSelectOptionValuePresent(String selectName,
             String optionValue) {
-        assertSelectOptionValuesPresent(selectName,
-                new String[] { optionValue });
+        assertSelectOptionValuesPresent(selectName, new String[] 
{optionValue});
     }
 
     public void assertSelectOptionValueNotPresent(String selectName,
@@ -1054,7 +1066,7 @@
     }
 
     public void assertSelectedOptionEquals(String selectName, String option) {
-        assertSelectedOptionsEqual(selectName, new String[] { option });
+        assertSelectedOptionsEqual(selectName, new String[] {option});
     }
 
     /**
@@ -1086,7 +1098,7 @@
      *            expected value of the selected option.
      */
     public void assertSelectedOptionValueEquals(String selectName, String 
value) {
-        assertSelectedOptionValuesEqual(selectName, new String[] { value });
+        assertSelectedOptionValuesEqual(selectName, new String[] {value});
     }
 
     /**
@@ -1112,7 +1124,7 @@
     }
 
     public void assertSelectedOptionMatches(String selectName, String regexp) {
-        assertSelectedOptionsMatch(selectName, new String[] { regexp });
+        assertSelectedOptionsMatch(selectName, new String[] {regexp});
     }
 
     /**
@@ -1235,7 +1247,8 @@
     }
 
     /**
-     * Assert that a button with a given text is not present in the current 
window.
+     * Assert that a button with a given text is not present in the current
+     * window.
      * 
      * @param text
      */
@@ -1245,14 +1258,16 @@
     }
 
     /**
-     * Assert that a button with a given id is not present in the current 
window.
+     * Assert that a button with a given id is not present in the current
+     * window.
      * 
      * @param buttonId
      */
     public void assertButtonNotPresent(String buttonId) {
         assertFormPresent();
-        Assert.assertFalse("Button [" + buttonId + "] found when not 
expected.", getDialog()
-                .hasButton(buttonId));
+        Assert.assertFalse(
+                "Button [" + buttonId + "] found when not expected.",
+                getDialog().hasButton(buttonId));
     }
 
     /**
@@ -1592,7 +1607,7 @@
                 + cookieName + "\"", re.match(getDialog().getCookieValue(
                 cookieName)));
     }
-    
+
     public void assertJavascriptAlertPresent(String msg) {
         String alert = null;
         try {
@@ -1627,7 +1642,7 @@
         assertFormElementPresent(formElementName);
         return getDialog().getFormParameterValue(formElementName);
     }
-    
+
     /**
      * Begin interaction with a specified form. If form interaction methods are
      * called without explicitly calling this method first, jWebUnit will
@@ -1749,7 +1764,7 @@
      *            label of option to be selected.
      */
     public void selectOption(String selectName, String label) {
-        selectOptions(selectName, new String[] { label });
+        selectOptions(selectName, new String[] {label});
     }
 
     /**
@@ -1774,7 +1789,7 @@
      *            values of options to be selected.
      */
     public void selectOptionByValue(String selectName, String value) {
-        selectOptionsByValues(selectName, new String[] { value });
+        selectOptionsByValues(selectName, new String[] {value});
     }
 
     // Form submission and link navigation methods
@@ -1991,7 +2006,13 @@
     }
 
     /**
-     * Patch sumbitted by Alex Chaffee.
+     * Go to the given page like if user has typed the URL manually in the
+     * browser. Use
+     * [EMAIL PROTECTED] TestContext#setBaseUrl(String) 
getTestContext().setBaseUrl(String)}
+     * to define base URL. Absolute URL should start with "http://";, 
"https://"; or "www.".
+     * 
+     * @param url
+     *            absolute or relative URL (relative to base URL).
      */
     public void gotoPage(String url) {
         try {
@@ -2131,18 +2152,18 @@
      * Exemple: <br/>
      * 
      * <pre>
-     *                 &lt;FORM action=&quot;http://my_host/doit&quot; 
method=&quot;post&quot;&gt;
-     *                   &lt;P&gt;
-     *                     &lt;SELECT multiple size=&quot;4&quot; 
name=&quot;component-select&quot;&gt;
-     *                       &lt;OPTION selected 
value=&quot;Component_1_a&quot;&gt;Component_1&lt;/OPTION&gt;
-     *                       &lt;OPTION selected 
value=&quot;Component_1_b&quot;&gt;Component_2&lt;/OPTION&gt;
-     *                       &lt;OPTION&gt;Component_3&lt;/OPTION&gt;
-     *                       &lt;OPTION&gt;Component_4&lt;/OPTION&gt;
-     *                       &lt;OPTION&gt;Component_5&lt;/OPTION&gt;
-     *                     &lt;/SELECT&gt;
-     *                     &lt;INPUT type=&quot;submit&quot; 
value=&quot;Send&quot;&gt;&lt;INPUT type=&quot;reset&quot;&gt;
-     *                   &lt;/P&gt;
-     *                 &lt;/FORM&gt;
+     *                   &lt;FORM action=&quot;http://my_host/doit&quot; 
method=&quot;post&quot;&gt;
+     *                     &lt;P&gt;
+     *                       &lt;SELECT multiple size=&quot;4&quot; 
name=&quot;component-select&quot;&gt;
+     *                         &lt;OPTION selected 
value=&quot;Component_1_a&quot;&gt;Component_1&lt;/OPTION&gt;
+     *                         &lt;OPTION selected 
value=&quot;Component_1_b&quot;&gt;Component_2&lt;/OPTION&gt;
+     *                         &lt;OPTION&gt;Component_3&lt;/OPTION&gt;
+     *                         &lt;OPTION&gt;Component_4&lt;/OPTION&gt;
+     *                         &lt;OPTION&gt;Component_5&lt;/OPTION&gt;
+     *                       &lt;/SELECT&gt;
+     *                       &lt;INPUT type=&quot;submit&quot; 
value=&quot;Send&quot;&gt;&lt;INPUT type=&quot;reset&quot;&gt;
+     *                     &lt;/P&gt;
+     *                   &lt;/FORM&gt;
      * </pre>
      * 
      * Should return [Component_1, Component_2, Component_3, Component_4,

Modified: trunk/src/changes/changes.xml
===================================================================
--- trunk/src/changes/changes.xml       2006-09-11 08:09:47 UTC (rev 562)
+++ trunk/src/changes/changes.xml       2006-09-15 09:33:11 UTC (rev 563)
@@ -6,6 +6,9 @@
        </properties>
        <body>
        <release version="2.0" date="unknow">
+             <action type="fix" dev="Julien Henry" due-to="Joe Athman" 
issue="1554148">
+                beginAt and gotoPage now accept absolute URL beginning with 
"http://";, "https://"; or "www."
+            </action>
                <action type="add" dev="Julien Henry">
                        Add assertJavascriptAlertPresent method to check 
presence of a Javascript alert.
                </action>


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

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Jwebunit-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jwebunit-development

Reply via email to