Author: andrei_exadel
Date: 2008-04-18 06:06:23 -0400 (Fri, 18 Apr 2008)
New Revision: 7920
Added:
trunk/test-applications/seleniumTest/src/main/java/org/ajax4jsf/ProgressBarTestBean.java
trunk/test-applications/seleniumTest/src/main/webapp/pages/progressBar/
trunk/test-applications/seleniumTest/src/main/webapp/pages/progressBar/progressBarDescription.xhtml
trunk/test-applications/seleniumTest/src/main/webapp/pages/progressBar/progressBarTest.xhtml
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/ProgressBarTest.java
Modified:
trunk/test-applications/seleniumTest/src/main/webapp/WEB-INF/faces-config.xml
trunk/test-applications/seleniumTest/src/main/webapp/layout/template.xhtml
trunk/test-applications/seleniumTest/src/test/java/org/ajax4jsf/test/base/SeleniumTestBase.java
Log:
progress bar test
Added:
trunk/test-applications/seleniumTest/src/main/java/org/ajax4jsf/ProgressBarTestBean.java
===================================================================
---
trunk/test-applications/seleniumTest/src/main/java/org/ajax4jsf/ProgressBarTestBean.java
(rev 0)
+++
trunk/test-applications/seleniumTest/src/main/java/org/ajax4jsf/ProgressBarTestBean.java 2008-04-18
10:06:23 UTC (rev 7920)
@@ -0,0 +1,50 @@
+package org.ajax4jsf;
+
+import java.util.Date;
+
+public class ProgressBarTestBean {
+
+ private boolean enabled = false;
+
+ private Long value = -5L;
+
+ public String getDate() {
+ return String.valueOf(new Date().getTime());
+ }
+
+ public String getCompleteDate() {
+ return String.valueOf(new Date().getTime());
+ }
+
+ /**
+ * @return the enabled
+ */
+ public boolean isEnabled() {
+ return enabled;
+ }
+
+ /**
+ * @param enabled the enabled to set
+ */
+ public void setEnabled(boolean enabled) {
+ this.enabled = enabled;
+ }
+
+ /**
+ * @return the value
+ */
+ public Long getValue() {
+ value++;
+ return value;
+ }
+
+ /**
+ * @param value the value to set
+ */
+ public void setValue(Long value) {
+ this.value = value;
+ }
+
+
+
+}
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-18
09:30:11 UTC (rev 7919)
+++
trunk/test-applications/seleniumTest/src/main/webapp/WEB-INF/faces-config.xml 2008-04-18
10:06:23 UTC (rev 7920)
@@ -25,6 +25,11 @@
<managed-bean-name>commandBean</managed-bean-name>
<managed-bean-class>org.ajax4jsf.A4JCommandTestBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
+ </managed-bean>
+ <managed-bean>
+ <managed-bean-name>progressBarBean</managed-bean-name>
+ <managed-bean-class>org.ajax4jsf.ProgressBarTestBean</managed-bean-class>
+ <managed-bean-scope>session</managed-bean-scope>
</managed-bean>
<managed-bean>
<managed-bean-name>tabPanelBean</managed-bean-name>
Modified: trunk/test-applications/seleniumTest/src/main/webapp/layout/template.xhtml
===================================================================
--- trunk/test-applications/seleniumTest/src/main/webapp/layout/template.xhtml 2008-04-18
09:30:11 UTC (rev 7919)
+++ trunk/test-applications/seleniumTest/src/main/webapp/layout/template.xhtml 2008-04-18
10:06:23 UTC (rev 7920)
@@ -8,6 +8,7 @@
<head>
<script>
var errorMessage = null;
+ var pauseHolder = {};
window.onerror = function (message, url, code) {
errorMessage = message;
};
@@ -15,6 +16,11 @@
return errorMessage;
}
+ function pause (miliseconds, id) {
+ pauseHolder[id] = false;
+ window.setTimeout(function () { pauseHolder[id] = true; }, miliseconds);
+ }
+
function submitForm () {
document.getElementById('_form').submit();
}
Added:
trunk/test-applications/seleniumTest/src/main/webapp/pages/progressBar/progressBarDescription.xhtml
===================================================================
---
trunk/test-applications/seleniumTest/src/main/webapp/pages/progressBar/progressBarDescription.xhtml
(rev 0)
+++
trunk/test-applications/seleniumTest/src/main/webapp/pages/progressBar/progressBarDescription.xhtml 2008-04-18
10:06:23 UTC (rev 7920)
@@ -0,0 +1,25 @@
+<html>
+<table border="1" style="border-color: #F1EEE9"
cellpadding="5" cellspacing="0">
+<tr><th></th><th>Action</th><th>Result</th></tr>
+<tr><td>1</td><td>Get progressBar1
value</td><td>Value < 0</td></tr>
+<tr><td>2</td><td>Get progreesBar1 text</td><td>Text
== 'Process not started'</td></tr>
+<tr><td>3</td><td>Enable progressBar1</td><td>Polling
should be started</td></tr>
+<tr><td>4</td><td>Wait for 5 seconds</td><td>
</td></tr>
+<tr><td>5</td><td>Disable
progressBar1</td><td>Polling should be stopped</td></tr>
+<tr><td>6</td><td>Get progressBar1 text</td><td>Test
should be ended with '%'</td></tr>
+<tr><td>7</td><td>Get progressBar1
value</td><td>Value > 0</td></tr>
+<tr><td>8</td><td>Enable progressBar1</td><td>Polling
should be started</td></tr>
+<tr><td>9</td><td>Wait for 5
seconds</td><td></td></tr>
+<tr><td>10</td><td>Get progressBar1
value</td><td>Value should be different from the
previous</td></tr>
+<tr><td>11</td><td>Disable
progressBar1</td><td>Polling should be stopped</td></tr>
+<tr><td>12</td><td>Get progressBar1
value</td><td>Remember the value</td></tr>
+<tr><td>13</td><td>Wait for 1.5 seconds</td><td>
</td></tr>
+<tr><td>14</td><td>Get progressBar1
value</td><td>Value should be the same as the previous</td></tr>
+<tr><td>15</td><td>Get progressBar2
value</td><td>Value == -5</td></tr>
+<tr><td>16</td><td>Get progreesBar2 text</td><td>Text
== 'Process not started'</td></tr>
+<tr><td>17</td><td>Set progressBar2 value in '20' through
JS API </td><td>Progress should be changed</td></tr>
+<tr><td>18</td><td>Get progressBar2 value
</td><td>Value == 20</td></tr>
+<tr><td>19</td><td>Set progressBar2 value in '60' through
JS API </td><td>Progress should be changed</td></tr>
+<tr><td>20</td><td>Get progressBar2 value
</td><td>Value == 60</td></tr>
+</table>
+</html>
\ No newline at end of file
Added:
trunk/test-applications/seleniumTest/src/main/webapp/pages/progressBar/progressBarTest.xhtml
===================================================================
---
trunk/test-applications/seleniumTest/src/main/webapp/pages/progressBar/progressBarTest.xhtml
(rev 0)
+++
trunk/test-applications/seleniumTest/src/main/webapp/pages/progressBar/progressBarTest.xhtml 2008-04-18
10:06:23 UTC (rev 7920)
@@ -0,0 +1,35 @@
+<!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="../../layout/template.xhtml">
+ <ui:define name="component">
+ <rich:progressBar enabled="#{progressBarBean.enabled}"
id="progressBar1" value="#{progressBarBean.value}">
+ <f:facet name="initial">
+ <h:outputText value="Process not started"></h:outputText>
+ </f:facet>
+ <f:facet name="complete">
+ <h:outputText value="Process not started"></h:outputText>
+ </f:facet>
+ <h:outputText value="{value}%"></h:outputText>
+ </rich:progressBar><br/>
+ <br/><br/>
+ <rich:progressBar enabled="#{progressBarBean.enabled}"
mode="client" id="progressBar2" value="-5">
+ <f:facet name="initial">
+ <h:outputText value="Process not started"></h:outputText>
+ </f:facet>
+ <f:facet name="complete">
+ <h:outputText value="Process not started"></h:outputText>
+ </f:facet>
+ <h:outputText value="{value}%"></h:outputText>
+ </rich:progressBar> <br/>
+ </ui:define>
+ <ui:define name="description">
+ <ui:include src="progressBarDescription.xhtml" />
+ </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-18
09:30:11 UTC (rev 7919)
+++
trunk/test-applications/seleniumTest/src/test/java/org/ajax4jsf/test/base/SeleniumTestBase.java 2008-04-18
10:06:23 UTC (rev 7920)
@@ -17,6 +17,8 @@
/** Specifies the time to wait for ajax processing */
protected static final int ajaxCompletionTime = 3000;
+
+ private static final String WINDOW_JS_RESOLVER =
"selenium.browserbot.getCurrentWindow().";
/** The default selenium instance */
public DefaultSelenium selenium;
@@ -106,6 +108,18 @@
// clickById("_Selenium_Test_ReRender_Form:_reRender");
waitForAjaxCompletion(3000);
}
+
+
+ /**
+ * Performs script defined in parameter
+ * @param script
+ * @return
+ */
+ public String runScript(String script) {
+ String result = selenium.getEval(WINDOW_JS_RESOLVER + script);
+ checkJSError();
+ return result;
+ }
/**
* This method are invoking after selenium tests completed
@@ -115,51 +129,53 @@
selenium = null;
}
- /**
- * Checks if JS error occurred. Fails test if yes. This method should be
- * invoked after each event or any thing which can be a cause of JS error.
- */
- public void checkJSError() {
- String error =
selenium.getEval("selenium.browserbot.getCurrentWindow().checkError();");
- if (error != null && !("null".equals(error)) &&
!("".equals(error))) {
- Assert.fail("Failure by the following Javascript error: " +
error);
- }
- }
+ /**
+ * Checks if JS error occurred. Fails test if yes. This method should be
+ * invoked after each event or any thing which can be a cause of JS error.
+ */
+ public void checkJSError() {
+ String error = selenium.getEval(WINDOW_JS_RESOLVER +
"checkError();");
+ if (error != null && !("null".equals(error)) &&
!("".equals(error))) {
+ Assert.fail("Failure by the following Javascript error: " +
error);
+ }
+ }
- /**
- * Checks if page containing component test has been rendered completely
- */
- public void checkPageRendering() {
- try {
- String t1 = getTextById("_Selenium_Test_ControlPoint1");
- String t2 = getTextById("_Selenium_Test_ControlPoint2");
- if (t1 == null || t2 == null || !"Control1".equals(t1) ||
!"Control2".equals(t2)) {
- Assert.fail("The page has been not rendered properlly");
- }
- }catch (Exception e) {
- Assert.fail("The page has been not rendered properlly by the following error:
" + e);
- }
- }
+ /**
+ * Checks if page containing component test has been rendered completely
+ */
+ public void checkPageRendering() {
+ try {
+ String t1 = getTextById("_Selenium_Test_ControlPoint1");
+ String t2 = getTextById("_Selenium_Test_ControlPoint2");
+ if (t1 == null || t2 == null || !"Control1".equals(t1) ||
!"Control2".equals(t2)) {
+ Assert.fail("The page has been not rendered properlly");
+ }
+ }catch (Exception e) {
+ Assert.fail("The page has been not rendered properlly by the following error:
" + e);
+ }
+ }
+ /**
+ * Waits while AJAX request will be completed
+ *
+ * @param miliseconds -
+ * time to wait
+ */
+ public void waitForAjaxCompletion(int miliseconds) {
+ selenium.waitForCondition(WINDOW_JS_RESOLVER + "done==true",
String.valueOf(miliseconds));
+ }
+
+ /**
+ * Waits while AJAX request will be completed
+ *
+ * @param miliseconds -
+ * time to wait
+ */
+ public void waitForAjaxCompletion() {
+ waitForAjaxCompletion(ajaxCompletionTime);
+ }
- /**
- * Waits while AJAX request will be completed
- *
- * @param miliseconds -
- * time to wait
- */
- public void waitForAjaxCompletion(int miliseconds) {
-
selenium.waitForCondition("selenium.browserbot.getCurrentWindow().done==true",
String.valueOf(miliseconds));
- }
/**
- * Waits while AJAX request will be completed
- *
- */
- public void waitForAjaxCompletion() {
-
selenium.waitForCondition("selenium.browserbot.getCurrentWindow().done==true",
String.valueOf(ajaxCompletionTime));
- }
-
- /**
* Waits while simple request will be completed
*
* @param miliseconds -
@@ -237,7 +253,7 @@
* @return
*/
public String getTextById(String id) {
- return selenium.getText(id);
+ return selenium.getText("id=" + id);
}
/**
@@ -248,8 +264,18 @@
* @return
*/
public String getValueById(String id) {
- return selenium.getValue(id);
+ return selenium.getValue("id=" + id);
}
+
+
+ /**
+ * Returns element's width
+ * @param id - DOM element id
+ * @return
+ */
+ public Number getWidthById(String id) {
+ return selenium.getElementWidth("id=" + id);
+ }
/**
* Clicks on element
@@ -259,7 +285,7 @@
* @return
*/
public void clickById(String id) {
- selenium.click(id);
+ selenium.click("id=" + id);
checkJSError();
}
@@ -269,16 +295,35 @@
* @return
*/
public boolean isVisibleById(String id) {
- return selenium.isVisible(id);
+ return selenium.isVisible("id=" + id);
}
+
/**
* Creates delay
* @param miliSeconds
* @throws InterruptedException
*/
- public void delay(int miliSeconds) throws InterruptedException {
- Thread.sleep(miliSeconds);
+ public void delay(int miliSeconds) {
+ try {
+ Thread.sleep(miliSeconds);
+ } catch (Exception e) {
+
+ }
+ }
+
+ /**
+ * Creates pause for defined time in miliSeconds
+ * @param miliSeconds
+ */
+ public void pause(int miliSeconds, String id) {
+ StringBuffer script = new StringBuffer("pause(");
+ script.append(miliSeconds);
+ script.append(",'");
+ script.append(id);
+ script.append("');");
+ runScript(script.toString());
+ selenium.waitForCondition(WINDOW_JS_RESOLVER + "pauseHolder['" + id +
"'] == true;", String.valueOf(miliSeconds + 1000));
}
}
Added:
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/ProgressBarTest.java
===================================================================
--- trunk/test-applications/seleniumTest/src/test/java/org/richfaces/ProgressBarTest.java
(rev 0)
+++
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/ProgressBarTest.java 2008-04-18
10:06:23 UTC (rev 7920)
@@ -0,0 +1,122 @@
+package org.richfaces;
+
+import org.ajax4jsf.test.base.RichSeleniumTest;
+import org.ajax4jsf.test.base.SeleniumTestBase;
+import org.testng.Assert;
+import org.testng.annotations.AfterTest;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Parameters;
+import org.testng.annotations.Test;
+
+public class ProgressBarTest extends SeleniumTestBase implements
+ RichSeleniumTest {
+
+ public ProgressBarTest() {
+ 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 testProgressBarComponent() {
+ renderPage("/faces/pages/progressBar/progressBarTest.xhtml");
+
+ _testProgressBarComponent(COMPONENT_PREFIX_INSIDE_TABLE);
+ _testProgressBarComponent(COMPONENT_PREFIX_INSIDE_PANEL);
+ }
+
+ private void _testProgressBarComponent(String parentId) {
+
+ //- Test ajax mode
+
+ String progressBarId = parentId + "progressBar1";
+ int value = getProgressBarValue(progressBarId);
+ Assert.assertTrue(value < 0);
+ String text = getTextById(progressBarId);
+ Assert.assertTrue(text.startsWith("Process not started"));
+
+ enableProgressBar(progressBarId, true);
+
+ pause(5000, progressBarId);
+
+ enableProgressBar(progressBarId, false);
+
+ text = getTextById(progressBarId + ":remain");
+ Assert.assertTrue(text.endsWith("%"));
+
+ value = getProgressBarValue(progressBarId);
+ Assert.assertTrue(value > 0);
+
+ enableProgressBar(progressBarId, true);
+
+ pause(5000, progressBarId);
+ Assert.assertTrue((getProgressBarValue(progressBarId).intValue() != value));
+
+ enableProgressBar(progressBarId, false);
+
+ value = getProgressBarValue(progressBarId);
+ delay(1500);
+ Assert.assertTrue(getProgressBarValue(progressBarId) == value);
+
+
+ // - Test client mode
+
+ progressBarId = parentId + "progressBar2";
+ value = getProgressBarValue(progressBarId);
+ Assert.assertTrue(value == -5);
+
+ text = getTextById(progressBarId);
+ Assert.assertTrue(text.startsWith("Process not started"));
+
+ setProgressBarValue(progressBarId, 20);
+ value = getProgressBarValue(progressBarId);
+ Assert.assertTrue(value == 20);
+
+ setProgressBarValue(progressBarId, 60);
+ value = getProgressBarValue(progressBarId);
+ Assert.assertTrue(value == 60);
+
+
+
+
+
+ }
+
+ private void enableProgressBar(String id, boolean enable) {
+ StringBuffer script = new StringBuffer("$('");
+ script.append(id).append("').component.").append(
+ enable ? "enable();" : "disable();");
+ runScript(script.toString());
+ }
+
+ private void setProgressBarValue(String id, Object value) {
+ StringBuffer script = new StringBuffer("$('");
+ script.append(id).append("').component.").append("setValue(").append(
+ value).append(");");
+ runScript(script.toString());
+ }
+
+ private Integer getProgressBarValue(String id) {
+ StringBuffer script = new StringBuffer("$('");
+ script.append(id).append("').component.").append("getValue();");
+ String value = runScript(script.toString());
+ Integer v = Integer.parseInt(value);
+ return v;
+ }
+
+}