// Copyright 2011, 2012 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// 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
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package org.apache.tapestry5.integration.app1;

import org.apache.tapestry5.test.SeleniumTestCase;
import org.testng.annotations.Test;

public class ZoneRefreshTest extends SeleniumTestCase
{
    @Test
    public void test_if_zone_with_event_handler_returning_void_works() throws Exception
    {
        openBaseURL();

        waitForPageInitialized();

        clickAndWait("link=Zone Refresh With Event Handler Returning Void");

        checkZoneValues("zone", 3);
    }

    @Test
    public void test_if_zone_with_event_handler_returning_zone_works() throws Exception
    {
        openBaseURL();

        waitForPageInitialized();

        clickAndWait("link=Zone Refresh With Event Handler Returning Zone");

        checkZoneValues("zone", 3);
    }

    private void checkZoneValues(String zone, int times) throws Exception
    {
        // Wait until Prototype is loaded ...
        waitForCondition("selenium.browserbot.getCurrentWindow().Ajax", "20000");

        for (int i = 1; i <= times; ++i)
        {
            // Wait for ajax call to begin
            waitForCondition("selenium.browserbot.getCurrentWindow().Ajax.activeRequestCount != 0", "20000");

            // Wait for ajax call from end
            waitForCondition("selenium.browserbot.getCurrentWindow().Ajax.activeRequestCount == 0", "20000");

            // Check the value changed
            assertText(zone, String.valueOf(i));
        }
    }

}

@@ -799,16 +799,59 @@
 tCase%0A%7B%0A
+%0A    private static final int WAIT = 250;%0A%0A
     @Tes
@@ -1079,24 +1079,46 @@
 ng Void%22);%0A%0A
+        sleep(WAIT);%0A%0A
         chec
@@ -1303,32 +1303,32 @@
 Initialized();%0A%0A
-
         clickAnd
@@ -1385,24 +1385,46 @@
 ng Zone%22);%0A%0A
+        sleep(WAIT);%0A%0A
         chec

Add some sleeps, hoping to make it work correctly