Author: andrei_exadel
Date: 2008-10-06 07:41:40 -0400 (Mon, 06 Oct 2008)
New Revision: 10668
Added:
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/SeleniumEvent.java
Modified:
trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/autotest/AutoTestContext.java
trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/autotest/AutoTestServlet.java
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/SeleniumTestBase.java
Log:
AutoTest refactoring
Modified:
trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/autotest/AutoTestContext.java
===================================================================
---
trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/autotest/AutoTestContext.java 2008-10-03
19:09:01 UTC (rev 10667)
+++
trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/autotest/AutoTestContext.java 2008-10-06
11:41:40 UTC (rev 10668)
@@ -1,7 +1,9 @@
package org.ajax4jsf.autotest;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
public class AutoTestContext {
@@ -9,6 +11,8 @@
List<String> events = new ArrayList<String>();
+ Map<String, String> attributes = new HashMap<String, String>();
+
String rendered;
public AutoTestContext(String component) {
@@ -18,6 +22,10 @@
public void addEvent(String ev) {
events.add(ev);
}
+
+ public void addAttribute(String name, String value) {
+ attributes.put(name, value);
+ }
/**
* @return the component
@@ -32,6 +40,10 @@
public List<String> getEvents() {
return events;
}
+
+ public Map<String, String> getAttributes() {
+ return attributes;
+ }
/**
* @return the rendered
Modified:
trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/autotest/AutoTestServlet.java
===================================================================
---
trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/autotest/AutoTestServlet.java 2008-10-03
19:09:01 UTC (rev 10667)
+++
trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/autotest/AutoTestServlet.java 2008-10-06
11:41:40 UTC (rev 10668)
@@ -25,6 +25,10 @@
private static final String EVENT_PARAMETER_NAME = "ev";
+ private static final String ATTRIBUTE_PARAMETER_NAME = "at_name";
+
+ private static final String ATTRIBUTE_PARAMETER_VALUE = "at_value";
+
private static final String CONTEXT_NAME = "SeleniumAutoTestContext";
String header = "<html
xmlns=\"http://www.w3.org/1999/xhtml\" " +
@@ -54,6 +58,11 @@
writer.write(ev + "=\"EventQueue.fire('"+ev+"')\"
");
}
+ for (String attribute : context.getAttributes().keySet()) {
+ writer.write(attribute + "=\"" +
context.getAttributes().get(attribute)+"\" ");
+ }
+
+
writer.write(">");
writer.write("</" + context.getComponent() + ">");
@@ -65,12 +74,19 @@
throws ServletException, IOException {
String component = req.getParameter(COMPONENT_PARAMETER_NAME);
String [] events = req.getParameterValues(EVENT_PARAMETER_NAME);
+ String [] attributes_name = req.getParameterValues(ATTRIBUTE_PARAMETER_NAME);
+ String [] attributes_value = req.getParameterValues(ATTRIBUTE_PARAMETER_VALUE);
+
AutoTestContext context = new AutoTestContext(component);
for (String event: events) {
context.addEvent(event);
}
+ for (int i = 0; i < attributes_name.length; i++) {
+ context.addAttribute(attributes_name[i], attributes_value[i]);
+ }
+
getServletContext().setAttribute(CONTEXT_NAME, context);
resp.sendRedirect("/richfaces/faces/NEKO/pages/_autotest/autotest.xhtml");
Added:
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/SeleniumEvent.java
===================================================================
---
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/SeleniumEvent.java
(rev 0)
+++
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/SeleniumEvent.java 2008-10-06
11:41:40 UTC (rev 10668)
@@ -0,0 +1,27 @@
+package org.richfaces;
+
+public enum SeleniumEvent {
+
+ ONCLICK("onclick"),
+ ONDBCLICK("ondbclick"),
+ ONMOUSEOVER("onmouseover"),
+ ONMOUSEMOVE("onmousemove"),
+ ONMOUSEOUT("onmouseout"),
+ ONMOUSEDOWN("onmousedown"),
+ ONMOUSEUP("onmouseup"),
+ ONDRAGANDDROP("ondraganddrop"),
+ ONKEYDOWN("onkeydown"),
+ ONKEYUP("onkeyup"),
+ ONKEYPRESS("onkeypress");
+
+ private String name;
+
+ private SeleniumEvent(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ 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-03
19:09:01 UTC (rev 10667)
+++
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/SeleniumTestBase.java 2008-10-06
11:41:40 UTC (rev 10668)
@@ -23,10 +23,12 @@
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
import org.ajax4jsf.bean.Configurator;
import org.ajax4jsf.javascript.ScriptUtils;
import org.ajax4jsf.template.Template;
+import org.apache.tools.ant.types.FilterSet.OnMissing;
import org.openqa.selenium.server.RemoteControlConfiguration;
import org.openqa.selenium.server.SeleniumServer;
import org.testng.Assert;
@@ -982,16 +984,29 @@
}
}
- public void autoTest(Template template, String component, List<String> events)
{
+ 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");
waitForPageToLoad();
runScript("setComponent('"+component+"');", false);
- for (String ev : events) {
- runScript("addEvent('"+ev+"');", false);
+ List<String> assertevent = new ArrayList<String>();
+
+ for (SeleniumEvent ev : events) {
+ if (ev != SeleniumEvent.ONDRAGANDDROP) {
+ runScript("addEvent('"+ev.getName()+"');", false);
+ assertevent.add(ev.getName());
+ }else {
+ runScript("addEvent('ondrag');addEvent('ondrop');",
false);
+ assertevent.add("ondrag");
+ assertevent.add("ondrop");
+ }
}
+ for (String attr : attributes.keySet()) {
+ runScript("addAttribute('"+attr+"',
'"+attributes.get(attr)+"');", false);
+ }
+
runScript("submitForm();", false);
waitForPageToLoad();
@@ -999,13 +1014,31 @@
waitForPageToLoad();
String id = template.getPrefix() + "test";
- for (String ev : events) {
- if ("onclick".equals(ev)) {
+ for (SeleniumEvent ev : events) {
+ 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");
}
}
- assertEvents(events);
+ assertEvents(assertevent);
}
}