Author: hlship
Date: Tue Feb 2 22:09:30 2010
New Revision: 905814
URL: http://svn.apache.org/viewvc?rev=905814&view=rev
Log:
Move some useful methods and contants from TapestryCoreTestCase to
SeleniumTestCase
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/TapestryCoreTestCase.java
tapestry/tapestry5/trunk/tapestry-test/src/main/java/org/apache/tapestry5/test/SeleniumTestCase.java
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/TapestryCoreTestCase.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/TapestryCoreTestCase.java?rev=905814&r1=905813&r2=905814&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/TapestryCoreTestCase.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/TapestryCoreTestCase.java
Tue Feb 2 22:09:30 2010
@@ -18,37 +18,9 @@
public abstract class TapestryCoreTestCase extends SeleniumTestCase
{
- /**
- * 15 seconds
- */
- public static final String PAGE_LOAD_TIMEOUT = "15000";
-
public static final String SUBMIT = "//inp...@type='submit']";
/**
- * Click a link identified by a locator, then wait for the resulting page
to load.
- * This is not useful for Ajax updates, just normal full-page refreshes.
- *
- * @param locator
- * identifies the link to click
- */
- protected final void clickAndWait(String locator)
- {
- click(locator);
-
- waitForPageToLoad();
- }
-
- /**
- * Waits for the page to load (up to 15 seconds). This is invoked after
clicking on an element
- * that forces a full page refresh.
- */
- protected final void waitForPageToLoad()
- {
- waitForPageToLoad(PAGE_LOAD_TIMEOUT);
- }
-
- /**
* Opens the base URL, then clicks through a series of links to get to a
desired application
* state.
*/
@@ -73,39 +45,6 @@
}
}
- /**
- * Used when the locator identifies an attribute, not an element.
- *
- * @param locator
- * identifies the attribute whose value is to be asserted
- * @param expected
- * expected value for the attribute
- */
- protected final void assertAttribute(String locator, String expected)
- {
- String actual = null;
-
- try
- {
- actual = getAttribute(locator);
- }
- catch (RuntimeException ex)
- {
- System.err.printf("Error accessing %s: %s", locator,
ex.getMessage());
-
- writeErrorReport();
-
- throw ex;
- }
-
- if (actual.equals(expected))
- return;
-
- writeErrorReport();
-
- throw new AssertionError(String.format("%s was '%s' not '%s'",
locator, actual, expected));
- }
-
protected final void sleep(long millis)
{
try
@@ -125,20 +64,6 @@
waitForCondition(condition, PAGE_LOAD_TIMEOUT);
}
- protected final void assertFieldValue(String locator, String expected)
- {
- try
- {
- assertEquals(getValue(locator), expected);
- }
- catch (AssertionError ex)
- {
- System.err.printf("%s:\n%s\n\n", ex.getMessage(), getHtmlSource());
-
- throw ex;
- }
- }
-
protected final void waitForElementToAppear(String elementId)
{
Modified:
tapestry/tapestry5/trunk/tapestry-test/src/main/java/org/apache/tapestry5/test/SeleniumTestCase.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-test/src/main/java/org/apache/tapestry5/test/SeleniumTestCase.java?rev=905814&r1=905813&r2=905814&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-test/src/main/java/org/apache/tapestry5/test/SeleniumTestCase.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-test/src/main/java/org/apache/tapestry5/test/SeleniumTestCase.java
Tue Feb 2 22:09:30 2010
@@ -4,7 +4,7 @@
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
-// http://www.apache.org/licenses/LICENSE-2.0
+// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
@@ -27,14 +27,18 @@
/**
* Base class for creating Selenium-based integration test cases. This class
implements all the
- * methods of {...@link Selenium} and delegates to an instance (setup once per
test by
- * {...@link SeleniumLauncher}).
+ * methods of {...@link Selenium} and delegates to an instance (setup once per
test by {...@link SeleniumLauncher}).
*
* @since 5.2.0
*/
public class SeleniumTestCase extends Assert implements Selenium
{
/**
+ * 15 seconds
+ */
+ public static final String PAGE_LOAD_TIMEOUT = "15000";
+
+ /**
* Provided by {...@link SeleniumLauncher}.
*/
private Selenium delegate;
@@ -52,8 +56,7 @@
delegate = (Selenium)
context.getAttribute(TapestryTestConstants.SELENIUM_ATTRIBUTE);
baseURL = (String)
context.getAttribute(TapestryTestConstants.BASE_URL_ATTRIBUTE);
- errorReporter = (ErrorReporter) context
- .getAttribute(TapestryTestConstants.ERROR_REPORTER_ATTRIBUTE);
+ errorReporter = (ErrorReporter)
context.getAttribute(TapestryTestConstants.ERROR_REPORTER_ATTRIBUTE);
}
@AfterClass
@@ -61,6 +64,8 @@
{
delegate = null;
baseURL = null;
+ errorReporter = null;
+ testContext = null;
}
/**
@@ -73,8 +78,8 @@
}
/**
- * Returns the base URL for the application. This is of the typically
- * <code>http://localhost:9999/</code> (i.e., it includes a trailing
slash).
+ * Returns the base URL for the application. This is of the typically
<code>http://localhost:9999/</code> (i.e., it
+ * includes a trailing slash).
*/
public String getBaseURL()
{
@@ -266,8 +271,7 @@
delegate.dragAndDrop(locator, movementsString);
}
- public void dragAndDropToObject(String locatorOfObjectToBeDragged,
- String locatorOfDragDestinationObject)
+ public void dragAndDropToObject(String locatorOfObjectToBeDragged, String
locatorOfDragDestinationObject)
{
delegate.dragAndDropToObject(locatorOfObjectToBeDragged,
locatorOfDragDestinationObject);
}
@@ -487,8 +491,7 @@
return
delegate.getWhetherThisFrameMatchFrameExpression(currentFrameString, target);
}
- public boolean getWhetherThisWindowMatchWindowExpression(String
currentWindowString,
- String target)
+ public boolean getWhetherThisWindowMatchWindowExpression(String
currentWindowString, String target)
{
return
delegate.getWhetherThisWindowMatchWindowExpression(currentWindowString, target);
}
@@ -902,8 +905,7 @@
}
catch (RuntimeException ex)
{
- System.err.printf("Error accessing %s: %s, in:\n\n%s\n\n",
locator, ex.getMessage(),
- getHtmlSource());
+ System.err.printf("Error accessing %s: %s, in:\n\n%s\n\n",
locator, ex.getMessage(), getHtmlSource());
throw ex;
}
@@ -949,4 +951,74 @@
throw new AssertionError("Page did not contain source '" + snippet
+ "'.");
}
}
+
+ /**
+ * Click a link identified by a locator, then wait for the resulting page
to load.
+ * This is not useful for Ajax updates, just normal full-page refreshes.
+ *
+ * @param locator
+ * identifies the link to click
+ */
+ protected final void clickAndWait(String locator)
+ {
+ click(locator);
+
+ waitForPageToLoad();
+ }
+
+ /**
+ * Waits for the page to load (up to 15 seconds). This is invoked after
clicking on an element
+ * that forces a full page refresh.
+ */
+ protected final void waitForPageToLoad()
+ {
+ waitForPageToLoad(PAGE_LOAD_TIMEOUT);
+ }
+
+ /**
+ * Used when the locator identifies an attribute, not an element.
+ *
+ * @param locator
+ * identifies the attribute whose value is to be asserted
+ * @param expected
+ * expected value for the attribute
+ */
+ protected final void assertAttribute(String locator, String expected)
+ {
+ String actual = null;
+
+ try
+ {
+ actual = getAttribute(locator);
+ }
+ catch (RuntimeException ex)
+ {
+ System.err.printf("Error accessing %s: %s", locator,
ex.getMessage());
+
+ writeErrorReport();
+
+ throw ex;
+ }
+
+ if (actual.equals(expected))
+ return;
+
+ writeErrorReport();
+
+ throw new AssertionError(String.format("%s was '%s' not '%s'",
locator, actual, expected));
+ }
+
+ protected final void assertFieldValue(String locator, String expected)
+ {
+ try
+ {
+ assertEquals(getValue(locator), expected);
+ }
+ catch (AssertionError ex)
+ {
+ System.err.printf("%s:\n%s\n\n", ex.getMessage(), getHtmlSource());
+
+ throw ex;
+ }
+ }
}