Author: jpapouse
Date: 2011-07-25 10:28:29 -0400 (Mon, 25 Jul 2011)
New Revision: 22564
Added:
modules/tests/metamer/branches/sandbox-components/ftest-source/src/main/java/org/jboss/test/selenium/waiting/NegationCondition.java
modules/tests/metamer/branches/sandbox-components/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/notify/
modules/tests/metamer/branches/sandbox-components/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/notify/TestNotify.java
Modified:
modules/tests/metamer/branches/sandbox-components/application/src/main/java/org/richfaces/tests/metamer/bean/NotifyBean.java
Log:
FPL-1504: created selenium tests for simple page containing Notify component
added NegationCondition
Modified:
modules/tests/metamer/branches/sandbox-components/application/src/main/java/org/richfaces/tests/metamer/bean/NotifyBean.java
===================================================================
---
modules/tests/metamer/branches/sandbox-components/application/src/main/java/org/richfaces/tests/metamer/bean/NotifyBean.java 2011-07-25
08:34:11 UTC (rev 22563)
+++
modules/tests/metamer/branches/sandbox-components/application/src/main/java/org/richfaces/tests/metamer/bean/NotifyBean.java 2011-07-25
14:28:29 UTC (rev 22564)
@@ -46,6 +46,9 @@
@ViewScoped
public class NotifyBean implements Serializable {
+ public static final String DEFAULT_DETAIL = "Detailed message text";
+ public static final String DEFAULT_TEXT = "Message text";
+ public static final String DEFAULT_TITLE = "Message title";
private static final long serialVersionUID = 8408544368608166106L;
private static Logger logger;
private Attributes attributesNotify;
@@ -66,23 +69,20 @@
attributesBean = Attributes.getEmptyAttributes(getClass());
attributesNotify.putAll(getGeneralAttributes());
- attributesNotify.setAttribute("text", "Message text");
- attributesNotify.setAttribute("title", "Message title");
- attributesNotify.remove("rendered");
+ attributesNotify.setAttribute("text", DEFAULT_TEXT);
+ attributesNotify.setAttribute("title", DEFAULT_TITLE);
attributesNotifyMessages.putAll(getGeneralAttributes());
attributesNotifyMessages.setAttribute("interval", 800);
attributesNotifyMessages.setAttribute("showSummary", true);
- attributesNotifyMessages.remove("rendered");
attributesNotifyStack.setAttribute("push", "bottom");
attributesNotifyStack.setAttribute("stackDir1", "down");
attributesNotifyStack.setAttribute("stackDir2", "left");
- attributesNotifyStack.remove("rendered");
attributesBean.setAttribute("messageCount", "1");
- attributesBean.setAttribute("messageDetail", "Detail: <Message
text>");
- attributesBean.setAttribute("messageText", "Message text");
+ attributesBean.setAttribute("messageDetail", DEFAULT_DETAIL);
+ attributesBean.setAttribute("messageText", DEFAULT_TEXT);
}
public void produceError() {
@@ -154,7 +154,7 @@
attributes.setAttribute("hideAnimation", "show");
attributes.setAttribute("showCloseButton", true);
attributes.setAttribute("stack", "exampleNotifyStack");
- attributes.setAttribute("stayTime", 3000);
+ attributes.setAttribute("stayTime", 100000);
return attributes;
}
}
Added:
modules/tests/metamer/branches/sandbox-components/ftest-source/src/main/java/org/jboss/test/selenium/waiting/NegationCondition.java
===================================================================
---
modules/tests/metamer/branches/sandbox-components/ftest-source/src/main/java/org/jboss/test/selenium/waiting/NegationCondition.java
(rev 0)
+++
modules/tests/metamer/branches/sandbox-components/ftest-source/src/main/java/org/jboss/test/selenium/waiting/NegationCondition.java 2011-07-25
14:28:29 UTC (rev 22564)
@@ -0,0 +1,67 @@
+/*******************************************************************************
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010-2011, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ *******************************************************************************/
+package org.jboss.test.selenium.waiting;
+
+import org.apache.commons.lang.Validate;
+import org.jboss.test.selenium.encapsulated.JavaScript;
+import org.jboss.test.selenium.waiting.ajax.JavaScriptCondition;
+import org.jboss.test.selenium.waiting.conditions.TextEquals;
+import org.jboss.test.selenium.waiting.selenium.SeleniumCondition;
+
+/**
+ * Condition that verifies that the given condition doesn't hold.
+ *
+ * @author <a href="mailto:jpapouse@redhat.com">Jan Papousek</a>
+ */
+public class NegationCondition implements SeleniumCondition, JavaScriptCondition{
+
+ private SeleniumCondition condition;
+
+ /**
+ * Factory method.
+ *
+ * @return single instance of NegationCondition
+ */
+ public static NegationCondition getInstance() {
+ return new NegationCondition();
+ }
+
+ public NegationCondition condition(SeleniumCondition condition) {
+ Validate.notNull(condition);
+ NegationCondition copy = new NegationCondition();
+ copy.condition = condition;
+ return copy;
+ }
+
+ @Override
+ public JavaScript getJavaScriptCondition() {
+ if (!(condition instanceof JavaScriptCondition)) {
+ throw new IllegalStateException("The given condition doesn't
implement JavaScriptCondition so its negation can't be converted to the
JavaScript.");
+ }
+ return new JavaScript("!(" + ((JavaScriptCondition)
condition).getJavaScriptCondition().getAsString() + ")");
+ }
+
+ @Override
+ public boolean isTrue() {
+ return !condition.isTrue();
+ }
+}
Added:
modules/tests/metamer/branches/sandbox-components/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/notify/TestNotify.java
===================================================================
---
modules/tests/metamer/branches/sandbox-components/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/notify/TestNotify.java
(rev 0)
+++
modules/tests/metamer/branches/sandbox-components/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/notify/TestNotify.java 2011-07-25
14:28:29 UTC (rev 22564)
@@ -0,0 +1,319 @@
+/*******************************************************************************
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010-2011, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ *******************************************************************************/
+package org.richfaces.tests.metamer.ftest.notify;
+
+import static org.jboss.test.selenium.utils.URLUtils.buildUrl;
+
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertEquals;
+import static org.jboss.test.selenium.locator.LocatorFactory.jq;
+
+import org.jboss.test.selenium.css.CssProperty;
+import org.jboss.test.selenium.dom.Event;
+import org.jboss.test.selenium.locator.JQueryLocator;
+import org.jboss.test.selenium.waiting.NegationCondition;
+import org.jboss.test.selenium.waiting.selenium.SeleniumCondition;
+import org.junit.Ignore;
+import org.richfaces.tests.metamer.bean.NotifyBean;
+import org.richfaces.tests.metamer.ftest.AbstractMetamerTest;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+/**
+ * Abstract test case for pages faces/components/notify/simple.xhtml
+ *
+ * @author <a href="mailto:jpapouse@redhat.com">Jan Papousek</a>
+ */
+public class TestNotify extends AbstractMetamerTest {
+
+ private JQueryLocator notify = jq("div.rf-ny");
+ private JQueryLocator notifyError = jq("div.rf-ny-error");
+ private JQueryLocator notifyFatal = jq("div.rf-ny-fatal");
+ private JQueryLocator notifyInfo = jq("div.rf-ny-info");
+ private JQueryLocator notifyWarn = jq("div.rf-ny-warn");
+ private JQueryLocator notifyStack = jq("div.rf-ny");
+ private Map<String, JQueryLocator> messages = new HashMap<String,
JQueryLocator>();
+
+ @BeforeClass
+ public void init() {
+ messages.put("Error", notifyError);
+ messages.put("Fatal", notifyFatal);
+ messages.put("Info", notifyInfo);
+ messages.put("Warn", notifyWarn);
+ }
+
+ @Override
+ public URL getTestUrl() {
+ return buildUrl(contextPath, "faces/components/notify/simple.xhtml");
+ }
+
+ @Test
+ public void testAttributeDelay() {
+ JQueryLocator attribute =
pjq("input[name*='attributesNotify:delayInput']");
+ selenium.type(attribute, "1000");
+ selenium.fireEvent(attribute, Event.BLUR);
+ selenium.waitForPageToLoad();
+ delay(500);
+ assertFalse(selenium.isElementPresent(notify), "The delay is set to 1000 and
after some little waiting the notify is still present.");
+ delay(1000);
+ assertTrue(selenium.isElementPresent(notify), "The delay is set to 1000 and
after some waiting the notify is not present.");
+ }
+
+ @Test
+ public void testAttributeRendered() {
+
selenium.click(pjq("input[type=radio][name*='attributesNotify:rendered'][value=false]"));
+ selenium.waitForPageToLoad();
+ assertFalse(selenium.isElementPresent(notify), "The attribute rendered is
set to <false> but the notify is still present.");
+ }
+
+ @Test
+ public void testAttributeShowCloseButton() {
+
selenium.click(pjq("input[type=radio][name*='attributesNotify:showCloseButtonInput'][value=false]"));
+ selenium.waitForPageToLoad();
+ assertTrue(selenium.getStyle(jq(notify.getRawLocator() + " > div.rf-ny-co
> div.rf-ny-cl"), new
CssProperty("visibility")).contains("hidden"), "The
showCloseButton is set to <false> and therefore the close button shouldn't be
displayed.");
+ }
+
+ @Test
+ public void testAttributesStayTime() {
+ close(notify);
+ produceMessage(notifyError, "Error", 1);
+ close(notifyError);
+ delay(1000);
+ assertTrue(selenium.isElementPresent(notify), "The stayTime is set to very
high number and after some little delay the notify is not present.");
+
+ JQueryLocator attribute =
pjq("input[name*='attributesNotify:stayTime']");
+ selenium.type(attribute, "500");
+ selenium.fireEvent(attribute, Event.BLUR);
+ selenium.waitForPageToLoad();
+ produceMessage(notifyError, "Error", 1);
+ close(notifyError);
+ delay(1000);
+ assertFalse(selenium.isElementPresent(notify), "The stayTime is set to 500
but after some delay the notify is still present.");
+ }
+
+ @Test
+ public void testAttributeStyleClass() {
+
selenium.type(pjq("input[name*='attributesNotify:styleClassInput']"),
"someStyleClass");
+ selenium.waitForPageToLoad();
+ assertTrue(selenium.belongsClass(notify, "someStyleClass"), "The
cssStyle has been set but notify doesn't belong to the set class.");
+ }
+
+ @Test(enabled=false)
+ public void testAttributeMessagesDelay() {
+ JQueryLocator attribute =
pjq("input[name*='attributesNotifyMessages:delayInput']");
+ selenium.type(attribute, "1000");
+ selenium.fireEvent(attribute, Event.BLUR);
+ selenium.waitForPageToLoad();
+ for(String type : messages.keySet()) {
+ selenium.click(pjq("input[id$=produce" + type + "]"));
+ delay(500);
+ assertFalse(selenium.isElementPresent(messages.get(type)), "The delay is
set to 1000 and after some little waiting the " + type + " message is still
present.");
+ delay(1000);
+ assertTrue(selenium.isElementPresent(messages.get(type)), "The delay is
set to 1000 and after some waiting the " + type + " message is not
present.");
+ }
+ }
+
+ @Test
+ public void testAttributeMessagesRendered() {
+
selenium.click(pjq("input[type=radio][name*='attributesNotifyMessages:rendered'][value=false]"));
+ selenium.waitForPageToLoad();
+ for(String type : messages.keySet()) {
+ selenium.click(pjq("input[id$=produce" + type + "]"));
+ String before = selenium.getText(jq("span[id=requestTime]"));
+
waitGui.until(textEquals.locator(jq("span[id=requestTime]")).text(before));
+ assertFalse(selenium.isElementPresent(messages.get(type)), "The
attribute rendered is set to <false> but the " + type + " message is still
present.");
+ }
+ }
+
+ @Test(enabled=false)
+ public void testAttributeMessagesShowCloseButton() {
+
selenium.click(pjq("input[type=radio][name*='attributesNotifyMessages:showCloseButtonInput'][value=false]"));
+ selenium.waitForPageToLoad();
+ for(String type : messages.keySet()) {
+ produceMessage(messages.get(type), type, 1);
+ assertTrue(selenium.getStyle(jq(messages.get(type) + " > div.rf-ny-co
> div.rf-ny-cl"), new
CssProperty("visibility")).contains("hidden"), "The
showCloseButton is set to <false> and therefore the close button shouldn't be
displayed.");
+ }
+ }
+
+ @Test(enabled=false)
+ public void testAttributeMessagesShowDetail() {
+ for(String type : messages.keySet()) {
+ produceMessage(messages.get(type), type, 1);
+ assertTrue(selenium.getStyle(jq(messages.get(type) + " > div.rf-ny-co
> div.rf-ny-te"), new
CssProperty("display")).contains("none"));
+ }
+
selenium.click(pjq("input[type=radio][name*='attributesNotifyMessages:showDetail'][value=true]"));
+ selenium.waitForPageToLoad();
+ for(String type : messages.keySet()) {
+ assertFalse(selenium.getStyle(jq(messages.get(type) + " >
div.rf-ny-co > div.rf-ny-te"), new
CssProperty("display")).contains("none"));
+ }
+ }
+
+ @Test
+ public void testAttributeMessagesStayTime() {
+ for(String type : messages.keySet()) {
+ produceMessage(messages.get(type), type, 1);
+ delay(1000);
+ assertTrue(selenium.isElementPresent(messages.get(type)), "The stayTime
is set to very high number and after some little delay the " + type + " message
is not present.");
+ close(messages.get(type));
+ }
+
+ JQueryLocator attribute =
pjq("input[name*='attributesNotifyMessages:stayTime']");
+ selenium.type(attribute, "500");
+ selenium.fireEvent(attribute, Event.BLUR);
+ selenium.waitForPageToLoad();
+ for(String type : messages.keySet()) {
+ produceMessage(messages.get(type), type, 1);
+ delay(1000);
+ assertFalse(selenium.isElementPresent(messages.get(type)), "The stayTime
is set to 500 but after some delay the " + type + " message is still
present.");
+ }
+ }
+
+ @Test
+ public void testAttributeMessagesStyleClass() {
+
selenium.type(pjq("input[name*='attributesNotifyMessages:styleClassInput']"),
"someStyleClass");
+ selenium.waitForPageToLoad();
+ for(String type : messages.keySet()) {
+ produceMessage(messages.get(type), type, 1);
+ assertTrue(selenium.belongsClass(messages.get(type),
"someStyleClass"), "The cssStyle has been set but " + type + "
message doesn't belong to the set class.");
+ }
+ }
+
+ @Test
+ public void testAttributeStackStyleClass() {
+ JQueryLocator attribute =
pjq("input[name*='attributesNotifyStack:styleClass']");
+ selenium.type(attribute, "someNiceStyleClass");
+ selenium.fireEvent(attribute, Event.BLUR);
+ selenium.waitForPageToLoad();
+ assertTrue(selenium.belongsClass(notifyStack, "someNiceStyleClass"));
+ }
+
+ @Test
+ public void testAttributeStackRendered() {
+
selenium.click(pjq("input[name*='attributesNotifyStack:rendered']"));
+ selenium.waitForPageToLoad();
+ assertFalse(selenium.isElementPresent(notifyStack), "The attribute rendered
is set to <false> but the notify stack is still present.");
+ }
+
+ @Test
+ public void testInit() {
+ assertTrue(selenium.isElementPresent(notify), "There is no notify message
after page is loaded.");
+ assertEquals(selenium.getText(jq(notify.getRawLocator() + " >
div.rf-ny-co > div.rf-ny-te")), NotifyBean.DEFAULT_TEXT, "The notify text
doesn't match.");
+ assertEquals(selenium.getText(jq(notify.getRawLocator() + " >
div.rf-ny-co > div.rf-ny-tl")), NotifyBean.DEFAULT_TITLE, "The notify title
doesn't match.");
+ }
+
+ @Test
+ public void testCloseAndProduceNotify() {
+ close(notify);
+ waitModel
+ .failWith("After closing notify message the message is stil
present.")
+
.until(NegationCondition.getInstance().condition(elementPresent.locator(notify)));
+ selenium.click(pjq("input[id$=produceError]"));
+ selenium.click(pjq("input[id$=produceError]"));
+ selenium.click(pjq("input[id$=produceFatal]"));
+ selenium.click(pjq("input[id$=produceInfo]"));
+ selenium.click(pjq("input[id$=produceWarn]"));
+ waitModel
+ .failWith("After producing messages the correct number of notifies
isn't present. Expected <5>, was <" + getNumberOfNotifies() +
">")
+ .until(new SeleniumCondition() {
+ @Override
+ public boolean isTrue() {
+ return getNumberOfNotifies() == 5;
+ }
+ });
+ }
+
+ @Test
+ public void testProduceAndCloseMessages() {
+ for(String type : messages.keySet()) {
+ testProduceAndCloseMessage(messages.get(type), type);
+ }
+ }
+
+ @Test
+ public void testProduceMoreMessages() {
+ int testedNumber = 3;
+ selenium.type(pjq("input[id$=messageCountInput]"), testedNumber +
"");
+ selenium.fireEvent(pjq("input[id$=messageCountInput]"), Event.BLUR);
+ selenium.waitForPageToLoad();
+ for(String type : messages.keySet()) {
+ testProduceMoreMessages(messages.get(type), type, testedNumber);
+ }
+ }
+
+ private void testProduceAndCloseMessage(final JQueryLocator message, String type) {
+ produceMessage(message, type, 1);
+ close(message);
+ }
+
+ private void testProduceMoreMessages(final JQueryLocator message, String type, int
number) {
+ close(notify);
+ produceMessage(message, type, number);
+ assertEquals(getNumberOfNotifies(), 1, "Number of produced messages has been
set to <" + number + "> but number of notifies should be still
<1>.");
+ for(int i=0; i<number; i++) {
+ close(message);
+ }
+ }
+
+ private void close(final JQueryLocator locator) {
+ final int before = selenium.getCount(locator);
+ selenium.click(getFirstCloseButton(locator));
+ waitGui
+ .failWith("Message " + locator.getRawLocator() + " can't
be closed.")
+ .until(countEquals.locator(locator).count(before - 1));
+ }
+
+ private void delay(int ms) {
+ try {
+ Thread.sleep(ms);
+ } catch (InterruptedException e) {
+ Logger.getLogger(getClass().getName()).log(Level.WARNING, e.toString());
+ }
+ }
+
+ private JQueryLocator getCloseButton(JQueryLocator message) {
+ return jq(message.getRawLocator() + " > div.rf-ny-co > div.rf-ny-cl
> span.rf-ny-cl-ic");
+ }
+
+ private JQueryLocator getFirstCloseButton(JQueryLocator message) {
+ return jq(getCloseButton(message).getRawLocator() + ":first");
+ }
+
+ private int getNumberOfNotifies() {
+ return selenium.getCount(notify) - (selenium.getCount(notifyError) +
selenium.getCount(notifyFatal) + selenium.getCount(notifyInfo) +
selenium.getCount(notifyWarn));
+ }
+
+ private void produceMessage(final JQueryLocator message, String type, final int
expected) {
+ final int before = selenium.getCount(message);
+ selenium.click(pjq("input[id$=produce" + type + "]"));
+ waitGui
+ .failWith("Number of produced messages has been set to <" +
expected + "> but <" + selenium.getCount(notifyError) + "> "
+ type + " messages is present.")
+ .until(countEquals.locator(message).count(expected + before));
+ }
+}