Author: konstantin.mishin
Date: 2008-10-29 10:36:58 -0400 (Wed, 29 Oct 2008)
New Revision: 10964
Added:
trunk/test-applications/seleniumTest/richfaces/src/main/resources/script/
trunk/test-applications/seleniumTest/richfaces/src/main/resources/script/selenium/
trunk/test-applications/seleniumTest/richfaces/src/main/resources/script/selenium/user-extensions.js
Modified:
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/SeleniumTestBase.java
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/ListShuttleTest.java
Log:
keyboard navigation works for component
Added:
trunk/test-applications/seleniumTest/richfaces/src/main/resources/script/selenium/user-extensions.js
===================================================================
---
trunk/test-applications/seleniumTest/richfaces/src/main/resources/script/selenium/user-extensions.js
(rev 0)
+++
trunk/test-applications/seleniumTest/richfaces/src/main/resources/script/selenium/user-extensions.js 2008-10-29
14:36:58 UTC (rev 10964)
@@ -0,0 +1,49 @@
+IEBrowserBot.prototype._fireEventOnElement = function(eventType, element, clientX,
clientY) {
+ var win = this.getCurrentWindow();
+ triggerEvent(element, 'focus', false);
+
+ var wasChecked = element.checked;
+
+ // Set a flag that records if the page will unload - this isn't always accurate,
because
+ // <a href="javascript:alert('foo'):"> triggers the
onbeforeunload event, even thought the page won't unload
+ var pageUnloading = false;
+ var pageUnloadDetector = function() {
+ pageUnloading = true;
+ };
+ win.attachEvent("onbeforeunload", pageUnloadDetector);
+ this._modifyElementTarget(element);
+ if (element[eventType] && !this.controlKeyDown && !this.altKeyDown
&& !this.shiftKeyDown && !this.metaKeyDown) {
+ element[eventType]();
+ }
+ else {
+ this.browserbot.triggerMouseEvent(element, eventType, true, clientX, clientY);
+ }
+
+
+ // If the page is going to unload - still attempt to fire any subsequent events.
+ // However, we can't guarantee that the page won't unload half way through,
so we need to handle exceptions.
+ try {
+ win.detachEvent("onbeforeunload", pageUnloadDetector);
+
+ if (this._windowClosed(win)) {
+ return;
+ }
+
+ // Onchange event is not triggered automatically in IE.
+ if (isDefined(element.checked) && wasChecked != element.checked) {
+ triggerEvent(element, 'change', true);
+ }
+
+ }
+ catch (e) {
+ // If the page is unloading, we may get a "Permission denied" or
"Unspecified error".
+ // Just ignore it, because the document may have unloaded.
+ if (pageUnloading) {
+ LOG.logHook = function() {
+ };
+ LOG.warn("Caught exception when firing events on unloading page: "
+ e.message);
+ return;
+ }
+ throw e;
+ }
+};
\ No newline at end of file
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-29
12:07:43 UTC (rev 10963)
+++
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/SeleniumTestBase.java 2008-10-29
14:36:58 UTC (rev 10964)
@@ -21,6 +21,7 @@
package org.richfaces;
+import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -115,6 +116,7 @@
public void startSeleniumServer() throws Exception {
RemoteControlConfiguration config = new RemoteControlConfiguration();
config.setMultiWindow(false);
+ config.setUserExtensions(new
File(getClass().getClassLoader().getResource("script/selenium/user-extensions.js").toURI()));
seleniumServer = new SeleniumServer(false, config);
seleniumServer.start();
}
Modified:
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/ListShuttleTest.java
===================================================================
---
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/ListShuttleTest.java 2008-10-29
12:07:43 UTC (rev 10963)
+++
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/ListShuttleTest.java 2008-10-29
14:36:58 UTC (rev 10964)
@@ -111,6 +111,36 @@
}
/**
+ * keyboard navigation works for component
+ */
+ @Test
+ public void testHTMLKeyboardNavigation(Template template) {
+ init(template);
+ _selectItem(parentId + "ls:0", true, false);
+ _selectItem(parentId + "ls:1", true, false);
+ _selectItem(parentId + "ls:2", true, false);
+ _selectItem(parentId + "ls:4", true, false);
+ _selectItem(parentId + "ls:1", true, false);
+ clickById(copyId);
+ _assertTableRowsCount(targetListId, 3);
+ clickById(removeAllId);
+
+ _selectItem(parentId + "ls:1", false, false);
+ _selectItem(parentId + "ls:0", false, true);
+ clickById(copyId);
+ _assertTableRowsCount(targetListId, 3);
+ clickById(removeAllId);
+
+ _selectItem(parentId + "ls:0", false, false);
+ selenium.controlKeyDown();
+ selenium.keyDown("id=" + lsId + "focusKeeper",
"A");
+ selenium.controlKeyUp();
+ clickById(copyId);
+ _assertTableRowsCount(targetListId, 5);
+ clickById(removeAllId);
+ }
+
+ /**
* style and classes, standard HTML attributes are output to client
*/
@Test
@@ -144,14 +174,14 @@
_assertTableRowsCount(sourceSelectionTableId, 0);
_assertTableRowsCount(targetSelectionTableId, 0);
- _selectItem(parentId + "ls:0", true);
- _selectItem(parentId + "ls:2", true);
+ _selectItem(parentId + "ls:0", true, false);
+ _selectItem(parentId + "ls:2", true, false);
clickById(copyId);
- _selectItem(parentId + "ls:1", true);
- _selectItem(parentId + "ls:3", true);
- _selectItem(parentId + "ls:0", true);
+ _selectItem(parentId + "ls:1", true, false);
+ _selectItem(parentId + "ls:3", true, false);
+ _selectItem(parentId + "ls:0", true, false);
clickAjaxCommandAndWait(submitId);
@@ -520,10 +550,22 @@
}
}
- private void _selectItem(String itemId, boolean ctrl) {
+ private void _selectItem(String itemId, boolean ctrl, boolean shift) {
writeStatus("Select item id: " + itemId);
try {
- fireMouseEvent(itemId, "click", 0, 0, ctrl);
+ if (ctrl) {
+ selenium.controlKeyDown();
+ }
+ if (shift) {
+ selenium.shiftKeyDown();
+ }
+ selenium.click("id=" + itemId);
+ if (ctrl) {
+ selenium.controlKeyUp();
+ }
+ if (shift) {
+ selenium.shiftKeyUp();
+ }
} catch (Exception e) {
writeStatus("Selection item id: " + itemId + "
failed.");
Assert.fail("No item was found. Item id: " + itemId + e);
@@ -531,7 +573,7 @@
}
private void _selectItem(String itemId) {
- _selectItem(itemId, false);
+ _selectItem(itemId, false, false);
}
private void _checkItemText(String text, String listId, int i) {