Author: andrei_exadel
Date: 2008-04-28 10:02:27 -0400 (Mon, 28 Apr 2008)
New Revision: 8236
Added:
trunk/test-applications/seleniumTest/src/main/java/org/ajax4jsf/A4JPollTestBean.java
trunk/test-applications/seleniumTest/src/main/webapp/pages/ajaxPoll/
trunk/test-applications/seleniumTest/src/main/webapp/pages/ajaxPoll/ajaxPollTest.xhtml
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/AjaxPollTest.java
Modified:
trunk/test-applications/seleniumTest/src/main/webapp/WEB-INF/faces-config.xml
trunk/test-applications/seleniumTest/src/test/java/org/ajax4jsf/test/base/SeleniumTestBase.java
Log:
Ajax Poll Test
Added:
trunk/test-applications/seleniumTest/src/main/java/org/ajax4jsf/A4JPollTestBean.java
===================================================================
--- trunk/test-applications/seleniumTest/src/main/java/org/ajax4jsf/A4JPollTestBean.java
(rev 0)
+++
trunk/test-applications/seleniumTest/src/main/java/org/ajax4jsf/A4JPollTestBean.java 2008-04-28
14:02:27 UTC (rev 8236)
@@ -0,0 +1,54 @@
+package org.ajax4jsf;
+
+import javax.faces.event.ActionEvent;
+
+public class A4JPollTestBean {
+
+ private Integer i = 1;
+
+ private static final String POLLING = "Polling";
+
+ private boolean enabled = true;
+
+ public void listener(ActionEvent event) {
+ i++;
+ if (i == 7) {
+ enabled = false;
+ }
+ }
+
+ public String getText() {
+ return POLLING.substring(0, i);
+ }
+
+ /**
+ * @return the i
+ */
+ public Integer getI() {
+ return i;
+ }
+
+ /**
+ * @param i the i to set
+ */
+ public void setI(Integer i) {
+ this.i = i;
+ }
+
+ /**
+ * @return the enabled
+ */
+ public boolean isEnabled() {
+ return enabled;
+ }
+
+ /**
+ * @param enabled the enabled to set
+ */
+ public void setEnabled(boolean enabled) {
+ this.enabled = enabled;
+ }
+
+
+
+}
Modified: trunk/test-applications/seleniumTest/src/main/webapp/WEB-INF/faces-config.xml
===================================================================
---
trunk/test-applications/seleniumTest/src/main/webapp/WEB-INF/faces-config.xml 2008-04-28
13:45:32 UTC (rev 8235)
+++
trunk/test-applications/seleniumTest/src/main/webapp/WEB-INF/faces-config.xml 2008-04-28
14:02:27 UTC (rev 8236)
@@ -51,5 +51,10 @@
<managed-bean-name>statusBean</managed-bean-name>
<managed-bean-class>org.ajax4jsf.A4JStatusTestBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
+ </managed-bean>
+ <managed-bean>
+ <managed-bean-name>pollBean</managed-bean-name>
+ <managed-bean-class>org.ajax4jsf.A4JPollTestBean</managed-bean-class>
+ <managed-bean-scope>request</managed-bean-scope>
</managed-bean>
</faces-config>
\ No newline at end of file
Added:
trunk/test-applications/seleniumTest/src/main/webapp/pages/ajaxPoll/ajaxPollTest.xhtml
===================================================================
---
trunk/test-applications/seleniumTest/src/main/webapp/pages/ajaxPoll/ajaxPollTest.xhtml
(rev 0)
+++
trunk/test-applications/seleniumTest/src/main/webapp/pages/ajaxPoll/ajaxPollTest.xhtml 2008-04-28
14:02:27 UTC (rev 8236)
@@ -0,0 +1,18 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html
xmlns="http://www.w3.org/1999/xhtml"
+
xmlns:a4j="http://richfaces.org/a4j"
+
xmlns:rich="http://richfaces.org/rich"
+
xmlns:h="http://java.sun.com/jsf/html"
+
xmlns:f="http://java.sun.com/jsf/core"
+
xmlns:ui="http://java.sun.com/jsf/facelets">
+
+<ui:composition template="#{templateBean.template}">
+ <ui:define name="component">
+ <h:form id="_form">
+ <a4j:poll interval="700" id="poll"
enabled="#{pollBean.enabled}" actionListener="#{pollBean.listener}"
reRender="_value, _text"></a4j:poll><br/>
+ <h:inputHidden id="_value" value="#{pollBean.i}"/>
+ <h:outputText id="_text" value="#{pollBean.text}" />
+ </h:form>
+ </ui:define>
+</ui:composition>
+</html>
\ No newline at end of file
Modified:
trunk/test-applications/seleniumTest/src/test/java/org/ajax4jsf/test/base/SeleniumTestBase.java
===================================================================
---
trunk/test-applications/seleniumTest/src/test/java/org/ajax4jsf/test/base/SeleniumTestBase.java 2008-04-28
13:45:32 UTC (rev 8235)
+++
trunk/test-applications/seleniumTest/src/test/java/org/ajax4jsf/test/base/SeleniumTestBase.java 2008-04-28
14:02:27 UTC (rev 8236)
@@ -227,7 +227,6 @@
public void waitForAjaxCompletion() {
waitForAjaxCompletion(ajaxCompletionTime);
}
-
/**
* Waits while simple request will be completed
@@ -240,6 +239,16 @@
}
/**
+ * Waits for condition
+ * @param condition
+ * @param miliseconds
+ */
+ public void waiteForCondition(String condition, int miliseconds) {
+ selenium.waitForCondition(WINDOW_JS_RESOLVER + condition,
String.valueOf(miliseconds));
+ checkJSError();
+ }
+
+ /**
* Waits while simple request will be completed
*
*/
Added: trunk/test-applications/seleniumTest/src/test/java/org/richfaces/AjaxPollTest.java
===================================================================
--- trunk/test-applications/seleniumTest/src/test/java/org/richfaces/AjaxPollTest.java
(rev 0)
+++
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/AjaxPollTest.java 2008-04-28
14:02:27 UTC (rev 8236)
@@ -0,0 +1,75 @@
+/**
+ *
+ */
+package org.richfaces;
+
+import org.ajax4jsf.test.base.RichSeleniumTest;
+import org.ajax4jsf.test.base.SeleniumTestBase;
+import org.ajax4jsf.test.base.Templates;
+import org.testng.annotations.AfterTest;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Parameters;
+import org.testng.annotations.Test;
+
+/**
+ * @author Andrey Markavstov
+ *
+ */
+public class AjaxPollTest extends SeleniumTestBase implements RichSeleniumTest {
+
+ public AjaxPollTest() {
+ super("http", "localhost", "8080");
+ }
+
+ /**
+ * This method are invoking before selenium tests started
+ */
+ @BeforeTest
+ @Parameters( { "browser" })
+ public void startSelenium(String browser) {
+ super.startSelenium(browser);
+ }
+
+ /**
+ * This method are invoking after selenium tests completed
+ */
+ @AfterTest
+ public void stopSelenium() {
+ super.stopSelenium();
+ }
+
+ @Test
+ public void testAjaxPollComponent() {
+ _testAjaxPollComponent(Templates.SIMPLE);
+ _testAjaxPollComponent(Templates.DATATABLE);
+ }
+
+ private void _testAjaxPollComponent(Templates template) {
+ renderPage(getTestUrl(), template);
+ String parentId = getParentId() + "_form:";
+ String pollId = parentId + "poll";
+ String inputId = parentId + "_value";
+
+ writeStatus("Polling in progress...");
+ AssertValueEquals(inputId, "1");
+ pause(1500, pollId);
+ AssertValueNotEquals(inputId, "1");
+ waiteForCondition("document.getElementById('"+inputId+"').value
== 7", 7000);
+
+ pause(1500, pollId);
+ writeStatus("Polling should be stopped...");
+ AssertValueEquals(inputId, "7");
+ AssertTextEquals(parentId + "_text", "Polling");
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ajax4jsf.test.base.RichSeleniumTest#getTestUrl()
+ */
+ public String getTestUrl() {
+ return "/faces/pages/ajaxPoll/ajaxPollTest.xhtml";
+ }
+
+}