Author: andrei_exadel
Date: 2008-10-15 05:46:40 -0400 (Wed, 15 Oct 2008)
New Revision: 10760
Modified:
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/ajaxCommandLink/ajaxCommandLinkAutoTest.xhtml
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/AutoTester.java
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/SeleniumEvent.java
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/SeleniumTestBase.java
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/AjaxCommandLinkTest.java
Log:
AJAX command Link: test HTML attrs & events
Modified:
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/ajaxCommandLink/ajaxCommandLinkAutoTest.xhtml
===================================================================
---
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/ajaxCommandLink/ajaxCommandLinkAutoTest.xhtml 2008-10-15
09:39:01 UTC (rev 10759)
+++
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/ajaxCommandLink/ajaxCommandLinkAutoTest.xhtml 2008-10-15
09:46:40 UTC (rev 10760)
@@ -18,6 +18,17 @@
rendered="#{autoTestBean.rendered}"
oncomplete="#{autoTestBean.oncomplete}"
value="Link"
+ styleClass="noname"
+ style="color: blue; text-decoration: underline;"
+ onclick="EventQueue.fire('onclick')"
+ onkeydown="EventQueue.fire('onkeydown')"
+ onkeypress="EventQueue.fire('onkeypress')"
+ onkeyup="EventQueue.fire('onkeyup')"
+ onmousedown="EventQueue.fire('onmousedown')"
+ onmousemove="EventQueue.fire('onmousemove')"
+ onmouseout="EventQueue.fire('onmouseout')"
+ onmouseover="EventQueue.fire('onmouseover')"
+ onmouseup="EventQueue.fire('onmouseup')"
<f:param name="parameter1"
value="value1" />
<f:param name="parameter2" value="value2" />
Modified:
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/AutoTester.java
===================================================================
---
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/AutoTester.java 2008-10-15
09:39:01 UTC (rev 10759)
+++
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/AutoTester.java 2008-10-15
09:46:40 UTC (rev 10760)
@@ -197,6 +197,21 @@
}
+ public void testStyleAndClasses(String [] classNames, Map<String, String>
styleAttr) {
+ reset();
+ clickLoad();
+
+ String componentId = getClientId(COMPONENT_ID);
+
+ base.assertClassNames(componentId, classNames, "Component's rendering
invalid", true);
+ base.assertStyleAttributes(componentId, styleAttr);
+ }
+
+ public void testHTMLEvents() {
+ String componentId = getClientId(COMPONENT_ID);
+ base.assertEvents(componentId, SeleniumEvent.STANDARD_HTML_EVENTS);
+ }
+
private void checkComponentReRendered() {
if (base.getReRendersId() == null) {
return;
Modified:
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/SeleniumEvent.java
===================================================================
---
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/SeleniumEvent.java 2008-10-15
09:39:01 UTC (rev 10759)
+++
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/SeleniumEvent.java 2008-10-15
09:46:40 UTC (rev 10760)
@@ -1,5 +1,8 @@
package org.richfaces;
+import java.util.ArrayList;
+import java.util.List;
+
public enum SeleniumEvent {
ONCLICK("onclick"),
@@ -16,6 +19,20 @@
private String name;
+ public static final List<SeleniumEvent> STANDARD_HTML_EVENTS = new
ArrayList<SeleniumEvent>();
+ static {
+ STANDARD_HTML_EVENTS.add(ONCLICK);
+ STANDARD_HTML_EVENTS.add(ONMOUSEOVER);
+ STANDARD_HTML_EVENTS.add(ONMOUSEMOVE);
+ STANDARD_HTML_EVENTS.add(ONMOUSEOUT);
+ STANDARD_HTML_EVENTS.add(ONMOUSEDOWN);
+ STANDARD_HTML_EVENTS.add(ONMOUSEUP);
+ STANDARD_HTML_EVENTS.add(ONKEYDOWN);
+ STANDARD_HTML_EVENTS.add(ONKEYUP);
+ STANDARD_HTML_EVENTS.add(ONKEYPRESS);
+
+ }
+
private SeleniumEvent(String name) {
this.name = name;
}
@@ -23,5 +40,10 @@
public String getName() {
return name;
}
+
+ @Override
+ public String toString() {
+ return name;
+ }
}
Modified:
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/SeleniumTestBase.java
===================================================================
---
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/SeleniumTestBase.java 2008-10-15
09:39:01 UTC (rev 10759)
+++
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/SeleniumTestBase.java 2008-10-15
09:46:40 UTC (rev 10760)
@@ -1063,6 +1063,48 @@
}
eventsExpected.clear();
}
+
+ public Object assertEvents(String id, List<SeleniumEvent> eventsExpected) {
+
+ for (SeleniumEvent ev : eventsExpected) {
+ if (ev == SeleniumEvent.ONCLICK) {
+ clickById(id);
+ }else if (ev == SeleniumEvent.ONDBCLICK) {
+ selenium.doubleClick(id);
+ } else if (ev == SeleniumEvent.ONMOUSEDOWN) {
+ selenium.mouseDown(id);
+ }else if (ev == SeleniumEvent.ONMOUSEMOVE) {
+ selenium.mouseMove(id);
+ }else if (ev == SeleniumEvent.ONMOUSEUP) {
+ selenium.mouseUp(id);
+ }else if (ev == SeleniumEvent.ONMOUSEOVER) {
+ selenium.mouseOver(id);
+ }else if (ev == SeleniumEvent.ONMOUSEOUT) {
+ selenium.mouseOut(id);
+ }else if (ev == SeleniumEvent.ONKEYDOWN) {
+ selenium.keyDown(id, "a");
+ }else if (ev == SeleniumEvent.ONKEYUP) {
+ selenium.keyUp(id, "a");
+ }else if (ev == SeleniumEvent.ONKEYPRESS) {
+ selenium.keyPress(id, "a");
+ }
+
+ }
+
+ StringBuilder sb = new StringBuilder();
+ String delim = "";
+ for (SeleniumEvent event : eventsExpected) {
+
sb.append(delim).append("'").append(event).append("'");
+ delim = ",";
+ }
+ String json = "[" + sb.toString() + "]";
+ String message = runScript("EventQueue.assert(eval(\"" + json +
"\"))");
+ if (null != message && message.length() > 0) {
+ Assert.fail(message);
+ }
+ eventsExpected.clear();
+ return null;
+ }
public void autoTest(Template template, String component, List<SeleniumEvent>
events, Map<String , String> attributes) {
selenium.open(protocol + "://" + host + ":" + port +
"/" + APPLICATION_NAME + filterPrefix +
"/pages/_autotest/autotestsetup.xhtml");
@@ -1139,4 +1181,17 @@
public String getHTMLById(String id) {
return runScript(getElementById(id) + ".innerHTML");
}
+
+ public String getStyleAttributeString (String id, String attr) {
+ return runScript(getElementById(id) + ".getStyle('" + attr +
"')");
+
+ }
+
+ public void assertStyleAttributes(String id, Map<String, String> styleAttrs) {
+ for (String a : styleAttrs.keySet()) {
+ String actualStyle = getStyleAttributeString(id, a);
+ Assert.assertEquals(actualStyle, styleAttrs.get(a), "Style attribute invalid.
Expected ["+styleAttrs.get(a)+"]. But was ["+actualStyle+"]");
+ }
+
+ }
}
Modified:
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/AjaxCommandLinkTest.java
===================================================================
---
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/AjaxCommandLinkTest.java 2008-10-15
09:39:01 UTC (rev 10759)
+++
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/AjaxCommandLinkTest.java 2008-10-15
09:46:40 UTC (rev 10760)
@@ -13,13 +13,28 @@
public class AjaxCommandLinkTest extends SeleniumTestBase {
private static Map<String, String> parameter = new HashMap<String,
String>();
+ private static Map<String, String> styleAttributes = new HashMap<String,
String>();
static {
parameter.put("parameter1", "value1");
parameter.put("parameter2", "value2");
parameter.put("parameter3", "value3");
+
+ styleAttributes.put("color", "blue");
+ styleAttributes.put("text-decoration", "underline");
+
}
@Test
+ public void testHTMLAttributes(Template template) {
+ AutoTester tester = getAutoTester(this);
+ tester.renderPage(template, null);
+
+ tester.testStyleAndClasses(new String [] {"noname"}, styleAttributes);
+ tester.testHTMLEvents();
+
+ }
+
+ @Test
public void testReRender(Template template) {
AutoTester tester = getAutoTester(this);
tester.renderPage(template, null);