Author: jpapouse
Date: 2012-01-10 05:16:49 -0500 (Tue, 10 Jan 2012)
New Revision: 23136
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richHotKey/AbstractRichHotKeyTest.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richHotKey/HotKeyAttributes.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richHotKey/TestRichHotKey.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richHotKey/TestRichHotKeyAttributes.java
Log:
fixed tests for rich:hotKey
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richHotKey/AbstractRichHotKeyTest.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richHotKey/AbstractRichHotKeyTest.java 2012-01-10
09:38:24 UTC (rev 23135)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richHotKey/AbstractRichHotKeyTest.java 2012-01-10
10:16:49 UTC (rev 23136)
@@ -24,6 +24,8 @@
import static org.jboss.test.selenium.utils.text.SimplifiedFormat.format;
import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
import org.jboss.test.selenium.locator.JQueryLocator;
import org.jboss.test.selenium.utils.URLUtils;
@@ -46,7 +48,8 @@
protected static final JQueryLocator INPUT_2 = pjq(INPUT_2_LOCATOR);
private static final JQueryLocator CLEAR_BUTTON =
pjq("button.rf-log-element");
- private static final String HOT_KEY_EVENT_LOCATOR =
"span.rf-log-entry-msg-info:contains({0})";
+ private static final String HOT_KEY_EVENT_LOCATOR_WITH_CONTENT =
"span.rf-log-entry-msg-info:contains({0})";
+ private static final String HOT_KEY_EVENT_LOCATOR_WITH_ORDER =
"span.rf-log-entry-msg-info:eq({0})";
@Override
public URL getTestUrl() {
@@ -55,15 +58,24 @@
protected void checkEvent(String text, int number) {
waitGui
- .failWith("The number of hotkey events doesn't match. Found
<" + selenium.getCount(pjq(format(HOT_KEY_EVENT_LOCATOR, text))) + ">,
expected <" + number + ">.")
- .until(countEquals.locator(pjq(format(HOT_KEY_EVENT_LOCATOR,
text))).count(number));
+ .failWith("The number of hotkey events doesn't match. Found
<" + selenium.getCount(pjq(format(HOT_KEY_EVENT_LOCATOR_WITH_CONTENT, text))) +
">, expected <" + number + ">.")
+ .until(countEquals.locator(pjq(format(HOT_KEY_EVENT_LOCATOR_WITH_CONTENT,
text))).count(number));
}
protected void clearHotKeyEvents() {
selenium.click(CLEAR_BUTTON);
-
waitGui.until(NegationCondition.getInstance().condition(elementPresent.locator(pjq(format(HOT_KEY_EVENT_LOCATOR,
"''")))));
+
waitGui.until(NegationCondition.getInstance().condition(elementPresent.locator(pjq(format(HOT_KEY_EVENT_LOCATOR_WITH_CONTENT,
"''")))));
}
+ protected List<String> getEvents() {
+ List<String> events = new ArrayList<String>();
+ int eventsCount =
selenium.getCount(pjq(format(HOT_KEY_EVENT_LOCATOR_WITH_CONTENT,
"''")));
+ for (int i=0; i<eventsCount; i++) {
+ events.add(selenium.getText(pjq(format(HOT_KEY_EVENT_LOCATOR_WITH_ORDER,
String.valueOf(i)))));
+ }
+ return events;
+ }
+
protected static final Attributes<HotKeyAttributes> ATTRIBUTES_FIRST = new
Attributes<HotKeyAttributes>(pjq("table.attributes[id$=attributes1]"));
protected static final Attributes<HotKeyAttributes> ATTRIBUTES_SECOND = new
Attributes<HotKeyAttributes>(pjq("table.attributes[id$=attributes2]"));
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richHotKey/HotKeyAttributes.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richHotKey/HotKeyAttributes.java 2012-01-10
09:38:24 UTC (rev 23135)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richHotKey/HotKeyAttributes.java 2012-01-10
10:16:49 UTC (rev 23136)
@@ -30,8 +30,9 @@
enabledInInput,
key,
+ onkeydown,
+ onkeyup,
rendered,
- selector,
- type
+ selector
}
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richHotKey/TestRichHotKey.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richHotKey/TestRichHotKey.java 2012-01-10
09:38:24 UTC (rev 23135)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richHotKey/TestRichHotKey.java 2012-01-10
10:16:49 UTC (rev 23136)
@@ -21,12 +21,8 @@
*******************************************************************************/
package org.richfaces.tests.metamer.ftest.richHotKey;
-import static org.jboss.test.selenium.utils.text.SimplifiedFormat.format;
-
import java.awt.event.KeyEvent;
-import org.jboss.test.selenium.locator.JQueryLocator;
-import org.jboss.test.selenium.waiting.NegationCondition;
import org.testng.annotations.Test;
/**
@@ -51,9 +47,9 @@
selenium.keyPressNative(String.valueOf(KeyEvent.VK_X));
selenium.keyUpNative(String.valueOf(KeyEvent.VK_ALT));
}
- checkEvent("hotkey 1", i);
- checkEvent("hotkey 2", i);
- checkEvent("''", 2 * i);
+ checkEvent("hotkey 1 : onkeydown", i);
+ checkEvent("hotkey 2 : onkeydown", i);
+ checkEvent("'onkeydown'", 2 * i);
clearHotKeyEvents();
}
}
@@ -66,24 +62,22 @@
selenium.keyPressNative(String.valueOf(KeyEvent.VK_X));
selenium.keyPressNative(String.valueOf(KeyEvent.VK_A));
}
- checkEvent("hotkey 1", i);
- checkEvent("''", i);
+ checkEvent("hotkey 1 : onkeydown", i);
+ checkEvent("onkeydown", i);
clearHotKeyEvents();
}
}
@Test
public void testFirstPair() {
- testPair(KeyEvent.VK_CONTROL, KeyEvent.VK_X, "hotkey 1");
+ testPair(KeyEvent.VK_CONTROL, KeyEvent.VK_X, "hotkey 1 : onkeydown");
}
@Test
public void testSecondPair() {
- testPair(KeyEvent.VK_ALT, KeyEvent.VK_X, "hotkey 2");
+ testPair(KeyEvent.VK_ALT, KeyEvent.VK_X, "hotkey 2 : onkeydown");
}
-
-
private void testPair(int firstKey, int secondKey, String text) {
for (int i=1; i<=NUMBER_OF_TESTS; i++) {
for (int j=0; j<i; j++) {
@@ -94,7 +88,7 @@
selenium.keyUpNative(String.valueOf(firstKey));
}
checkEvent(text, i);
- checkEvent("''", i);
+ checkEvent("onkeydown", i);
clearHotKeyEvents();
}
}
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richHotKey/TestRichHotKeyAttributes.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richHotKey/TestRichHotKeyAttributes.java 2012-01-10
09:38:24 UTC (rev 23135)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richHotKey/TestRichHotKeyAttributes.java 2012-01-10
10:16:49 UTC (rev 23136)
@@ -21,9 +21,11 @@
*******************************************************************************/
package org.richfaces.tests.metamer.ftest.richHotKey;
+import static org.testng.Assert.assertEquals;
+
import java.awt.event.KeyEvent;
+import java.util.List;
-import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
@@ -32,21 +34,13 @@
*/
public class TestRichHotKeyAttributes extends AbstractRichHotKeyTest {
- @AfterMethod
- public void tearDown() {
- selenium.keyUpNative(String.valueOf(KeyEvent.VK_CONTROL));
- selenium.keyUpNative(String.valueOf(KeyEvent.VK_ALT));
- selenium.keyUpNative(String.valueOf(KeyEvent.VK_M));
- selenium.keyUpNative(String.valueOf(KeyEvent.VK_X));
- }
-
@Test
public void enabledInInput() {
ATTRIBUTES_FIRST.set(HotKeyAttributes.key, "x");
// true
selenium.focus(INPUT_1);
selenium.keyPressNative(String.valueOf(KeyEvent.VK_X));
- checkEvent("hotkey 1", 1);
+ checkEvent("hotkey 1", 2);
clearHotKeyEvents();
// false
ATTRIBUTES_FIRST.set(HotKeyAttributes.enabledInInput, false);
@@ -54,6 +48,16 @@
selenium.keyPressNative(String.valueOf(KeyEvent.VK_X));
checkEvent("hotkey 1", 0);
}
+
+ @Test
+ public void testOnkeydownAndOnkeyup() {
+ ATTRIBUTES_FIRST.set(HotKeyAttributes.key, "x");
+ selenium.keyPressNative(String.valueOf(KeyEvent.VK_X));
+ checkEvent("hotkey 1", 2);
+ List<String> events = getEvents();
+ assertEquals(events.get(0), "hotkey 1 : onkeydown");
+ assertEquals(events.get(1), "hotkey 1 : onkeyup");
+ }
@Test
public void testRendered() {
@@ -74,71 +78,7 @@
checkEvent("hotkey 1", 0);
selenium.focus(INPUT_1);
selenium.keyPressNative(String.valueOf(KeyEvent.VK_X));
- checkEvent("hotkey 1", 1);
+ checkEvent("hotkey 1", 2);
}
- @Test
- public void testTypeKeydownOne() {
- testTypeOne("keydown", 3, KeyEvent.VK_CONTROL, "ctrl");
- }
-
- @Test
- public void testTypeKeydownPair() {
- testTypePair("keydown", 3, KeyEvent.VK_ALT, KeyEvent.VK_CONTROL,
"alt+ctrl");
- }
-
- @Test
- public void testTypeKeypressOne() {
- testTypeOne("keypress", 0, KeyEvent.VK_CONTROL, "ctrl");
- tearDown();
- testTypeOne("keypress", 3, KeyEvent.VK_X, "x");
- }
-
- @Test
- public void testTypeKeypressPair() {
- testTypePair("keypress", 3, KeyEvent.VK_CONTROL, KeyEvent.VK_X,
"ctrl+x");
- }
-
- @Test
- public void testTypeKeyupOne() {
- testTypeOne("keyup", 2, KeyEvent.VK_CONTROL, "ctrl");
- }
-
- @Test
- public void testTypeKeyupPair() {
- testTypePair("keyup", 2, KeyEvent.VK_ALT, KeyEvent.VK_CONTROL,
"alt+ctrl");
- }
-
- private void processOneKeySequence(int correctKey, int wrongKey) {
- selenium.keyDownNative(String.valueOf(correctKey));
- selenium.keyDownNative(String.valueOf(wrongKey));
- selenium.keyUpNative(String.valueOf(correctKey));
- selenium.keyUpNative(String.valueOf(wrongKey));
- selenium.keyPressNative(String.valueOf(correctKey));
- selenium.keyPressNative(String.valueOf(wrongKey));
- selenium.keyDownNative(String.valueOf(correctKey));
- selenium.keyDownNative(String.valueOf(wrongKey));
- }
-
- private void processPairKeySequence(int firstKey, int secondCorrectKey, int
secondWrongKey) {
- selenium.keyDownNative(String.valueOf(firstKey));
- processOneKeySequence(secondCorrectKey, secondWrongKey);
- }
-
- private void testTypeOne(String event, int number, int correctKeyCode, String
correctKeyName) {
- ATTRIBUTES_FIRST.set(HotKeyAttributes.key, correctKeyName);
- ATTRIBUTES_FIRST.set(HotKeyAttributes.type, event);
- processOneKeySequence(correctKeyCode, KeyEvent.VK_M);
- checkEvent("hotkey 1", number);
- clearHotKeyEvents();
- }
-
- private void testTypePair(String event, int number, int firstCorrectKeyCode, int
secondCorrectKeyCode, String keyNames) {
- ATTRIBUTES_FIRST.set(HotKeyAttributes.key, keyNames);
- ATTRIBUTES_FIRST.set(HotKeyAttributes.type, event);
- processPairKeySequence(firstCorrectKeyCode, secondCorrectKeyCode,
KeyEvent.VK_M);
- checkEvent("hotkey 1", number);
- clearHotKeyEvents();
- }
-
}