Author: jpapouse
Date: 2011-08-17 07:25:52 -0400 (Wed, 17 Aug 2011)
New Revision: 22638
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/jboss/test/selenium/waiting/TextContainsCondition.java
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richSelect/TestSelectWithJSR303.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richSelect/TestSelectsWithJSR303.java
Log:
fixed JSR 303 selenium tests for rich:select component to accept messages from myfaces
(are prefixed by form input identifier)
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/jboss/test/selenium/waiting/TextContainsCondition.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/jboss/test/selenium/waiting/TextContainsCondition.java
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/jboss/test/selenium/waiting/TextContainsCondition.java 2011-08-17
11:25:52 UTC (rev 22638)
@@ -0,0 +1,125 @@
+package org.jboss.test.selenium.waiting;
+
+import static org.apache.commons.lang.StringEscapeUtils.escapeJavaScript;
+import static org.jboss.test.selenium.encapsulated.JavaScript.js;
+import static org.jboss.test.selenium.utils.text.SimplifiedFormat.format;
+
+import org.apache.commons.lang.Validate;
+import org.jboss.test.selenium.encapsulated.JavaScript;
+import org.jboss.test.selenium.framework.AjaxSelenium;
+import org.jboss.test.selenium.framework.AjaxSeleniumProxy;
+import org.jboss.test.selenium.locator.ElementLocator;
+import org.jboss.test.selenium.waiting.ajax.JavaScriptCondition;
+import org.jboss.test.selenium.waiting.conditions.TextEquals;
+import org.jboss.test.selenium.waiting.selenium.SeleniumCondition;
+
+/**
+ *
+ * <p>
+ * Implementation of Condition for waiting if element given by elementLocator has text
containing the given text.
+ * </p>
+ *
+ * <p>
+ * Implements Condition and JavaScriptCondition used in SeleniumWaiting and AjaxWaiting.
+ * </p>
+ *
+ * @author <a href="mailto:jpapouse@redhat.com">Jan Papousek</a>
+ * @version $Revision$
+ */
+public class TextContainsCondition implements SeleniumCondition, JavaScriptCondition {
+
+ /**
+ * Proxy to local selenium instance
+ */
+ private AjaxSelenium selenium = AjaxSeleniumProxy.getInstance();
+
+ /** The element locator. */
+ private ElementLocator<?> elementLocator;
+
+ /** The text. */
+ private String text;
+
+ /**
+ * Instantiates a new text equals.
+ */
+ protected TextContainsCondition() {
+ }
+
+
+ @Override
+ public JavaScript getJavaScriptCondition() {
+ String escapedLocator = escapeJavaScript(this.elementLocator.getAsString());
+ String escapedText = escapeJavaScript(this.text);
+ return js(format("selenium.isElementPresent('{0}') &&
(selenium.getText('{0}').indexOf('{1}') != -1)", escapedLocator,
+ escapedText));
+ }
+
+ /**
+ * Factory method.
+ *
+ * @return single instance of TextContainsCondition
+ */
+ public static TextContainsCondition getInstance() {
+ return new TextContainsCondition();
+ }
+
+ @Override
+ public boolean isTrue() {
+ Validate.notNull(elementLocator);
+ Validate.notNull(text);
+ return selenium.getText(elementLocator).contains(text);
+ }
+
+ /**
+ * <p>
+ * Returns the TextContainsCondition instance with given elementLocator set.
+ * </p>
+ *
+ * <p>
+ * From this locator will be obtained the text.
+ * </p>
+ *
+ * @param elementLocator
+ * the element locator
+ * @return the TextContainsCondition object with preset locator
+ */
+ public TextContainsCondition locator(ElementLocator<?> elementLocator) {
+ Validate.notNull(elementLocator);
+
+ TextContainsCondition copy = copy();
+ copy.elementLocator = elementLocator;
+
+ return copy;
+ }
+
+ /**
+ * <p>
+ * Returns the TextContainsCondition instance with text set.
+ * </p>
+ *
+ * @param text
+ * it should wait for the containg
+ * @return the TextContainsCondition object with preset text
+ */
+ public TextContainsCondition text(String text) {
+ Validate.notNull(text);
+
+ TextContainsCondition copy = copy();
+ copy.text = text;
+
+ return copy;
+ }
+
+ /**
+ * Returns the exact copy of this ElementPresent object.
+ *
+ * @return the copy of this TextContainsCondition object
+ */
+ private TextContainsCondition copy() {
+ TextContainsCondition copy = new TextContainsCondition();
+ copy.elementLocator = elementLocator;
+ copy.text = text;
+ return copy;
+ }
+
+}
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richSelect/TestSelectWithJSR303.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richSelect/TestSelectWithJSR303.java 2011-08-17
08:07:59 UTC (rev 22637)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richSelect/TestSelectWithJSR303.java 2011-08-17
11:25:52 UTC (rev 22638)
@@ -24,6 +24,7 @@
import java.net.URL;
import org.jboss.test.selenium.utils.URLUtils;
+import org.richfaces.tests.metamer.ftest.annotations.IssueTracking;
import org.testng.annotations.Test;
/**
@@ -60,6 +61,7 @@
}
@Test
+ @IssueTracking("https://issues.jboss.org/browse/RF-11264")
public void testAllInputsWrong() {
verifyAllInputsWrong();
}
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richSelect/TestSelectsWithJSR303.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richSelect/TestSelectsWithJSR303.java 2011-08-17
08:07:59 UTC (rev 22637)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richSelect/TestSelectsWithJSR303.java 2011-08-17
11:25:52 UTC (rev 22638)
@@ -26,6 +26,7 @@
import org.jboss.test.selenium.dom.Event;
import org.jboss.test.selenium.locator.Attribute;
import org.jboss.test.selenium.locator.JQueryLocator;
+import org.jboss.test.selenium.waiting.TextContainsCondition;
import org.richfaces.tests.metamer.ftest.AbstractMetamerTest;
/**
@@ -99,9 +100,13 @@
selenium.click(notEmptySelect.getDescendant(optionEmpty));
selenium.fireEvent(notEmptyInput, Event.BLUR);
// give selenium time set new value to appropriate field before submit
- waitGui.until(textEquals.locator(input1Msg).text(NOT_EMPTY_VALIDATION_MSG));
+ waitGui
+ .failWith("After selecting empty value, the correct message is not
displayed.")
+
.until(TextContainsCondition.getInstance().locator(input1Msg).text(NOT_EMPTY_VALIDATION_MSG));
selenium.click(a4jCommandButton);
- waitAjax.until(textEquals.locator(input1Msg).text(NOT_EMPTY_VALIDATION_MSG));
+ waitGui
+ .failWith("After submitting (a4j:commandButton) empty value, the correct
message is not displayed.")
+
.until(TextContainsCondition.getInstance().locator(input1Msg).text(NOT_EMPTY_VALIDATION_MSG));
setAllCorrect();
@@ -109,10 +114,14 @@
selenium.click(notEmptySelect.getDescendant(optionEmpty));
selenium.fireEvent(notEmptyInput, Event.BLUR);
// give selenium time set new value to appropriate field before submit
- waitGui.until(textEquals.locator(input1Msg).text(NOT_EMPTY_VALIDATION_MSG));
+ waitGui
+ .failWith("After selecting empty value, the correct message is not
displayed.")
+
.until(TextContainsCondition.getInstance().locator(input1Msg).text(NOT_EMPTY_VALIDATION_MSG));
selenium.click(hCommandButton);
selenium.waitForPageToLoad();
- waitGui.until(textEquals.locator(input1Msg).text(NOT_EMPTY_VALIDATION_MSG));
+ waitGui
+ .failWith("After submitting (h:commandButton) empty value, the correct
message is not displayed.")
+
.until(TextContainsCondition.getInstance().locator(input1Msg).text(NOT_EMPTY_VALIDATION_MSG));
}
protected void verifyRegExpPattern() {
@@ -122,9 +131,13 @@
selenium.click(regExpPatternSelect.getDescendant(option.format(WRONG_REG_EXP)));
selenium.fireEvent(regExpPatternInput, Event.BLUR);
// give selenium time set new value to appropriate field before submit
- waitGui.until(textEquals.locator(input2Msg).text(REGEXP_VALIDATION_MSG));
+ waitGui
+ .failWith("After selecting value which doesn't match the given
REGEXP, the correct message is not displayed.")
+
.until(TextContainsCondition.getInstance().locator(input2Msg).text(REGEXP_VALIDATION_MSG));
selenium.click(a4jCommandButton);
- waitGui.until(textEquals.locator(input2Msg).text(REGEXP_VALIDATION_MSG));
+ waitGui
+ .failWith("After submitting (a4j:commandButton) value which doesn't
match the given REGEXP, the correct message is not displayed.")
+
.until(TextContainsCondition.getInstance().locator(input2Msg).text(REGEXP_VALIDATION_MSG));
setAllCorrect();
@@ -132,10 +145,14 @@
selenium.click(regExpPatternSelect.getDescendant(option.format(WRONG_REG_EXP)));
selenium.fireEvent(regExpPatternInput, Event.BLUR);
// give selenium time set new value to appropriate field before submit
- waitGui.until(textEquals.locator(input2Msg).text(REGEXP_VALIDATION_MSG));
+ waitGui
+ .failWith("After selecting value which doesn't match the given
REGEXP, the correct message is not displayed.")
+
.until(TextContainsCondition.getInstance().locator(input2Msg).text(REGEXP_VALIDATION_MSG));
selenium.click(hCommandButton);
selenium.waitForPageToLoad();
- waitGui.until(textEquals.locator(input2Msg).text(REGEXP_VALIDATION_MSG));
+ waitGui
+ .failWith("After submitting (h:commandButton) value which doesn't
match the given REGEXP, the correct message is not displayed.")
+
.until(TextContainsCondition.getInstance().locator(input2Msg).text(REGEXP_VALIDATION_MSG));
}
protected void verifyStringSize() {
@@ -145,9 +162,13 @@
selenium.click(stringSizeSelect.getDescendant(option.format(WRONG_STRING_SIZE)));
selenium.fireEvent(stringSizeInput, Event.BLUR);
// give selenium time set new value to appropriate field before submit
- waitGui.until(textEquals.locator(input3Msg).text(STRING_SIZE_VALIDATION_MSG));
+ waitGui
+ .failWith("After selecting string with wrong size, the correct message
is not displayed.")
+
.until(TextContainsCondition.getInstance().locator(input3Msg).text(STRING_SIZE_VALIDATION_MSG));
selenium.click(a4jCommandButton);
- waitGui.until(textEquals.locator(input3Msg).text(STRING_SIZE_VALIDATION_MSG));
+ waitGui
+ .failWith("After submitting (a4j:commandButton) string with wrong size,
the correct message is not displayed.")
+
.until(TextContainsCondition.getInstance().locator(input3Msg).text(STRING_SIZE_VALIDATION_MSG));
setAllCorrect();
@@ -155,10 +176,14 @@
selenium.click(stringSizeSelect.getDescendant(option.format(WRONG_STRING_SIZE)));
selenium.fireEvent(stringSizeInput, Event.BLUR);
// give selenium time set new value to appropriate field before submit
- waitGui.until(textEquals.locator(input3Msg).text(STRING_SIZE_VALIDATION_MSG));
+ waitGui
+ .failWith("After selecting string with wrong size, the correct message
is not displayed.")
+
.until(TextContainsCondition.getInstance().locator(input3Msg).text(STRING_SIZE_VALIDATION_MSG));
selenium.click(hCommandButton);
selenium.waitForPageToLoad();
- waitGui.until(textEquals.locator(input3Msg).text(STRING_SIZE_VALIDATION_MSG));
+ waitGui
+ .failWith("After submitting (h:commandButton) string with wrong size,
the correct message is not displayed.")
+
.until(TextContainsCondition.getInstance().locator(input3Msg).text(STRING_SIZE_VALIDATION_MSG));
}
protected void verifyCustomString() {
@@ -168,9 +193,13 @@
selenium.click(customStringSelect.getDescendant(option.format(WRONG_CUSTOM_STRING)));
selenium.fireEvent(customStringInput, Event.BLUR);
// give selenium time set new value to appropriate field before submit
- waitGui.until(textEquals.locator(input4Msg).text(CUSTOM_STRING_VALIDATION_MSG));
+ waitGui
+ .failWith("After selecting value which doesn't match the given
string ('RichFaces'), the correct message is not displayed.")
+
.until(TextContainsCondition.getInstance().locator(input4Msg).text(CUSTOM_STRING_VALIDATION_MSG));
selenium.click(a4jCommandButton);
- waitGui.until(textEquals.locator(input4Msg).text(CUSTOM_STRING_VALIDATION_MSG));
+ waitGui
+ .failWith("After submitting (a4j:commandButton) value which doesn't
match the given string ('RichFaces'), the correct message is not
displayed.")
+
.until(TextContainsCondition.getInstance().locator(input4Msg).text(CUSTOM_STRING_VALIDATION_MSG));
setAllCorrect();
@@ -178,31 +207,50 @@
selenium.click(customStringSelect.getDescendant(option.format(WRONG_CUSTOM_STRING)));
selenium.fireEvent(customStringInput, Event.BLUR);
// give selenium time set new value to appropriate field before submit
- waitGui.until(textEquals.locator(input4Msg).text(CUSTOM_STRING_VALIDATION_MSG));
+ waitGui
+ .failWith("After selecting value which doesn't match the given
string ('RichFaces'), the correct message is not displayed.")
+
.until(TextContainsCondition.getInstance().locator(input4Msg).text(CUSTOM_STRING_VALIDATION_MSG));
selenium.click(hCommandButton);
selenium.waitForPageToLoad();
- waitGui.until(textEquals.locator(input4Msg).text(CUSTOM_STRING_VALIDATION_MSG));
+ waitGui
+ .failWith("After submitting (h:commandButton) value which doesn't
match the given string ('RichFaces'), the correct message is not
displayed.")
+
.until(TextContainsCondition.getInstance().locator(input4Msg).text(CUSTOM_STRING_VALIDATION_MSG));
}
protected void verifyAllInputsWrong() {
setAllCorrect();
setAllWrong();
selenium.click(a4jCommandButton);
+ waitGui
+ .failWith("After submitting (a4j:commandButton) empty value, the correct
message is not displayed.")
+
.until(TextContainsCondition.getInstance().locator(input1Msg).text(NOT_EMPTY_VALIDATION_MSG));
+ waitGui
+ .failWith("After submitting (a4j:commandButton) value which doesn't
match the given REGEXP, the correct message is not displayed.")
+
.until(TextContainsCondition.getInstance().locator(input2Msg).text(REGEXP_VALIDATION_MSG));
+ waitGui
+ .failWith("After submitting (a4j:commandButton) string with wrong size,
the correct message is not displayed.")
+
.until(TextContainsCondition.getInstance().locator(input3Msg).text(STRING_SIZE_VALIDATION_MSG));
+ waitGui
+ .failWith("After submitting (a4j:commandButton) value which doesn't
match the given string ('RichFaces'), the correct message is not
displayed.")
+
.until(TextContainsCondition.getInstance().locator(input4Msg).text(CUSTOM_STRING_VALIDATION_MSG));
- waitGui.until(textEquals.locator(input1Msg).text(NOT_EMPTY_VALIDATION_MSG));
- waitGui.until(textEquals.locator(input2Msg).text(REGEXP_VALIDATION_MSG));
- waitGui.until(textEquals.locator(input3Msg).text(STRING_SIZE_VALIDATION_MSG));
- waitGui.until(textEquals.locator(input4Msg).text(CUSTOM_STRING_VALIDATION_MSG));
-
setAllCorrect();
setAllWrong();
selenium.click(hCommandButton);
selenium.waitForPageToLoad();
- waitGui.until(textEquals.locator(input1Msg).text(NOT_EMPTY_VALIDATION_MSG));
- waitGui.until(textEquals.locator(input2Msg).text(REGEXP_VALIDATION_MSG));
- waitGui.until(textEquals.locator(input3Msg).text(STRING_SIZE_VALIDATION_MSG));
- waitGui.until(textEquals.locator(input4Msg).text(CUSTOM_STRING_VALIDATION_MSG));
+ waitGui
+ .failWith("After submitting (h:commandButton) empty value, the correct
message is not displayed.")
+
.until(TextContainsCondition.getInstance().locator(input1Msg).text(NOT_EMPTY_VALIDATION_MSG));
+ waitGui
+ .failWith("After submitting (h:commandButton) value which doesn't
match the given REGEXP, the correct message is not displayed.")
+
.until(TextContainsCondition.getInstance().locator(input2Msg).text(REGEXP_VALIDATION_MSG));
+ waitGui
+ .failWith("After submitting (h:commandButton) string with wrong size,
the correct message is not displayed.")
+
.until(TextContainsCondition.getInstance().locator(input3Msg).text(STRING_SIZE_VALIDATION_MSG));
+ waitGui
+ .failWith("After submitting (h:commandButton) value which doesn't
match the given string ('RichFaces'), the correct message is not
displayed.")
+
.until(TextContainsCondition.getInstance().locator(input4Msg).text(CUSTOM_STRING_VALIDATION_MSG));
}
protected void verifyAllInputsCorrect() {