Author: andrei_exadel
Date: 2008-04-09 07:34:34 -0400 (Wed, 09 Apr 2008)
New Revision: 7690
Added:
trunk/test-applications/seleniumTest/src/test/java/
trunk/test-applications/seleniumTest/src/test/java/org/
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/AjaxCommandsTest.java
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/SeleniumExampleTest.java
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/SeleniumTestBase.java
Removed:
trunk/test-applications/seleniumTest/src/test/org/
Log:
Added:
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/AjaxCommandsTest.java
===================================================================
---
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/AjaxCommandsTest.java
(rev 0)
+++
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/AjaxCommandsTest.java 2008-04-09
11:34:34 UTC (rev 7690)
@@ -0,0 +1,89 @@
+package org.richfaces;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+
+import org.testng.annotations.Test;
+
+public class AjaxCommandsTest extends SeleniumTestBase {
+
+ public AjaxCommandsTest() {
+ super("http", "localhost", "8080");
+ }
+
+ @Test
+ public void testAjaxCommandsComponents() throws Exception {
+ selenium.open("http://localhost:8080/seleniumTest/faces/pages/ajaxCommands.xhtml");
+ selenium.waitForPageToLoad("5000");
+
+ assertEquals("1", getValueById("fff:text"));
+ assertTrue(isVisibleById("_viewRoot:status.stop"));
+
+ String date = getTextById("fff:date");
+
+ // the click on command button [ ajaxSingle = false ]
+ clickById("fff:b1");
+ selenium.waitForCondition(
+ "selenium.browserbot.getCurrentWindow().done==true", "1000");
+ assertEquals("3", getValueById("fff:text"));
+ assertFalse(getTextById("fff:date").equals(date));
+
+ // the click on command button [ ajaxSingle = false ]
+ clickById("fff:b1");
+ selenium.waitForCondition(
+ "selenium.browserbot.getCurrentWindow().done==true", "1000");
+ assertEquals("5", getValueById("fff:text"));
+ assertFalse(getTextById("fff:date").equals(date));
+
+ // the click on command link [ ajaxSingle = true ]
+ clickById("fff:l1");
+ selenium.waitForCondition(
+ "selenium.browserbot.getCurrentWindow().done==true", "1000");
+ assertEquals("2", getValueById("fff:text"));
+ assertFalse(getTextById("fff:date").equals(date));
+
+ // the click on command link [ ajaxSingle = true ]
+ clickById("fff:l1");
+ selenium.waitForCondition(
+ "selenium.browserbot.getCurrentWindow().done==true", "1000");
+ assertEquals("2", getValueById("fff:text"));
+ assertFalse(getTextById("fff:date").equals(date));
+
+ // the click on command button [ ajaxSingle = true ]
+ clickById("fff:b2");
+ assertTrue("".equals(getTextById("_form:param")));
+ assertEquals("2", getValueById("fff:text"));
+ delay(2000);
+ assertEquals("3", getValueById("fff:text"));
+ assertFalse(getTextById("fff:date").equals(date));
+
+ // the click on command button [ ajaxSingle = true ]
+ clickById("fff:b2");
+ assertEquals("3", getValueById("fff:text"));
+ delay(2000);
+ assertEquals("3", getValueById("fff:text"));
+ assertFalse(getTextById("fff:date").equals(date));
+
+ // the click on command link [ ajaxSingle = false ]
+ clickById("fff:l2");
+ assertTrue("actionParameter1"
+ .equals(getTextById("_form:param")));
+ assertEquals("3", getValueById("fff:text"));
+ delay(2000);
+ assertEquals("6", getValueById("fff:text"));
+ assertFalse(getTextById("fff:date").equals(date));
+ assertTrue("actionParameter2"
+ .equals(getTextById("_form:param")));
+
+ // the click on command link [ ajaxSingle = false ]
+ clickById("fff:l2");
+ assertEquals("6", getValueById("fff:text"));
+ delay(2000);
+ assertEquals("9", getValueById("fff:text"));
+ assertFalse(getTextById("fff:date").equals(date));
+ assertTrue("actionParameter2"
+ .equals(getTextById("_form:param")));
+ }
+
+}
Added:
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/SeleniumExampleTest.java
===================================================================
---
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/SeleniumExampleTest.java
(rev 0)
+++
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/SeleniumExampleTest.java 2008-04-09
11:34:34 UTC (rev 7690)
@@ -0,0 +1,62 @@
+/**
+ *
+ */
+package org.richfaces;
+
+/**
+ * @author asmirnov
+ *
+ */
+import static org.testng.Assert.*;
+
+import org.testng.Assert;
+import org.testng.annotations.AfterTest;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Parameters;
+import org.testng.annotations.Test;
+
+import com.thoughtworks.selenium.DefaultSelenium;
+
+public class SeleniumExampleTest
+
+{
+ private DefaultSelenium selenium;
+
+ protected DefaultSelenium createSeleniumClient(String url, String browser){
+ return new DefaultSelenium("localhost", 4444,
+ browser, url);
+ }
+ @BeforeTest
+ @Parameters({ "browser" })
+ public void startSelenium(String browser){
+ selenium = createSeleniumClient("http://localhost:8080/", browser);
+ selenium.start();
+ }
+
+ @Test(enabled=false)
+ public void testSomethingSimple() throws Exception {
+ selenium.open("http://localhost:8080/seleniumTest/faces/test.xhtml");
+ selenium.waitForPageToLoad("5000");
+
+ //
+ System.out.println("body [" + selenium.getHtmlSource() + "]");
+ //
+ // selenium.getEval("window.done=false;A4J.AJAX.AddListener(new
+ // A4J.AJAX.Listener(function(){window.done=true}))");
+ selenium.click("id=fff:lnk");
+ selenium.waitForCondition(
+ "selenium.browserbot.getCurrentWindow().done==true", "3000");
+ System.out.println("ajax body [" + selenium.getHtmlSource() + "]");
+ assertEquals("testOk", selenium.getText("id=fff:out"));
+
+ // Test help link
+ }
+ /**
+ *
+ */
+ @AfterTest
+ public void stopSelenium() {
+ selenium.stop();
+ selenium = null;
+ }
+}
\ No newline at end of file
Added:
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/SeleniumTestBase.java
===================================================================
---
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/SeleniumTestBase.java
(rev 0)
+++
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/SeleniumTestBase.java 2008-04-09
11:34:34 UTC (rev 7690)
@@ -0,0 +1,110 @@
+package org.richfaces;
+
+import org.ajax4jsf.renderkit.RendererUtils;
+import org.testng.annotations.AfterTest;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Parameters;
+
+import com.thoughtworks.selenium.DefaultSelenium;
+
+public class SeleniumTestBase {
+
+ private static final String equalCh = "=";
+
+ private static final String idSearch = RendererUtils.HTML.id_ATTRIBUTE + equalCh;
+
+ protected DefaultSelenium selenium;
+
+ private String host;
+
+ private String port;
+
+ private String protocol;
+
+ public SeleniumTestBase() {
+ // Default constructor
+ }
+
+ public SeleniumTestBase(String protocol, String host, String port) {
+ this.host = host;
+ this.port = port;
+ this.protocol = protocol;
+ }
+
+ /**
+ * @param url
+ * @param browser
+ * @return
+ */
+ public 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) {
+ System.out.println("___________>>>>>>>>>>>>."
+ protocol + "://" + host + ":" + port);
+ selenium = createSeleniumClient(protocol + "://" + host + ":" +
port, browser);
+ selenium.start();
+ }
+
+ /**
+ * This method are invoking after selenium tests completed
+ */
+ @AfterTest
+ public void stopSelenium() {
+ selenium.stop();
+ selenium = null;
+ }
+
+
+ /**
+ * Returns element's text
+ * @param id - DOM element id
+ * @return
+ */
+ public String getTextById(String id) {
+ return selenium.getText(idSearch + id);
+ }
+
+ /**
+ * Returns element's value
+ * @param id - DOM element id
+ * @return
+ */
+ public String getValueById(String id) {
+ return selenium.getValue(idSearch + id);
+ }
+
+ /**
+ * Clicks on element
+ * @param id - DOM element id
+ * @return
+ */
+ public void clickById(String id) {
+ selenium.click(idSearch + id);
+ }
+
+
+ /**
+ * Return true if element is visible
+ * @param id - DOM element id
+ * @return
+ */
+ public boolean isVisibleById(String id) {
+ return selenium.isVisible(idSearch + id);
+ }
+
+ /**
+ * Creates delay
+ * @param miliSeconds
+ * @throws InterruptedException
+ */
+ public void delay (int miliSeconds) throws InterruptedException {
+ Thread.sleep(miliSeconds);
+ }
+
+}
Show replies by date