Author: ppitonak(a)redhat.com
Date: 2011-11-22 10:00:50 -0500 (Tue, 22 Nov 2011)
New Revision: 22973
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/model/Autocomplete.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richAutocomplete/TestAutocompleteAttributes.java
Log:
test for rich:autocomplete fixed
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/model/Autocomplete.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/model/Autocomplete.java 2011-11-22
12:18:09 UTC (rev 22972)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/model/Autocomplete.java 2011-11-22
15:00:50 UTC (rev 22973)
@@ -42,141 +42,138 @@
* @version $Revision$
*/
public class Autocomplete implements Model {
-
+
private static final String KEY_UP = "38";
private static final String KEY_DOWN = "40";
AjaxSelenium selenium = AjaxSeleniumProxy.getInstance();
JQueryLocator input = pjq("input.rf-au-inp[id$=autocompleteInput]");
-
+
JQueryLocator items = jq("div.rf-au-lst-cord[id$=autocompleteList]
div[id$=autocompleteItems]");
JQueryLocator selection = items.getDescendant(jq("div.rf-au-itm-sel"));
JQueryLocator option = jq("div.rf-au-itm");
JQueryLocator labeledOption = jq("div.rf-au-opt:contains('{0}')");
-
+
public void typeKeys(String keys) {
- for (int i = 0; i < keys.length(); i++) {
- final String key = String.valueOf(keys.charAt(i));
+ for (int i = 0; i < keys.length(); i++) {
+ final String key = String.valueOf(keys.charAt(i));
selenium.focus(input);
selenium.keyPress(input, key);
- selenium.fireEvent(input, Event.KEYDOWN);
- }
+ selenium.fireEvent(input, Event.KEYDOWN);
+ }
}
-
+
public void type(String value) {
- selenium.type(input, value);
+ selenium.type(input, value);
selenium.fireEvent(input, Event.BLUR);
}
-
+
public void confirmByKeys() {
- pressEnter();
+ selenium.fireEvent(input, Event.FOCUS);
+ pressEnter();
}
-
+
public void selectByKeys(String label) {
- int labeledIndex = getLabeledOptionIndex(label);
- while (getSelectedOptionIndex() < labeledIndex) {
+ int labeledIndex = getLabeledOptionIndex(label);
+ while (getSelectedOptionIndex() < labeledIndex) {
pressDown();
- }
- while (getSelectedOptionIndex() > labeledIndex) {
+ }
+ while (getSelectedOptionIndex() > labeledIndex) {
pressUp();
- }
+ }
}
-
+
public boolean isLabeledOptionAvailable(String label) {
- return selenium.isElementPresent(getLabeledOption(label));
+ return selenium.isElementPresent(getLabeledOption(label));
}
-
+
public int getLabeledOptionIndex(String label) {
- String index = selenium.getEval(jqScript(getLabeledOption(label),
- "index()"));
- return Integer.valueOf(index);
+ String index = selenium.getEval(jqScript(getLabeledOption(label),
"index()"));
+ return Integer.valueOf(index);
}
-
+
public int getSelectedOptionIndex() {
- JavaScript script = jqScript(option, "index({0})").parametrize(
- jqObject(selection));
- String index = selenium.getEval(script);
- return Integer.valueOf(index);
+ JavaScript script = jqScript(option,
"index({0})").parametrize(jqObject(selection));
+ String index = selenium.getEval(script);
+ return Integer.valueOf(index);
}
-
+
public String getSelectedOptionText() {
- return selenium.getText(selection);
+ return selenium.getText(selection);
}
-
+
public String getInputText() {
- return selenium.getValue(input);
+ return selenium.getValue(input);
}
-
+
public void clearInputValue() {
selenium.type(input, "");
- // selenium.fireEvent(input, Event.KEYUP);
- // selenium.fireEvent(input, Event.BLUR);
selenium.focus(input);
}
-
+
private JQueryLocator getLabeledOption(String label) {
- return labeledOption.format(label);
+ return labeledOption.format(label);
}
-
+
public void pressBackspace() {
- selenium.keyPressNative(String.valueOf(KeyEvent.VK_BACK_SPACE));
+ selenium.keyPressNative(String.valueOf(KeyEvent.VK_BACK_SPACE));
}
-
+
public void pressUp() {
- selenium.keyDown(input, KEY_UP);
+ selenium.keyDown(input, KEY_UP);
}
-
+
public void pressDown() {
- selenium.keyDown(input, KEY_DOWN);
+ selenium.keyDown(input, KEY_DOWN);
}
-
+
public void pressEnter() {
- selenium.keyDownNative(Integer.toString(KeyEvent.VK_ENTER));
+ selenium.keyPressNative(Integer.toString(KeyEvent.VK_ENTER));
}
-
+
public void pressLeft() {
- selenium.keyPressNative(String.valueOf(KeyEvent.VK_LEFT));
+ selenium.keyPressNative(String.valueOf(KeyEvent.VK_LEFT));
}
-
+
public void pressRight() {
- selenium.keyPressNative(String.valueOf(KeyEvent.VK_RIGHT));
+ selenium.keyPressNative(String.valueOf(KeyEvent.VK_RIGHT));
}
-
+
public void pressDelete() {
- selenium.keyPressNative(String.valueOf(KeyEvent.VK_DELETE));
+ selenium.keyPressNative(String.valueOf(KeyEvent.VK_DELETE));
}
-
+
public void textSelectionLeft(int size) {
- selenium.keyDownNative(String.valueOf(KeyEvent.VK_SHIFT));
- for (int i = 0; i < size; i++) {
- selenium.keyPressNative(String.valueOf(KeyEvent.VK_LEFT));
- }
- selenium.keyUpNative(String.valueOf(KeyEvent.VK_SHIFT));
+ selenium.keyDownNative(String.valueOf(KeyEvent.VK_SHIFT));
+ for (int i = 0; i < size; i++) {
+ selenium.keyPressNative(String.valueOf(KeyEvent.VK_LEFT));
+ }
+ selenium.keyUpNative(String.valueOf(KeyEvent.VK_SHIFT));
}
-
+
public void textSelectionRight(int size) {
- selenium.keyDownNative(String.valueOf(KeyEvent.VK_SHIFT));
- for (int i = 0; i < size; i++) {
- selenium.keyPressNative(String.valueOf(KeyEvent.VK_RIGHT));
- }
- selenium.keyUpNative(String.valueOf(KeyEvent.VK_SHIFT));
+ selenium.keyDownNative(String.valueOf(KeyEvent.VK_SHIFT));
+ for (int i = 0; i < size; i++) {
+ selenium.keyPressNative(String.valueOf(KeyEvent.VK_RIGHT));
+ }
+ selenium.keyUpNative(String.valueOf(KeyEvent.VK_SHIFT));
}
-
+
public void textSelectAll() {
- selenium.keyDownNative(String.valueOf(KeyEvent.VK_CONTROL));
- selenium.keyPressNative(String.valueOf(KeyEvent.VK_A));
- selenium.keyDownNative(String.valueOf(KeyEvent.VK_CONTROL));
+ selenium.keyDownNative(String.valueOf(KeyEvent.VK_CONTROL));
+ selenium.keyPressNative(String.valueOf(KeyEvent.VK_A));
+ selenium.keyDownNative(String.valueOf(KeyEvent.VK_CONTROL));
}
-
- public boolean isCompletionVisible() {
- if (!selenium.isElementPresent(items)) {
- return false;
- }
- return selenium.isVisible(items);
+
+ public boolean isCompletionVisible() {
+ if (!selenium.isElementPresent(items)) {
+ return false;
+ }
+ return selenium.isVisible(items);
}
-
+
public void waitForCompletionVisible() {
- WAIT_GUI.until(ELEMENT_PRESENT.locator(option));
+ WAIT_GUI.until(ELEMENT_PRESENT.locator(option));
}
}
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richAutocomplete/TestAutocompleteAttributes.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richAutocomplete/TestAutocompleteAttributes.java 2011-11-22
12:18:09 UTC (rev 22972)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richAutocomplete/TestAutocompleteAttributes.java 2011-11-22
15:00:50 UTC (rev 22973)
@@ -37,6 +37,7 @@
private static final JQueryLocator PHASE_FORMAT = jq("div#phasesPanel
li:eq({0})");
private static final String PHASE_LISTENER_LOG_FORMAT = "*1 value changed: {0}
-> {1}";
+
@Override
public URL getTestUrl() {
return buildUrl(contextPath,
"faces/components/richAutocomplete/autocomplete.xhtml");
@@ -44,23 +45,25 @@
@Test
public void testValueChangeListener() {
- getAutocomplete().type("something");
+ getAutocomplete().typeKeys("something");
getAutocomplete().confirmByKeys();
// valueChangeListener output as 4th record
- waitGui
- .failWith("Expected <" + format(PHASE_LISTENER_LOG_FORMAT,
"null", "something") + ">, found <" +
selenium.getText(PHASE_FORMAT.format(3)) + ">")
- .until(textEquals.locator(PHASE_FORMAT.format(3)).text(
- format(PHASE_LISTENER_LOG_FORMAT, "null",
"something"))
- );
-
- getAutocomplete().type("something else");
+ waitFor(2000);
+ waitGui.failWith(
+ "Expected <" + format(PHASE_LISTENER_LOG_FORMAT,
"null", "something") + ">, found <"
+ + selenium.getText(PHASE_FORMAT.format(3)) + ">").until(
+
textEquals.locator(PHASE_FORMAT.format(3)).text(format(PHASE_LISTENER_LOG_FORMAT,
"null", "something")));
+
+ getAutocomplete().clearInputValue();
+ getAutocomplete().typeKeys("something else");
getAutocomplete().confirmByKeys();
// valueChangeListener output as 4th record
- waitGui
- .failWith("Expected <" + format(PHASE_LISTENER_LOG_FORMAT,
"something", "something else") + ">, found <" +
selenium.getText(PHASE_FORMAT.format(3)) + ">")
- .until(textEquals.locator(PHASE_FORMAT.format(3)).text(
- format(PHASE_LISTENER_LOG_FORMAT, "something", "something
else"))
- );
+ waitFor(2000);
+ waitGui.failWith(
+ "Expected <" + format(PHASE_LISTENER_LOG_FORMAT,
"something", "something else") + ">, found <"
+ + selenium.getText(PHASE_FORMAT.format(3)) + ">").until(
+ textEquals.locator(PHASE_FORMAT.format(3)).text(
+ format(PHASE_LISTENER_LOG_FORMAT, "something", "something
else")));
}
-
+
}