tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject git commit: Set a flag on the HTML element when page initializations complete Add a method to TapestryCoreTestCase to wait for the flag to be set
Date Thu, 29 Nov 2012 19:17:54 GMT
Updated Branches:
  refs/heads/5.4-js-rewrite 04e0d898f -> 8c95676fc


Set a flag on the HTML element when page initializations complete
Add a method to TapestryCoreTestCase to wait for the flag to be set


Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/8c95676f
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/8c95676f
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/8c95676f

Branch: refs/heads/5.4-js-rewrite
Commit: 8c95676fcdddfd74252c376385d0ed61ea9512f1
Parents: 04e0d89
Author: Howard M. Lewis Ship <hlship@apache.org>
Authored: Thu Nov 29 11:17:42 2012 -0800
Committer: Howard M. Lewis Ship <hlship@apache.org>
Committed: Thu Nov 29 11:17:42 2012 -0800

----------------------------------------------------------------------
 .../META-INF/modules/core/pageinit.coffee          |    9 ++++-
 .../app1/SubmitUnconditionalTests.groovy           |    4 +-
 .../integration/TapestryCoreTestCase.java          |   28 +++++++++++---
 .../tapestry5/integration/app1/ZoneTests.java      |    8 ++--
 .../apache/tapestry5/test/SeleniumTestCase.java    |   13 ++++++-
 5 files changed, 47 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/8c95676f/tapestry-core/src/main/coffeescript/META-INF/modules/core/pageinit.coffee
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/coffeescript/META-INF/modules/core/pageinit.coffee b/tapestry-core/src/main/coffeescript/META-INF/modules/core/pageinit.coffee
index 6650a78..c71c807 100644
--- a/tapestry-core/src/main/coffeescript/META-INF/modules/core/pageinit.coffee
+++ b/tapestry-core/src/main/coffeescript/META-INF/modules/core/pageinit.coffee
@@ -152,7 +152,14 @@ define ["_", "core/console", "core/dom", "core/events"],
       # executed), and then executes the other initializations.
       loadLibrariesAndInitialize: (libraries, inits) ->
         console.debug "Loading #{libraries?.length or 0} libraries"
-        exports.loadLibraries libraries, -> exports.initialize inits
+        exports.loadLibraries libraries,
+          -> exports.initialize inits,
+            ->
+              # At this point, all libraries have been loaded, and all inits should have
executed. Unless some of
+              # the inits triggered Ajax updates (such as a core/ProgressiveDisplay component),
then the page should
+              # be ready to go. We set a flag, mostly used by test suites, to ensure that
all is ready.
+
+              (dom document.documentElement).attribute "data-page-loaded", "true"
 
       evalJavaScript: (js) ->
         console.debug "Evaluating: #{js}"

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/8c95676f/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/SubmitUnconditionalTests.groovy
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/SubmitUnconditionalTests.groovy
b/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/SubmitUnconditionalTests.groovy
index 13c13d7..5f6bbaa 100644
--- a/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/SubmitUnconditionalTests.groovy
+++ b/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/SubmitUnconditionalTests.groovy
@@ -10,7 +10,7 @@ class SubmitUnconditionalTests extends TapestryCoreTestCase {
     void submit_with_unconditional_mode() {
         openLinks "Cancel Demo"
 
-        sleep SETUP_TIME
+        waitForPageLoaded()
 
         clickAndWait "//input[@value='Abort']"
 
@@ -22,7 +22,7 @@ class SubmitUnconditionalTests extends TapestryCoreTestCase {
 
         openLinks "Cancel Demo"
 
-        sleep SETUP_TIME
+        waitForPageLoaded()
 
         clickAndWait "link=Abort"
 

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/8c95676f/tapestry-core/src/test/java/org/apache/tapestry5/integration/TapestryCoreTestCase.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/integration/TapestryCoreTestCase.java
b/tapestry-core/src/test/java/org/apache/tapestry5/integration/TapestryCoreTestCase.java
index 96058ae..a8f85b9 100644
--- a/tapestry-core/src/test/java/org/apache/tapestry5/integration/TapestryCoreTestCase.java
+++ b/tapestry-core/src/test/java/org/apache/tapestry5/integration/TapestryCoreTestCase.java
@@ -23,12 +23,6 @@ public abstract class TapestryCoreTestCase extends SeleniumTestCase
     public static final String EXCEPTION_PROCESSING_REQUEST = "An exception has occurred
processing this request.";
     public static final String TEST_APP_BANNER = "Tapestry Integration Test Application";
 
-    /**
-     * Number of milliseconds to sleep after the page has loaded, when giving JavaScript
a chance to fully initialize.
-     * Perhaps we need another option, say one that sets a flag on the HTML element once
the initializations are complete.
-     */
-    public static final int SETUP_TIME = 100;
-
     protected final void assertTextSeries(String idFormat, int startIndex, String... values)
     {
         for (int i = 0; i < values.length; i++)
@@ -63,6 +57,7 @@ public abstract class TapestryCoreTestCase extends SeleniumTestCase
      * and the alert itself to appear.
      *
      * @param text
+     * @since 5.4
      */
     protected final void assertFirstAlert(String text)
     {
@@ -71,4 +66,25 @@ public abstract class TapestryCoreTestCase extends SeleniumTestCase
         // Add the special "x" for the close button to the text.
         assertText("css=[data-container-type=alerts] .alert", "\u00d7" + text);
     }
+
+    /**
+     * Waits for page initialization to finish, which is recognized by the {@code data-page-loaded}
attribute
+     * being added to the HTML element. Polls at 20ms intervals for 200ms.
+     *
+     * @since 5.4
+     */
+    protected final void waitForPageLoaded()
+    {
+        for (int i = 0; i < 10; i++)
+        {
+            if (isElementPresent("css=html[data-page-loaded]"))
+            {
+                return;
+            }
+
+            sleep(20);
+        }
+
+        reportAndThrowAssertionError("Page did not finish loading.");
+    }
 }

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/8c95676f/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/ZoneTests.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/ZoneTests.java
b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/ZoneTests.java
index d1bad25..deec281 100644
--- a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/ZoneTests.java
+++ b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/ZoneTests.java
@@ -32,7 +32,7 @@ public class ZoneTests extends TapestryCoreTestCase
     {
         openLinks("Select Zone Demo");
 
-        sleep(SETUP_TIME);
+        waitForPageLoaded();
 
         select("carMaker", "Bmw");
 
@@ -302,11 +302,11 @@ public class ZoneTests extends TapestryCoreTestCase
     {
         openLinks("Zone Demo");
 
-        sleep(SETUP_TIME);
+        waitForPageLoaded();
 
         click("link=Select \"CSS Injection\"");
 
-        sleep(SETUP_TIME);
+        waitForPageLoaded();
 
         // First check that the update arrived
 
@@ -318,7 +318,7 @@ public class ZoneTests extends TapestryCoreTestCase
         assertCSS("demo-aip", "color", "rgb(0, 128, 0)");
         assertCSS("demo-aip", "text-decoration", "underline");
     }
-    
+
     /**
      * TAP5-1890
      */

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/8c95676f/tapestry-test/src/main/java/org/apache/tapestry5/test/SeleniumTestCase.java
----------------------------------------------------------------------
diff --git a/tapestry-test/src/main/java/org/apache/tapestry5/test/SeleniumTestCase.java b/tapestry-test/src/main/java/org/apache/tapestry5/test/SeleniumTestCase.java
index 98ad5f8..850b46d 100644
--- a/tapestry-test/src/main/java/org/apache/tapestry5/test/SeleniumTestCase.java
+++ b/tapestry-test/src/main/java/org/apache/tapestry5/test/SeleniumTestCase.java
@@ -1161,7 +1161,15 @@ public abstract class SeleniumTestCase extends Assert implements Selenium
     // End of delegate methods
     // ---------------------------------------------------------------------
 
-    private final void reportAndThrowAssertionError(String message, Object... arguments)
+    /**
+     * Formats a message from the provided arguments, which is written to System.err. In
addition,
+     * captures the AUT's markup, screenshot, and a report to the output directory.
+     *
+     * @param message
+     * @param arguments
+     * @since 5.4
+     */
+    protected final void reportAndThrowAssertionError(String message, Object... arguments)
     {
         StringBuilder builder = new StringBuilder(5000);
 
@@ -1476,11 +1484,12 @@ public abstract class SeleniumTestCase extends Assert implements Selenium
     }
 
     /**
-     * Waits until all active XHR requests are completed.
+     * Waits until all active XHR requests are completed. However, this is Prototype-based.
      *
      * @param timeout
      *         timeout to wait for
      * @since 5.3
+     * @deprecated Deprecated in 5.4 as it is tied to Prototype.
      */
     protected final void waitForAjaxRequestsToComplete(String timeout)
     {


Mime
View raw message