Author: lfryc(a)redhat.com
Date: 2010-07-10 17:07:49 -0400 (Sat, 10 Jul 2010)
New Revision: 17898
Added:
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/richfaces/tests/testapp/a4jPoll/
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/richfaces/tests/testapp/a4jPoll/PollTestCase.java
Log:
added PollTestCase
Added:
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/richfaces/tests/testapp/a4jPoll/PollTestCase.java
===================================================================
---
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/richfaces/tests/testapp/a4jPoll/PollTestCase.java
(rev 0)
+++
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/richfaces/tests/testapp/a4jPoll/PollTestCase.java 2010-07-10
21:07:49 UTC (rev 17898)
@@ -0,0 +1,93 @@
+/*******************************************************************************
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ *******************************************************************************/
+package org.richfaces.tests.testapp.a4jPoll;
+
+import java.net.URL;
+
+import org.jboss.test.selenium.dom.Event;
+import org.jboss.test.selenium.locator.ElementLocator;
+import org.jboss.test.selenium.locator.JQueryLocator;
+import org.richfaces.tests.testapp.AbstractTestappTestCase;
+import org.testng.annotations.Test;
+
+import static org.jboss.test.selenium.utils.URLUtils.buildUrl;
+import static org.jboss.test.selenium.locator.LocatorFactory.*;
+import static org.testng.Assert.*;
+import static org.jboss.test.selenium.guard.request.RequestTypeGuardFactory.*;
+import static org.jboss.test.selenium.SystemProperties.isSeleniumDebug;
+
+/**
+ * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
+ * @version $Revision$
+ */
+public class PollTestCase extends AbstractTestappTestCase {
+
+ ElementLocator attributeEnabled = id("form:attributes:enabledInput");
+ ElementLocator attributeInterval = id("form:attributes:intervalInput");
+ JQueryLocator time = pjq("span[id$=time]");
+
+ @Override
+ public URL getTestUrl() {
+ return buildUrl(contextPath, "faces/components/a4jPoll/simple.xhtml");
+ }
+
+ @Test(groups = "client-side-perf")
+ public void testPollInterval() {
+
+ long total = 0;
+ long count = 0;
+ for (int interval : new Integer[]{1000, 5000, 500}) {
+ selenium.type(attributeInterval, String.valueOf(interval));
+ waitHttp(selenium).fireEvent(attributeInterval, Event.BLUR);
+
+ selenium.check(attributeEnabled);
+ waitHttp(selenium).fireEvent(attributeEnabled, Event.CHANGE);
+
+ selenium.getPageExtensions().install();
+
+ for (int i = 0; i <= 5; i++) {
+ long time = System.currentTimeMillis();
+ selenium.getRequestInterceptor().clearRequestTypeDone();
+ selenium.getRequestInterceptor().waitForRequestTypeChange();
+ time -= System.currentTimeMillis();
+ if (i > 0) {
+ if (isSeleniumDebug()) {
+ System.out.println(time);
+ }
+ total += Math.abs(interval - Math.abs(time));
+ count += 1;
+ }
+ }
+
+ selenium.uncheck(attributeEnabled);
+ guardHttp(selenium).fireEvent(attributeEnabled, Event.CHANGE);
+ }
+
+ if (isSeleniumDebug()) {
+ System.out.println(total / count);
+ }
+ // asserts that average deviation is not greater than 100
+ assertTrue((total / count) <= 100);
+
+ }
+
+}