Author: andrei_exadel
Date: 2008-04-15 07:11:39 -0400 (Tue, 15 Apr 2008)
New Revision: 7835
Added:
trunk/test-applications/seleniumTest/src/main/webapp/pages/ajaxCommandButton/
trunk/test-applications/seleniumTest/src/test/java/org/ajax4jsf/test/base/RichSeleniumTest.java
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/AjaxCommandButtonTest.java
Removed:
trunk/test-applications/seleniumTest/src/main/webapp/pages/ajaxCommonButton/
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/AjaxCommandButtonTest.java
Modified:
trunk/test-applications/seleniumTest/src/test/java/org/ajax4jsf/test/base/SeleniumTestBase.java
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/AjaxCommandLinkTest.java
Log:
refactoring
Copied: trunk/test-applications/seleniumTest/src/main/webapp/pages/ajaxCommandButton (from
rev 7831, trunk/test-applications/seleniumTest/src/main/webapp/pages/ajaxCommonButton)
Added:
trunk/test-applications/seleniumTest/src/test/java/org/ajax4jsf/test/base/RichSeleniumTest.java
===================================================================
---
trunk/test-applications/seleniumTest/src/test/java/org/ajax4jsf/test/base/RichSeleniumTest.java
(rev 0)
+++
trunk/test-applications/seleniumTest/src/test/java/org/ajax4jsf/test/base/RichSeleniumTest.java 2008-04-15
11:11:39 UTC (rev 7835)
@@ -0,0 +1,8 @@
+package org.ajax4jsf.test.base;
+
+public interface RichSeleniumTest {
+
+ public void startSelenium (String browser);
+
+ public void stopSelenium();
+}
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-15
10:28:49 UTC (rev 7834)
+++
trunk/test-applications/seleniumTest/src/test/java/org/ajax4jsf/test/base/SeleniumTestBase.java 2008-04-15
11:11:39 UTC (rev 7835)
@@ -1,9 +1,6 @@
package org.ajax4jsf.test.base;
import org.testng.Assert;
-import org.testng.annotations.AfterTest;
-import org.testng.annotations.BeforeTest;
-import org.testng.annotations.Parameters;
import com.thoughtworks.selenium.DefaultSelenium;
@@ -13,13 +10,16 @@
* @author Andrey Markavtsov
*
*/
-public class SeleniumTestBase {
+public abstract class SeleniumTestBase {
/** Specifies the time to wait for page rendering */
private static final Integer pageRenderTime = 5000;
+
+ /** Specifies the time to wait for ajax processing */
+ protected static final int ajaxCompletionTime = 3000;
/** The default selenium instance */
- protected DefaultSelenium selenium;
+ public DefaultSelenium selenium;
/** Host */
public String host;
@@ -37,10 +37,6 @@
public static final String COMPONENT_PREFIX_INSIDE_PANEL =
"_Selenium_Test_Form2:";
- public SeleniumTestBase() {
- /* Default constructor */
- }
-
public SeleniumTestBase(String protocol, String host, String port) {
this.host = host;
this.port = port;
@@ -52,18 +48,16 @@
* @param browser
* @return
*/
- public DefaultSelenium createSeleniumClient(String url, String browser) {
+ private DefaultSelenium createSeleniumClient(String url, String browser) {
return new DefaultSelenium(host, 4444, browser, url);
}
/**
* This method are invoking before selenium tests started
*/
- @BeforeTest
- @Parameters( { "browser" })
- public void startSelenium(String browser) {
- selenium = createSeleniumClient(protocol + "://" + host + ":"
+ port + "/", browser);
- selenium.start();
+ protected void startSelenium(String browser) {
+ selenium = createSeleniumClient(protocol + "://" + host + ":" +
port + "/", browser);
+ selenium.start();
}
/**
@@ -116,8 +110,7 @@
/**
* This method are invoking after selenium tests completed
*/
- @AfterTest
- public void stopSelenium() {
+ protected void stopSelenium() {
selenium.stop();
selenium = null;
}
@@ -153,6 +146,16 @@
public void waitForAjaxCompletion(int miliseconds) {
selenium.waitForCondition("selenium.browserbot.getCurrentWindow().done==true",
String.valueOf(miliseconds));
}
+
+ /**
+ * Waits while AJAX request will be completed
+ *
+ * @param miliseconds -
+ * time to wait
+ */
+ public void waitForAjaxCompletion() {
+
selenium.waitForCondition("selenium.browserbot.getCurrentWindow().done==true",
String.valueOf(ajaxCompletionTime));
+ }
/**
* Asserts DOM node value equals to value defined
Deleted:
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/AjaxCommandButtonTest.java
===================================================================
---
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/AjaxCommandButtonTest.java 2008-04-15
10:28:49 UTC (rev 7834)
+++
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/AjaxCommandButtonTest.java 2008-04-15
11:11:39 UTC (rev 7835)
@@ -1,70 +0,0 @@
-package org.richfaces;
-
-import org.ajax4jsf.test.base.SeleniumTestBase;
-import org.testng.annotations.Test;
-
-public class AjaxCommandButtonTest extends SeleniumTestBase {
-
- public AjaxCommandButtonTest() {
- super("http", "localhost", "8080");
- }
-
- @Test
- public void testAjaxCommandButtonComponent() throws Exception {
- renderPage("/faces/pages/ajaxCommandButton/ajaxButtonTest.xhtml");
-
- _testAjaxCommandButtonComponent(COMPONENT_PREFIX_INSIDE_TABLE);
- _testAjaxCommandButtonComponent(COMPONENT_PREFIX_INSIDE_PANEL);
- }
-
- private void _testAjaxCommandButtonComponent(String parentId) {
- // test inside DataTable
- String buttonId = parentId + "b1";
- String inputId = parentId + "_value";
-
- clickById(buttonId);
- waitForAjaxCompletion(3000);
- AssertValueEquals(inputId, "3");
-
- clickById(buttonId);
- waitForAjaxCompletion(1000);
- AssertValueEquals(inputId, "6");
-
- buttonId = parentId + "b2";
-
- clickById(buttonId);
- waitForAjaxCompletion(1000);
- AssertValueEquals(inputId, "6");
-
- buttonId = parentId + "b3";
-
- clickById(buttonId);
- waitForAjaxCompletion(1000);
- AssertValueEquals(inputId, "6");
-
- buttonId = parentId + "b4";
-
- clickById(buttonId);
- waitForAjaxCompletion(1000);
- AssertValueEquals(inputId, "1");
-
- buttonId = parentId + "b5";
-
- clickById(buttonId);
- waitForAjaxCompletion(1000);
- AssertValueEquals(inputId, "2");
-
- buttonId = parentId + "b1";
-
- clickById(buttonId);
- waitForAjaxCompletion(1000);
- AssertValueEquals(inputId, "5");
-
- buttonId = parentId + "b3";
-
- clickById(buttonId);
- waitForAjaxCompletion(1000);
- AssertValueEquals(inputId, "5");
- }
-
-}
Added:
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/AjaxCommandButtonTest.java
===================================================================
---
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/AjaxCommandButtonTest.java
(rev 0)
+++
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/AjaxCommandButtonTest.java 2008-04-15
11:11:39 UTC (rev 7835)
@@ -0,0 +1,92 @@
+package org.richfaces;
+
+import org.ajax4jsf.test.base.RichSeleniumTest;
+import org.ajax4jsf.test.base.SeleniumTestBase;
+import org.testng.annotations.AfterTest;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Parameters;
+import org.testng.annotations.Test;
+
+
+public class AjaxCommandButtonTest extends SeleniumTestBase implements RichSeleniumTest
{
+
+ public AjaxCommandButtonTest() {
+ 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 testAjaxCommandButtonComponent() throws Exception {
+ renderPage("/faces/pages/ajaxCommandButton/ajaxButtonTest.xhtml");
+
+ _testAjaxCommandButtonComponent(COMPONENT_PREFIX_INSIDE_TABLE);
+ _testAjaxCommandButtonComponent(COMPONENT_PREFIX_INSIDE_PANEL);
+ }
+
+ private void _testAjaxCommandButtonComponent(String parentId) {
+ // test inside DataTable
+ String buttonId = parentId + "b1";
+ String inputId = parentId + "_value";
+
+ clickById(buttonId);
+ waitForAjaxCompletion();
+ AssertValueEquals(inputId, "3");
+
+ clickById(buttonId);
+ waitForAjaxCompletion();
+ AssertValueEquals(inputId, "6");
+
+ buttonId = parentId + "b2";
+
+ clickById(buttonId);
+ waitForAjaxCompletion();
+ AssertValueEquals(inputId, "6");
+
+ buttonId = parentId + "b3";
+
+ clickById(buttonId);
+ waitForAjaxCompletion();
+ AssertValueEquals(inputId, "6");
+
+ buttonId = parentId + "b4";
+
+ clickById(buttonId);
+ waitForAjaxCompletion();
+ AssertValueEquals(inputId, "1");
+
+ buttonId = parentId + "b5";
+
+ clickById(buttonId);
+ waitForAjaxCompletion();
+ AssertValueEquals(inputId, "2");
+
+ buttonId = parentId + "b1";
+
+ clickById(buttonId);
+ waitForAjaxCompletion();
+ AssertValueEquals(inputId, "5");
+
+ buttonId = parentId + "b3";
+
+ clickById(buttonId);
+ waitForAjaxCompletion();
+ AssertValueEquals(inputId, "5");
+ }
+
+}
Modified:
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/AjaxCommandLinkTest.java
===================================================================
---
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/AjaxCommandLinkTest.java 2008-04-15
10:28:49 UTC (rev 7834)
+++
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/AjaxCommandLinkTest.java 2008-04-15
11:11:39 UTC (rev 7835)
@@ -1,69 +1,90 @@
package org.richfaces;
+import org.ajax4jsf.test.base.RichSeleniumTest;
import org.ajax4jsf.test.base.SeleniumTestBase;
+import org.testng.annotations.AfterTest;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
-public class AjaxCommandLinkTest extends SeleniumTestBase {
+public class AjaxCommandLinkTest extends SeleniumTestBase implements RichSeleniumTest {
public AjaxCommandLinkTest() {
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 testAjaxCommandLinkComponent() throws Exception {
renderPage("/faces/pages/ajaxCommandLink/ajaxLinkTest.xhtml");
- _testAjaxCommandButtonComponent(COMPONENT_PREFIX_INSIDE_TABLE);
- _testAjaxCommandButtonComponent(COMPONENT_PREFIX_INSIDE_PANEL);
+ _testAjaxCommandLinkComponent(COMPONENT_PREFIX_INSIDE_TABLE);
+ _testAjaxCommandLinkComponent(COMPONENT_PREFIX_INSIDE_PANEL);
}
- private void _testAjaxCommandButtonComponent(String parentId) {
+ private void _testAjaxCommandLinkComponent(String parentId) {
// test inside DataTable
String LinkId = parentId + "l1";
String inputId = parentId + "_value";
clickById(LinkId);
- waitForAjaxCompletion(3000);
+ waitForAjaxCompletion();
AssertValueEquals(inputId, "3");
clickById(LinkId);
- waitForAjaxCompletion(1000);
+ waitForAjaxCompletion();
AssertValueEquals(inputId, "6");
LinkId = parentId + "l2";
clickById(LinkId);
- waitForAjaxCompletion(1000);
+ waitForAjaxCompletion();
AssertValueEquals(inputId, "6");
LinkId = parentId + "l3";
clickById(LinkId);
- waitForAjaxCompletion(1000);
+ waitForAjaxCompletion();
AssertValueEquals(inputId, "6");
LinkId = parentId + "l4";
clickById(LinkId);
- waitForAjaxCompletion(1000);
+ waitForAjaxCompletion();
AssertValueEquals(inputId, "1");
LinkId = parentId + "l5";
clickById(LinkId);
- waitForAjaxCompletion(1000);
+ waitForAjaxCompletion();
AssertValueEquals(inputId, "2");
LinkId = parentId + "l1";
clickById(LinkId);
- waitForAjaxCompletion(1000);
+ waitForAjaxCompletion();
AssertValueEquals(inputId, "5");
LinkId = parentId + "l3";
clickById(LinkId);
- waitForAjaxCompletion(1000);
+ waitForAjaxCompletion();
AssertValueEquals(inputId, "5");
}