Author: jpapouse
Date: 2011-08-08 04:23:10 -0400 (Mon, 08 Aug 2011)
New Revision: 22597
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/jboss/test/selenium/waiting/NegationCondition.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richNotify/
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richNotify/AbstractRichNotifyTest.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richNotify/TestRichNotify.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richNotify/TestRichNotifyMoreStacks.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richNotify/TestRichNotifyValidation.java
Log:
selenium tests for rich:notify (containing some unstable tests)
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/jboss/test/selenium/waiting/NegationCondition.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/jboss/test/selenium/waiting/NegationCondition.java
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/jboss/test/selenium/waiting/NegationCondition.java 2011-08-08
08:23:10 UTC (rev 22597)
@@ -0,0 +1,66 @@
+/*******************************************************************************
+ * 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.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/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richNotify/AbstractRichNotifyTest.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richNotify/AbstractRichNotifyTest.java
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richNotify/AbstractRichNotifyTest.java 2011-08-08
08:23:10 UTC (rev 22597)
@@ -0,0 +1,181 @@
+/*******************************************************************************
+ * 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.richNotify;
+
+import static org.jboss.test.selenium.locator.LocatorFactory.jq;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.jboss.test.selenium.locator.JQueryLocator;
+import org.richfaces.tests.metamer.ftest.AbstractMetamerTest;
+
+/**
+ * Abstract test case for pages faces/components/notify/
+ *
+ * @author <a href="mailto:jpapouse@redhat.com">Jan Papousek</a>
+ */
+public abstract class AbstractRichNotifyTest extends AbstractMetamerTest {
+
+ /**
+ * notify locator which matches on all notifies and messages
+ */
+ protected final JQueryLocator notify = jq("div.rf-ntf");
+
+ /**
+ * error message locator
+ */
+ protected final JQueryLocator notifyError = jq("div.rf-ntf-error");
+
+ /**
+ * fatal message locator
+ */
+ protected final JQueryLocator notifyFatal = jq("div.rf-ntf-fatal");
+
+ /**
+ * history of notifies and notify messages
+ */
+ protected final JQueryLocator notifyHistory = jq("div.rf-ntf-hstr-hdr");
+
+ /**
+ * 'all' button in the history menu
+ */
+ protected final JQueryLocator notifyHistoryAll =
jq("button.rf-ntf-hstr-all");
+
+ /**
+ * 'last' button in the history menu
+ */
+ protected final JQueryLocator notifyHistoryLast =
jq("button.rf-ntf-hstr-last");
+
+ /**
+ * info message locator
+ */
+ protected final JQueryLocator notifyInfo = jq("div.rf-ntf-info");
+
+ /**
+ * warn message locator
+ */
+ protected final JQueryLocator notifyWarn = jq("div.rf-ntf-warn");
+
+ /**
+ * It closes a message defined by the given locator
+ *
+ * @param locator the message locator
+ */
+ protected 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));
+ }
+
+ /**
+ * It closes all message defined by the given locator
+ *
+ * @param locator the message locator
+ */
+ protected void closeAll(final JQueryLocator locator) {
+ while(selenium.isElementPresent(locator)) {
+ close(locator);
+ }
+ }
+
+ /**
+ * It delays for the given number of ms. If there is any exception thrown, it's
logged by logger of this class.
+ *
+ * @param ms number of miliseconds
+ */
+ protected void delay(int ms) {
+ try {
+ Thread.sleep(ms);
+ } catch (InterruptedException e) {
+ Logger.getLogger(getClass().getName()).log(Level.WARNING, e.toString());
+ }
+ }
+
+ /**
+ * It returns a close button of a message defined by the given locator
+ *
+ * @param message the message locator
+ * @return the close button locator
+ */
+ protected JQueryLocator getCloseButton(JQueryLocator message) {
+ return jq(message.getRawLocator() + " > div.rf-ntf-cnt >
div.rf-ntf-cls > span.rf-ntf-cls-ico");
+ }
+
+ /**
+ * It returns a detail element of a message defined by the given locator
+ *
+ * @param message the message locator
+ * @return the detail locator
+ */
+ protected JQueryLocator getDetail(JQueryLocator message) {
+ return jq(notify.getRawLocator() + " > div.rf-ntf-cnt >
div.rf-ntf-txt");
+ }
+
+ /**
+ * It returns the first available close button of a message defined by the given
locator
+ *
+ * @param message the message locator
+ * @return the close button locator
+ */
+ protected JQueryLocator getFirstCloseButton(JQueryLocator message) {
+ return jq(getCloseButton(message).getRawLocator() + ":first");
+ }
+
+ /**
+ * It returns a number of notifes (only notifies, not messages) in the given stack.
+ *
+ * @return number of notifies
+ */
+ protected int getNumberOfNotifies() {
+ return selenium.getCount(notify) - (selenium.getCount(notifyError) +
selenium.getCount(notifyFatal) + selenium.getCount(notifyInfo) +
selenium.getCount(notifyWarn));
+ }
+
+ /**
+ * It returns a summary element of a message defined by the given locator
+ *
+ * @param message the message locator
+ * @return the summary locator
+ */
+ protected JQueryLocator getSummary(JQueryLocator message) {
+ return jq(notify.getRawLocator() + " > div.rf-ntf-cnt >
div.rf-ntf-tl");
+ }
+
+ /**
+ * It produces a message defined by the given message locator and the given type.
+ * It waits until the <expected> number of message is produced.
+ *
+ * @param message the message locator
+ * @param type the name of the message type (started with capital letter)
+ * @param expected expected number of produced messages
+ */
+ protected 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(message) + "> " +
type + " messages is present.")
+ .until(countEquals.locator(message).count(expected + before));
+ }
+
+}
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richNotify/TestRichNotify.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richNotify/TestRichNotify.java
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richNotify/TestRichNotify.java 2011-08-08
08:23:10 UTC (rev 22597)
@@ -0,0 +1,441 @@
+/*******************************************************************************
+ * 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.richNotify;
+
+import static org.jboss.test.selenium.utils.URLUtils.buildUrl;
+
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+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.richfaces.tests.metamer.bean.rich.RichNotifyBean;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+/**
+ * Test case for pages faces/components/notify/simple.xhtml
+ *
+ * @author <a href="mailto:jpapouse@redhat.com">Jan Papousek</a>
+ */
+public class TestRichNotify extends AbstractRichNotifyTest {
+
+ /**
+ * notify stack locator
+ */
+ private JQueryLocator notifyStack = jq("div.rf-ntf");
+
+ /**
+ * Map containing locators of all tested messages. Type of the message is a key in
the map.
+ */
+ 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/richNotify/simple.xhtml");
+ }
+
+ @Test
+ public void testAttributeDelay() {
+ // set the delay to <1000>
+ JQueryLocator attribute =
pjq("input[id$='attributesNotify:delayInput']");
+ selenium.type(attribute, "1000");
+ selenium.fireEvent(attribute, Event.BLUR);
+ selenium.waitForPageToLoad();
+ // wait for <500>
+ delay(500);
+ assertFalse(selenium.isElementPresent(notify), "The delay is set to 1000 and
after some little waiting the notify shouldn't be present.");
+ // wait for <1000>
+ delay(1000);
+ assertTrue(selenium.isElementPresent(notify), "The delay is set to 1000 and
after some waiting the notify should be present.");
+ }
+
+ @Test
+ public void testAttributeRendered() {
+ // set the rendered to <false>
+
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() {
+ // set the showCloseButton to <false>
+
selenium.click(pjq("input[type=radio][name*='attributesNotify:showCloseButtonInput'][value=false]"));
+ selenium.waitForPageToLoad();
+ assertTrue(selenium.getStyle(getCloseButton(notify), new
CssProperty("visibility")).contains("hidden"), "The
showCloseButton is set to <false> and therefore the close button shouldn't be
displayed.");
+ }
+
+ @Test
+ public void testAttributeShowHistory() {
+ // check whether the history is not present (showHistory is set to
<false>)
+ assertFalse(selenium.isElementPresent(notifyHistory), "The showHistory is
set to <false> and there shouldn't be any history menu.");
+ // set the showHistory to <true>
+
selenium.click(pjq("input[type=radio][name*='attributesNotify:showHistory'][value=true]"));
+ selenium.waitForPageToLoad();
+ assertTrue(selenium.isElementPresent(notifyHistory), "The showHistory is set
to <true> and one notify is present, but there is no history menu.");
+ close(notify);
+ produceMessage(notifyError, "Error", 1);
+ close(notify);
+ close(notify);
+ // click on the All button in history menu
+ selenium.click(notifyHistoryAll);
+ waitModel
+ .failWith("After clicking on <All> in history menu there should be
all notifies. Expected <2>, found <" + getNumberOfNotifies() +
">")
+ .until(new SeleniumCondition() {
+ @Override
+ public boolean isTrue() {
+ return getNumberOfNotifies() == 2;
+ }
+ });
+ close(notify);
+ close(notify);
+ // click on the Last button in the history menu
+ selenium.click(notifyHistoryLast);
+ waitModel
+ .failWith("After clicking on <Last> in history menu there should
be last notify. Expected <1>, found <" + getNumberOfNotifies() +
">")
+ .until(new SeleniumCondition() {
+ @Override
+ public boolean isTrue() {
+ return getNumberOfNotifies() == 1;
+ }
+ });
+ }
+
+ @Test
+ public void testAttributesStayTime() {
+ // stayTime is set to a very high number
+ 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.");
+ // set the stayTime to <500>
+ JQueryLocator attribute =
pjq("input[name*='attributesNotify:stayTime']");
+ selenium.type(attribute, "500");
+ selenium.fireEvent(attribute, Event.BLUR);
+ selenium.waitForPageToLoad();
+ produceMessage(notifyError, "Error", 1);
+ close(notifyError);
+ // wait for <1000>
+ delay(1000);
+ assertFalse(selenium.isElementPresent(notify), "The stayTime is set to 500
but after some delay the notify is still present.");
+ }
+
+ @Test
+ public void testAttributeSticky() {
+ // set the stayTime to <0>
+ JQueryLocator stayTime =
pjq("input[name*='attributesNotify:stayTime']");
+ selenium.type(stayTime, "0");
+ selenium.fireEvent(stayTime, Event.BLUR);
+ selenium.waitForPageToLoad();
+ // set the sticky to <false>
+
selenium.click(pjq("input[type=radio][name*='attributesNotify:sticky'][value=false]"));
+ selenium.waitForPageToLoad();
+ waitGui
+ .failWith("The stayTime is set to <0> and sticky to <false>,
so the notify shouldn't be present.")
+
.until(NegationCondition.getInstance().condition(elementPresent.locator(notify)));
+ // produce messages and notifies and close messages
+ for(String type : messages.keySet()) {
+ produceMessage(messages.get(type), type, 1);
+ close(messages.get(type));
+ }
+ waitGui
+ .failWith("The stayTime is set to <0> and sticky to <false>,
so the notify shouldn't be present.")
+
.until(NegationCondition.getInstance().condition(elementPresent.locator(notify)));
+ // set the sticky to <true>
+
selenium.click(pjq("input[type=radio][name*='attributesNotify:sticky'][value=true]"));
+ selenium.waitForPageToLoad();
+ delay(500);
+ waitGui
+ .failWith("The stayTime is set to <0> and sticky to <true>,
so the notify should be present.")
+ .until(elementPresent.locator(notify));
+ closeAll(notify);
+ // produce messages and notifies and close messages
+ for(String type : messages.keySet()) {
+ produceMessage(messages.get(type), type, 1);
+ close(messages.get(type));
+ }
+ waitModel
+ .failWith("The stayTime is set to <0> and sticky to <true>,
so the notify shouldn't be present.")
+ .until(new SeleniumCondition() {
+ @Override
+ public boolean isTrue() {
+ return selenium.getCount(notify) == messages.size();
+ }
+ });
+ }
+
+ @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
+ public void testAttributeMessagesDelay() {
+ // set the delay to <1000>
+ JQueryLocator attribute =
pjq("input[id$='attributesNotifyMessages:delayInput']");
+ selenium.type(attribute, "1000");
+ selenium.fireEvent(attribute, Event.BLUR);
+ selenium.waitForPageToLoad();
+ // check the delay for each message type
+ 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 shouldn't
be present.");
+ delay(1000);
+ assertTrue(selenium.isElementPresent(messages.get(type)), "The delay is
set to 1000 and after some waiting the " + type + " message should be
present.");
+ }
+ }
+
+ @Test
+ public void testAttributeMessagesRendered() {
+ // set the rendered to <false>
+
selenium.click(pjq("input[type=radio][name*='attributesNotifyMessages:rendered'][value=false]"));
+ selenium.waitForPageToLoad();
+ // check the message isn't displayed for each message type
+ for(String type : messages.keySet()) {
+ String before = selenium.getText(jq("span[id=requestTime]"));
+ selenium.click(pjq("input[id$=produce" + type + "]"));
+
waitGui.until(NegationCondition.getInstance().condition(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() {
+ // set the showCloseButton to <false>
+
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-ntf-co > div.rf-ntf-cls"), 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() {
+ // produce messages and check whether the detail isn't displayed (showDetail
is set to <false>)
+ for(String type : messages.keySet()) {
+ produceMessage(messages.get(type), type, 1);
+ // FIXME:
+ assertTrue(selenium.getStyle(jq(messages.get(type) + " > div.rf-ny-co
> div.rf-ny-te"), new
CssProperty("display")).contains("none"));
+ }
+ // set showDetail to <true>
+
selenium.click(pjq("input[type=radio][name*='attributesNotifyMessages:showDetail'][value=true]"));
+ selenium.waitForPageToLoad();
+ for(String type : messages.keySet()) {
+ // FIXME:
+ assertFalse(selenium.getStyle(jq(messages.get(type) + " >
div.rf-ny-co > div.rf-ny-te"), new
CssProperty("display")).contains("none"));
+ }
+ }
+
+ @Test
+ public void testAttributeMessagesShowHistory() {
+ // check whether the history isn't present (showHistory is set to
<false>)
+ close(notify);
+ assertFalse(selenium.isElementPresent(notifyHistory), "The showHistory is
set to <false> and there shouldn't be any history menu.");
+ // set the showHistory to <true>
+
selenium.click(pjq("input[type=radio][name*='attributesNotifyMessages:showHistory'][value=true]"));
+ selenium.waitForPageToLoad();
+ // check whether the history isn't displayed (there is no message in the
history)
+ assertFalse(selenium.isElementPresent(notifyHistory), "The showHistory is
set to <true>, but there is no message, so there shouldn't be any history
menu.");
+ // produce messages and close them
+ for(String type : messages.keySet()) {
+ produceMessage(messages.get(type), type, 1);
+ close(notify);
+ close(notify);
+ }
+ // click on All button in the history menu
+ selenium.click(notifyHistoryAll);
+ final int expected = messages.size();
+ waitModel
+ .failWith("After clicking on <All> in history menu there should be
all messages. Expected <" + expected + ">, found <" +
selenium.getCount(notify) + ">")
+ .until(new SeleniumCondition() {
+ @Override
+ public boolean isTrue() {
+ return selenium.getCount(notify) == expected;
+ }
+ });
+ for(int i=0; i<expected; i++) {
+ close(notify);
+ }
+ // click on Last button in the history menu
+ selenium.click(notifyHistoryLast);
+ waitModel
+ .failWith("After clicking on <Last> in history menu there should
be last message. Expected <1>, found <" + selenium.getCount(notify) +
">")
+ .until(new SeleniumCondition() {
+ @Override
+ public boolean isTrue() {
+ return selenium.getCount(notify) == 1;
+ }
+ });
+ }
+
+ @Test
+ public void testAttributeMessagesStayTime() {
+ // produce messages and check whether the stay at least 1000 ms (stayTime is set
to a very high number)
+ 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));
+ }
+ // set the stayTime to <500>
+ JQueryLocator attribute =
pjq("input[name*='attributesNotifyMessages:stayTime']");
+ selenium.type(attribute, "500");
+ selenium.fireEvent(attribute, Event.BLUR);
+ selenium.waitForPageToLoad();
+ // produce messages and check whether the stay less then 1000 ms
+ 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 testAttributeMessagesSticky() {
+ // set the stayTime to <0>
+ JQueryLocator stayTime =
pjq("input[name*='attributesNotifyMessages:stayTime']");
+ selenium.type(stayTime, "0");
+ selenium.fireEvent(stayTime, Event.BLUR);
+ selenium.waitForPageToLoad();
+ // set the sticky to <false>
+
selenium.click(pjq("input[type=radio][name*='attributesNotifyMessages:sticky'][value=false]"));
+ selenium.waitForPageToLoad();
+ // produce messages and check whether they disappear quickly
+ for(String type : messages.keySet()) {
+ produceMessage(messages.get(type), type, 1);
+ waitGui
+ .failWith("The stayTime is set to <0> and sticky to
<false>, so the " + type + " message shouldn't be present.")
+
.until(NegationCondition.getInstance().condition(elementPresent.locator(messages.get(type))));
+ closeAll(notify);
+ }
+ // set the sticky to <true>
+
selenium.click(pjq("input[type=radio][name*='attributesNotifyMessages:sticky'][value=true]"));
+ selenium.waitForPageToLoad();
+ // produce messages
+ for(String type : messages.keySet()) {
+ produceMessage(messages.get(type), type, 1);
+ }
+ // check whether the messages are still present
+ delay(500);
+ for(String type : messages.keySet()) {
+ waitGui
+ .failWith("The stayTime is set to <0> and sticky to
<true>, so the " + type + " message should be present.")
+ .until(elementPresent.locator(messages.get(type)));
+ }
+ }
+
+ @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() {
+ // set the rendered to <false>
+
selenium.click(pjq("input[name*='attributesNotifyStack:rendered']"));
+ selenium.waitForPageToLoad();
+ assertFalse(selenium.isElementPresent(notifyStack), "The attribute rendered
is set to <false> but messages in the notify stack are still present.");
+ }
+
+ @Test
+ public void testInit() {
+ assertTrue(selenium.isElementPresent(notify), "There is no notify message
after page is loaded.");
+ assertEquals(selenium.getText(getDetail(notify)), RichNotifyBean.DEFAULT_DETAIL,
"The notify detail doesn't match.");
+ assertEquals(selenium.getText(getSummary(notify)),
RichNotifyBean.DEFAULT_SUMMARY, "The notify summary doesn't match.");
+ }
+
+ @Test
+ public void testCloseAndProduceNotify() {
+ // check closing the notify
+ close(notify);
+ waitGui
+ .failWith("After closing notify message the message is stil
present.")
+
.until(NegationCondition.getInstance().condition(elementPresent.locator(notify)));
+ // check producing notifies
+ for(String type : messages.keySet()) {
+ produceMessage(messages.get(type), type, 1);
+ close(messages.get(type));
+ }
+ waitGui
+ .failWith("After producing messages the correct number of notifies
isn't present. Expected <" + messages.size() + ">, was <" +
selenium.getCount(notify) + ">")
+ .until(countEquals.locator(notify).count(messages.size()));
+ }
+
+ @Test
+ public void testProduceAndCloseMessages() {
+ for(String type : messages.keySet()) {
+ produceMessage(messages.get(type), type, 1);
+ close(messages.get(type));
+ }
+ }
+
+ @Test
+ public void testProduceMoreMessages() {
+ // set the messageCount to <testedNumber>
+ int testedNumber = 3;
+ selenium.type(pjq("input[name*=messageCountInput]"), testedNumber +
"");
+ selenium.fireEvent(pjq("input[name*=messageCountInput]"), Event.BLUR);
+ selenium.waitForPageToLoad();
+ close(notify);
+ for(String type : messages.keySet()) {
+ produceMessage(messages.get(type), type, testedNumber);
+ assertEquals(getNumberOfNotifies(), 1, "Number of produced messages has
been set to <" + testedNumber + "> but number of notifies should be still
<1>.");
+ closeAll(messages.get(type));
+ close(notify);
+ }
+ }
+}
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richNotify/TestRichNotifyMoreStacks.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richNotify/TestRichNotifyMoreStacks.java
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richNotify/TestRichNotifyMoreStacks.java 2011-08-08
08:23:10 UTC (rev 22597)
@@ -0,0 +1,134 @@
+/*******************************************************************************
+ * 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.richNotify;
+
+import static org.jboss.test.selenium.utils.URLUtils.buildUrl;
+import static org.jboss.test.selenium.locator.LocatorFactory.jq;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.assertEquals;
+import java.net.URL;
+
+import org.jboss.test.selenium.dom.Event;
+import org.jboss.test.selenium.locator.JQueryLocator;
+import org.testng.annotations.Test;
+
+
+/**
+ * Test case for pages faces/components/notify/moreStacks.xhtml
+ *
+ * @author <a href="mailto:jpapouse@redhat.com">Jan Papousek</a>
+ */
+public class TestRichNotifyMoreStacks extends AbstractRichNotifyTest {
+
+ /**
+ * locator of the first stack
+ */
+ private final JQueryLocator stack1 = jq("div.topRight");
+
+ /**
+ * locator of the second stack
+ */
+ private final JQueryLocator stack2 = jq("div.bottomRight");
+
+ /**
+ * locater of the input which is associated with messages for the first stack
+ */
+ private final JQueryLocator number1 = pjq("input[id$=number1]");
+
+ /**
+ * locater of the input which is associated with messages for the second stack
+ */
+ private final JQueryLocator number2 = pjq("input[id$=number2]");
+
+ @Override
+ public URL getTestUrl() {
+ return buildUrl(contextPath,
"faces/components/richNotify/moreStacks.xhtml");
+ }
+
+ @Test
+ public void testInit() {
+ assertTrue(selenium.isElementPresent(stack1), "The first stack is not
present.");
+ assertTrue(selenium.isElementPresent(stack2), "The second stack is not
present.");
+ assertTrue(selenium.isElementPresent(inStack(stack1, notify)), "The notify
in the first stack is not present.");
+ assertTrue(selenium.isElementPresent(inStack(stack2, notify)), "The notify
in the second stack is not present.");
+ assertEquals(1, getNumberOfNotifies(stack1), "The initial number of notifies
in the first stack should be <1>, found <" + getNumberOfNotifies(stack1) +
">.");
+ assertEquals(1, getNumberOfNotifies(stack2), "The initial number of notifies
in the second stack should be <1>, found <" + getNumberOfNotifies(stack2) +
">.");
+ }
+
+ @Test
+ public void testValidationErrorInTwoStacks() {
+ // notify in stacks
+ JQueryLocator message1 = inStack(stack1, notify);
+ JQueryLocator message2 = inStack(stack2, notify);
+ // close notifes in both stacks
+ close(message1);
+ close(message2);
+ // try to fill the number 1 field (wrong)
+ selenium.type(number1, "1");
+ selenium.fireEvent(number1, Event.BLUR);
+ delay(1000);
+ waitGui
+ .failWith("After wrong filling the first form field the number of
messages in the first stack should be <1>, found <" +
selenium.getCount(message1) + ">")
+ .until(countEquals.locator(message1).count(1));
+ waitGui
+ .failWith("After wrong filling the first form field the number of
messages in the second stack should be <0>, found <" +
selenium.getCount(message2) + ">")
+ .until(countEquals.locator(message1).count(0));
+
+ // close produced notifies
+ close(message1);
+ close(message2);
+ // try to fill the number 2 field (wrong)
+ selenium.type(number2, "1");
+ selenium.fireEvent(number2, Event.BLUR);
+ delay(1000);
+ waitGui
+ .failWith("After wrong filling the second form field the number of
messages in the second stack should be <1>, found <" +
selenium.getCount(message2) + ">")
+ .until(countEquals.locator(message1).count(1));
+ waitGui
+ .failWith("After wrong filling the second form field the number of
messages in the first stack should be <0>, found <" +
selenium.getCount(message1) + ">")
+ .until(countEquals.locator(message1).count(0));
+ }
+
+ /**
+ * It returns a number of notifes (only notifies, not messages) in the given stack
+ *
+ * @param stack the stack where the notifies should be present
+ * @return number of notifies
+ */
+ private int getNumberOfNotifies(JQueryLocator stack) {
+ return selenium.getCount(inStack(stack, notify)) -
(selenium.getCount(inStack(stack, notifyError)) + selenium.getCount(inStack(stack,
notifyFatal)) + selenium.getCount(inStack(stack, notifyInfo)) +
selenium.getCount(inStack(stack, notifyWarn)));
+ }
+
+ /**
+ * It returns a new locator of the given message in the given stack
+ * @param stack
+ * @param message
+ * @return a new locator of the given message in the given stack
+ */
+ private JQueryLocator inStack(JQueryLocator stack, JQueryLocator message) {
+ String[] splittedMessageLocator = message.getAsString().split("\\.");
+ String[] splittedStackLocator = stack.getAsString().split("\\.");
+ String locator = "div[class*=" +
splittedStackLocator[splittedStackLocator.length - 1] + "][class*=" +
splittedMessageLocator[splittedMessageLocator.length - 1] + "]";
+ return jq(locator);
+ }
+
+}
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richNotify/TestRichNotifyValidation.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richNotify/TestRichNotifyValidation.java
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richNotify/TestRichNotifyValidation.java 2011-08-08
08:23:10 UTC (rev 22597)
@@ -0,0 +1,71 @@
+/*******************************************************************************
+ * 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.richNotify;
+
+import static org.jboss.test.selenium.utils.URLUtils.buildUrl;
+import java.net.URL;
+
+import org.jboss.test.selenium.dom.Event;
+import org.jboss.test.selenium.locator.JQueryLocator;
+import org.jboss.test.selenium.waiting.NegationCondition;
+import org.testng.annotations.Test;
+
+/**
+ * Test case for pages faces/components/notify/validation.xhtml
+ *
+ * @author <a href="mailto:jpapouse@redhat.com">Jan Papousek</a>
+ */
+public class TestRichNotifyValidation extends AbstractRichNotifyTest {
+
+ private JQueryLocator number = pjq("input[id$=number]");
+
+ @Override
+ public URL getTestUrl() {
+ return buildUrl(contextPath,
"faces/components/richNotify/validation.xhtml");
+ }
+
+ @Test
+ public void testAttributeMessagesGlobalOnly() {
+
+ }
+
+ @Test
+ public void testValidationMessageAppear() {
+ closeAll(notify);
+ selenium.type(number, "4");
+ selenium.fireEvent(number, Event.BLUR);
+ waitGui
+ .failWith("After typing <4> into the number field, the error
should appear.")
+ .until(elementPresent.locator(notifyError));
+ }
+
+ @Test
+ public void testValidationMessageNotAppear() {
+ closeAll(notify);
+ selenium.type(number, "5");
+ selenium.fireEvent(number, Event.BLUR);
+ waitGui
+ .failWith("After typing <5> into the number field, the error
should appear.")
+
.until(NegationCondition.getInstance().condition(elementPresent.locator(notifyError)));
+ }
+
+}