Hi Francois
I googled about waitFor... methods and found this
http://agilesoftwaretesting.com/?p=111
The waitFor methods get messed up as the page that three zones which were
refreshing. So, I created two separate tests
also i replaced the checkZoneValues() method to
private void checkZoneValues(String zone, int times) throws Exception
{
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));
}
}
It first waits for a ajax call to begin and then waits for it to end and
then checks the value. So it will be good enough for even a slow server (20
seconds wait)
Thanks Igor for pointing it out and very very thanks Francois for adding
this patch
regards
Taha
2011/7/2 françois facon <[email protected]>
> Thanks for your advise Igor.
> I will change that test.
> Regards
> François
>
> 2011/7/2 Igor Drobiazko <[email protected]>:
> > It's highly likely that this wait condition will break the build once the
> > build machine is busy. You should make use of Selenium's wait conditions.
> > Check out the wait methods like waitForElementToAppear, etc.
> >
> > On Sat, Jul 2, 2011 at 12:14 PM, <[email protected]> wrote:
> >>
> >> +
> >> +
> >> + private void checkZoneValues(String zone, int times) throws
> Exception
> >> + {
> >> + Thread.sleep(300);
> >> + for(int i = 0; i < times; ++i)
> >> + {
> >> + assertText(zone, String.valueOf(i));
> >> + Thread.sleep(1000);
> >> + }
> >> + }
> >> +
> >> +}
> >
> >
> >
> > --
> > Best regards,
> >
> > Igor Drobiazko
> > http://tapestry5.de
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>
Index: src/test/app1/ZoneRefreshWithHandlerReturningVoid.tml
===================================================================
--- src/test/app1/ZoneRefreshWithHandlerReturningVoid.tml (revision 1142235)
+++ src/test/app1/ZoneRefreshWithHandlerReturningVoid.tml (working copy)
@@ -1,20 +1,12 @@
<html xmlns:t='http://tapestry.apache.org/schema/tapestry_5_1_0.xsd'>
<head>
</head>
-
+
<body>
- Counter 1:
- <span t:type='zone' t:mixins='zonerefresh' t:period='1' id='zone' t:id='zone'>
+ Using zone with event handler returning void :
+ <span t:type='zone' t:mixins='zonerefresh' t:period='2' id='zone' t:id='zone'>
${counter}
</span>
-
- <br />
- Counter 2 :
- <span t:type='zone' t:mixins='zonerefresh' t:period='1' t:id='zone2' id='zone2'>${counter2}</span>
- <br />
- Counter 3 :
- <span t:type='zone' t:mixins='zonerefresh' t:period='1' t:id='zone3' id='zone3'>${counter3}</span>
- and
- <span t:type='zone' t:id='zone4' id='zone4'>${counter3}</span>
</body>
+
</html>
\ No newline at end of file
Index: src/test/app1/ZoneRefreshWithHandlerReturningZone.tml
===================================================================
--- src/test/app1/ZoneRefreshWithHandlerReturningZone.tml (revision 0)
+++ src/test/app1/ZoneRefreshWithHandlerReturningZone.tml (revision 0)
@@ -0,0 +1,15 @@
+<html xmlns:t='http://tapestry.apache.org/schema/tapestry_5_1_0.xsd'>
+ <head>
+ </head>
+
+ <body>
+ Using zone with event handler returning zone :
+ <span t:type='zone' t:mixins='zonerefresh' t:period='2' id='zone' t:id='zone'>
+ ${counter}
+ </span>
+ <br />
+ <span t:type='zone' id='zone2' t:id='zone2'>
+ and another zone ${counter}
+ </span>
+ </body>
+</html>
\ No newline at end of file
Index: src/test/app1/Index.tml
===================================================================
--- src/test/app1/Index.tml (revision 1142235)
+++ src/test/app1/Index.tml (working copy)
@@ -130,9 +130,13 @@
-- error reporting for adding a duplicate mixin to a component
</li>
<li>
- <a href="ZoneRefreshDemo">Zone Refresh Demo</a>
- -- refreshes zone after 5 seconds
+ <a href="ZoneRefreshWithHandlerReturningVoid">Zone Refresh With Event Handler Returning Void</a>
+ -- refreshes zone with an event handler returning void
</li>
+ <li>
+ <a href="ZoneRefreshWithHandlerReturningZone">Zone Refresh With Event Handler Returning Zone</a>
+ -- refreshes zone with an event handler returning zone
+ </li>
<li>
<a href="UnsupportedParameterBlockDemo">Unsupported Parameter Block Demo</a>
-- informal block parameter to a component that does not support informal parameters
Index: src/test/app1/ZoneRefreshDemo.tml
===================================================================
--- src/test/app1/ZoneRefreshDemo.tml (revision 1142235)
+++ src/test/app1/ZoneRefreshDemo.tml (working copy)
@@ -1,20 +0,0 @@
-<html xmlns:t='http://tapestry.apache.org/schema/tapestry_5_1_0.xsd'>
- <head>
- </head>
-
- <body>
- Counter 1:
- <span t:type='zone' t:mixins='zonerefresh' t:period='1' id='zone' t:id='zone'>
- ${counter}
- </span>
-
- <br />
- Counter 2 :
- <span t:type='zone' t:mixins='zonerefresh' t:period='1' t:id='zone2' id='zone2'>${counter2}</span>
- <br />
- Counter 3 :
- <span t:type='zone' t:mixins='zonerefresh' t:period='1' t:id='zone3' id='zone3'>${counter3}</span>
- and
- <span t:type='zone' t:id='zone4' id='zone4'>${counter3}</span>
- </body>
-</html>
\ No newline at end of file
Index: src/test/java/org/apache/tapestry5/integration/app1/pages/CopyOfZoneRefreshWithHandlerReturningVoid.java
===================================================================
--- src/test/java/org/apache/tapestry5/integration/app1/pages/CopyOfZoneRefreshWithHandlerReturningVoid.java (revision 0)
+++ src/test/java/org/apache/tapestry5/integration/app1/pages/CopyOfZoneRefreshWithHandlerReturningVoid.java (revision 0)
@@ -0,0 +1,46 @@
+// Copyright 2011 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.pages;
+
+import org.apache.tapestry5.ajax.MultiZoneUpdate;
+import org.apache.tapestry5.annotations.InjectComponent;
+import org.apache.tapestry5.annotations.Persist;
+import org.apache.tapestry5.annotations.Property;
+import org.apache.tapestry5.corelib.components.Zone;
+
+public class CopyOfZoneRefreshWithHandlerReturningVoid
+{
+ @Persist
+ @Property
+ private int counter;
+
+ @InjectComponent
+ private Zone zone;
+
+ @InjectComponent
+ private Zone zone2;
+
+
+ void setupRender()
+ {
+ counter = 0;
+ }
+
+ Object onRefreshFromZone(){
+ counter++;
+ return new MultiZoneUpdate(zone).add(zone2);
+ }
+
+}
+
Index: src/test/java/org/apache/tapestry5/integration/app1/pages/ZoneRefreshDemo.java
===================================================================
--- src/test/java/org/apache/tapestry5/integration/app1/pages/ZoneRefreshDemo.java (revision 1142235)
+++ src/test/java/org/apache/tapestry5/integration/app1/pages/ZoneRefreshDemo.java (working copy)
@@ -1,69 +0,0 @@
-// Copyright 2011 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.pages;
-
-import org.apache.tapestry5.ajax.MultiZoneUpdate;
-import org.apache.tapestry5.annotations.InjectComponent;
-import org.apache.tapestry5.annotations.Persist;
-import org.apache.tapestry5.annotations.Property;
-import org.apache.tapestry5.corelib.components.Zone;
-
-public class ZoneRefreshDemo
-{
- @Persist
- @Property
- private int counter;
-
- @Persist
- @Property
- private int counter2;
-
- @Persist
- @Property
- private int counter3;
-
- @InjectComponent
- private Zone zone2;
-
- @InjectComponent
- private Zone zone3;
-
- @InjectComponent
- private Zone zone4;
-
- void setupRender()
- {
- counter = 0;
- counter2 = 0;
- counter3 = 0;
- }
-
- void onRefreshFromZone()
- {
- counter++;
- }
-
- Zone onRefreshFromZone2()
- {
- counter2++;
- return zone2;
- }
-
- Object onRefreshFromZone3(){
- counter3++;
- return new MultiZoneUpdate(zone3).add(zone4);
- }
-
-}
-
Index: src/test/java/org/apache/tapestry5/integration/app1/pages/ZoneRefreshWithHandlerReturningVoid.java
===================================================================
--- src/test/java/org/apache/tapestry5/integration/app1/pages/ZoneRefreshWithHandlerReturningVoid.java (revision 0)
+++ src/test/java/org/apache/tapestry5/integration/app1/pages/ZoneRefreshWithHandlerReturningVoid.java (revision 0)
@@ -0,0 +1,35 @@
+// Copyright 2011 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.pages;
+
+import org.apache.tapestry5.annotations.Persist;
+import org.apache.tapestry5.annotations.Property;
+
+public class ZoneRefreshWithHandlerReturningVoid
+{
+ @Persist
+ @Property
+ private int counter;
+
+ void setupRender()
+ {
+ counter = 0;
+ }
+
+ void onRefreshFromZone(){
+ counter++;
+ }
+
+}
+
Index: src/test/java/org/apache/tapestry5/integration/app1/pages/ZoneRefreshWithHandlerReturningZone.java
===================================================================
--- src/test/java/org/apache/tapestry5/integration/app1/pages/ZoneRefreshWithHandlerReturningZone.java (revision 1142235)
+++ src/test/java/org/apache/tapestry5/integration/app1/pages/ZoneRefreshWithHandlerReturningZone.java (working copy)
@@ -19,51 +19,27 @@
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.corelib.components.Zone;
-public class ZoneRefreshDemo
+public class ZoneRefreshWithHandlerReturningZone
{
@Persist
@Property
private int counter;
- @Persist
- @Property
- private int counter2;
+ @InjectComponent
+ private Zone zone;
- @Persist
- @Property
- private int counter3;
-
@InjectComponent
private Zone zone2;
+
- @InjectComponent
- private Zone zone3;
-
- @InjectComponent
- private Zone zone4;
-
void setupRender()
{
counter = 0;
- counter2 = 0;
- counter3 = 0;
}
- void onRefreshFromZone()
- {
+ Object onRefreshFromZone(){
counter++;
+ return new MultiZoneUpdate(zone).add(zone2);
}
-
- Zone onRefreshFromZone2()
- {
- counter2++;
- return zone2;
- }
-
- Object onRefreshFromZone3(){
- counter3++;
- return new MultiZoneUpdate(zone3).add(zone4);
- }
}
-
Index: src/test/java/org/apache/tapestry5/integration/app1/ZoneRefreshTest.java
===================================================================
--- src/test/java/org/apache/tapestry5/integration/app1/ZoneRefreshTest.java (revision 1142235)
+++ src/test/java/org/apache/tapestry5/integration/app1/ZoneRefreshTest.java (working copy)
@@ -20,37 +20,33 @@
public class ZoneRefreshTest extends SeleniumTestCase
{
@Test
- public void test_if_zone_with_void_event_handler_works() throws Exception
+ public void test_if_zone_with_event_handler_returning_void_works() throws Exception
{
openBaseURL();
- clickAndWait("link=Zone Refresh Demo");
+ clickAndWait("link=Zone Refresh With Event Handler Returning Void");
checkZoneValues("zone", 3);
}
-
+
@Test
- public void test_if_zone_with_single_zone_event_handler_works() throws Exception
+ public void test_if_zone_with_event_handler_returning_zone_works() throws Exception
{
openBaseURL();
- clickAndWait("link=Zone Refresh Demo");
- checkZoneValues("zone2", 3);
+ clickAndWait("link=Zone Refresh With Event Handler Returning Zone");
+ checkZoneValues("zone", 3);
}
-
- @Test
- public void test_if_zone_with_multiple_zone_event_handler_works() throws Exception
- {
- openBaseURL();
- clickAndWait("link=Zone Refresh Demo");
- checkZoneValues("zone4", 3);
- }
-
private void checkZoneValues(String zone, int times) throws Exception
{
- Thread.sleep(300);
- for(int i = 0; i < times; ++i)
+ 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));
- Thread.sleep(1000);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]