Author: andrei_exadel
Date: 2008-05-29 08:21:21 -0400 (Thu, 29 May 2008)
New Revision: 8821
Modified:
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/SeleniumTestBase.java
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/testng/AjaxCommandButtonTest.java
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/testng/AjaxCommandLinkTest.java
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/testng/AjaxPollTest.java
Log:
Poll test refactoring
Modified:
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/SeleniumTestBase.java
===================================================================
---
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/SeleniumTestBase.java 2008-05-29
09:34:47 UTC (rev 8820)
+++
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/SeleniumTestBase.java 2008-05-29
12:21:21 UTC (rev 8821)
@@ -94,6 +94,7 @@
/**
* Renders page
*/
+ @Deprecated
protected void renderPage(String homePage) {
selenium.open(protocol + "://" + host + ":" + port +
"/" + APPLICATION_NAME + homePage);
selenium.waitForPageToLoad(String.valueOf(pageRenderTime));
@@ -112,6 +113,7 @@
/**
* Renders page
*/
+ @Deprecated
protected void renderPage(String homePage, Templates template) {
selenium.open(protocol + "://" + host + ":" + port +
"/" + APPLICATION_NAME + homePage);
selenium.waitForPageToLoad(String.valueOf(pageRenderTime));
@@ -128,7 +130,28 @@
checkJSError();
}
+
+ /**
+ * Renders page
+ */
+ protected void renderPage(Templates template) {
+ selenium.open(protocol + "://" + host + ":" + port +
"/" + APPLICATION_NAME + getTestUrl());
+ selenium.waitForPageToLoad(String.valueOf(pageRenderTime));
+
+ template.loadTemplate(this);
+ checkPageRendering(); // At the first we check if page has been
+ // rendered
+ checkJSError(); // At the second we check if JS errors occurred
+
+ reRenderForm(); // ReRender component
+
+ checkPageRendering(); // Check all again
+ checkJSError();
+
+ }
+
+
/**
* Writes status message on client side
*
@@ -273,6 +296,20 @@
String _v = getValueById(id);
Assert.assertEquals(_v, value);
}
+
+ /**
+ * Asserts DOM node value equals to value defined
+ *
+ * @param id -
+ * DOM element id
+ * @param value -
+ * value defined
+ * @param message = message to be displayed in failure case
+ */
+ public void AssertValueEquals(String id, String value, String message) {
+ String _v = getValueById(id);
+ Assert.assertEquals(_v, value, message);
+ }
/**
* Asserts DOM node value does not equal to value defined
@@ -286,7 +323,23 @@
String _v = getValueById(id);
Assert.assertNotSame(_v, value);
}
+
+
+ /**
+ * Asserts DOM node value does not equal to value defined
+ *
+ * @param id -
+ * DOM element id
+ * @param value -
+ * value defined
+ * @param message = message to be displayed in failure case
+ */
+ public void AssertValueNotEquals(String id, String value, String message) {
+ String _v = getValueById(id);
+ Assert.assertNotSame(_v, value, message);
+ }
+
/**
* Asserts DOM node text equals to text defined
*
@@ -299,7 +352,22 @@
String _v = getTextById(id);
Assert.assertEquals(_v, value);
}
+
+ /**
+ * Asserts DOM node text equals to text defined
+ *
+ * @param id -
+ * DOM element id
+ * @param value -
+ * text defined
+ * @param message = message to be displayed in failure case
+ */
+ public void AssertTextEquals(String id, String value, String message) {
+ String _v = getTextById(id);
+ Assert.assertEquals(_v, value, message);
+ }
+
/**
* Asserts DOM node text does not equal to text defined
*
@@ -312,6 +380,20 @@
String _v = getTextById(id);
Assert.assertNotSame(_v, value);
}
+
+ /**
+ * Asserts DOM node text does not equal to text defined
+ *
+ * @param id -
+ * DOM element id
+ * @param value -
+ * text defined
+ * @param message = message to be displayed in failure case
+ */
+ public void AssertTextNotEquals(String id, String value, String message) {
+ String _v = getTextById(id);
+ Assert.assertNotSame(_v, value, message);
+ }
/**
* Asserts DOM node is visible
@@ -538,7 +620,16 @@
}
}
+
+ /**
+ * Returns the url to test page to be opened by selenium
+ * @return
+ */
+ protected String getTestUrl() {
+ return null;
+ }
+
public boolean isFF() {
return new
Boolean(selenium.getEval("navigator.userAgent.indexOf('Firefox') >
-1"));
}
Modified:
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/testng/AjaxCommandButtonTest.java
===================================================================
---
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/testng/AjaxCommandButtonTest.java 2008-05-29
09:34:47 UTC (rev 8820)
+++
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/testng/AjaxCommandButtonTest.java 2008-05-29
12:21:21 UTC (rev 8821)
@@ -41,7 +41,7 @@
}
private void _testAjaxCommandButtonComponent(Templates template) {
- renderPage(getTestUrl(), template);
+ renderPage(template);
String parentId = getParentId() + "_form:";
Modified:
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/testng/AjaxCommandLinkTest.java
===================================================================
---
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/testng/AjaxCommandLinkTest.java 2008-05-29
09:34:47 UTC (rev 8820)
+++
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/testng/AjaxCommandLinkTest.java 2008-05-29
12:21:21 UTC (rev 8821)
@@ -41,7 +41,7 @@
}
private void _testAjaxCommandLinkComponent(Templates template) {
- renderPage(getTestUrl(), template);
+ renderPage(template);
String parentId = getParentId() + "_form:";
Modified:
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/testng/AjaxPollTest.java
===================================================================
---
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/testng/AjaxPollTest.java 2008-05-29
09:34:47 UTC (rev 8820)
+++
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/testng/AjaxPollTest.java 2008-05-29
12:21:21 UTC (rev 8821)
@@ -6,6 +6,7 @@
import org.richfaces.RichSeleniumTest;
import org.richfaces.SeleniumTestBase;
import org.richfaces.Templates;
+import org.testng.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Parameters;
@@ -46,27 +47,37 @@
}
private void _testAjaxPollComponent(Templates template) {
- renderPage(getTestUrl(), template);
+ renderPage(template);
String parentId = getParentId() + "_form:";
String pollId = parentId + "poll";
String inputId = parentId + "_value";
- writeStatus("Start polling...");
- clickById(parentId + "_enabled");
- waitForAjaxCompletion();
+ enablePoll(parentId + "_enabled");
AssertValueEquals(inputId, "1");
writeStatus("Polling in progress...");
pause(1500, pollId);
- AssertValueNotEquals(inputId, "1");
+ AssertValueNotEquals(inputId, "1", "Polling does not fire after
component was enabled. Or 'ReRender' attribute does not work");
+
waiteForCondition("document.getElementById('"+inputId+"').value
== 8", 7000);
pause(1500, pollId);
writeStatus("Polling should be stopped...");
- AssertValueEquals(inputId, "8");
- AssertTextEquals(parentId + "_text", "Polling");
+
+ AssertValueEquals(inputId, "8", "Polling should be stopped. It continues
to poll after component was disabled.");
+ AssertTextEquals(parentId + "_text", "Polling", "Polling
terminated abnormal or invalid count of ajax requests has been submitted");
}
+
+ private void enablePoll(String id) {
+ writeStatus("Enable polling...");
+ try {
+ clickById(id);
+ waitForAjaxCompletion();
+ }catch (Exception e) {
+ Assert.fail("Poll component failed after attempt to enable polling. Caused by
" + e);
+ }
+ }
/*
* (non-Javadoc)