Permalink
Browse files

Metamer: Fix PanelMenuGroupTest for @mode=server

Using alert to verify server mode is not reliable on Jenkins, but in the same time, using metamerEvents variable isn't reliable too, since it is rewritten during HTTP request processing. Fix: store metamerEvents variable in sessionStorage and then retrieve value from here.
  • Loading branch information...
1 parent ee8d555 commit f355ed07afedc5ce797c3f3c156f506919f177a8 @jjamrich jjamrich committed Mar 28, 2013
@@ -0,0 +1,79 @@
+/**
+ * JBoss, Home of Professional Open Source
+ * Copyright 2013, 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.richPanelMenuGroup;
+
+import static java.text.MessageFormat.format;
+import static org.testng.Assert.assertEquals;
+
+import java.util.Arrays;
+
+import org.jboss.arquillian.graphene.Graphene;
+import org.jboss.test.selenium.support.ui.ElementPresent;
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebElement;
+import org.richfaces.tests.metamer.ftest.AbstractWebDriverTest;
+import org.richfaces.tests.metamer.ftest.webdriver.MetamerPage;
+import org.richfaces.tests.metamer.ftest.webdriver.MetamerPage.WaitRequestType;
+
+/**
+ * @author <a href="jjamrich@redhat.com">Jan Jamrich</a>
+ *
+ */
+public abstract class AbstractPanelMenuCommonTest extends AbstractWebDriverTest {
+
+ private static final String ATTR_INPUT_LOC_FORMAT = "input[id$=on{0}Input]";
+
+ public abstract MetamerPage getPage();
+
+ public void testRequestEventsBefore(String... events) {
+ for (String event : events) {
+ String inputExp = format(ATTR_INPUT_LOC_FORMAT, event);
+ WebElement input = getPage().attributesTable.findElement(By.cssSelector(inputExp));
+ // Note: To avoid lost metamerEvents variable when @mode=server, use sessionStorage
+ String inputVal = format("metamerEvents += \"{0} \"", event);
+ String inputValFull = "sessionStorage.setItem('metamerEvents', " + inputVal + ")";
+ // even there would be some events (in params) twice, don't expect handle routine to be executed twice
+ input.clear();
+ waiting(1000);
+ input = getPage().attributesTable.findElement(By.cssSelector(inputExp));
+ input.sendKeys(inputValFull);
+ // sendKeys triggers page reload automatically
+ waiting(300);
+ Graphene.waitAjax().until(ElementPresent.getInstance().element(getPage().attributesTable));
+ input = getPage().attributesTable.findElement(By.cssSelector(inputExp));
+ MetamerPage.waitRequest(input, WaitRequestType.HTTP).submit();
+ }
+ cleanMetamerEventsVariable();
+ }
+
+ public void testRequestEventsAfter(String... events) {
+ String[] actualEvents = ((String)executeJS("return sessionStorage.getItem('metamerEvents')")).split(" ");
+ assertEquals(actualEvents, events, format("The events ({0}) don't came in right order ({1})",
+ Arrays.deepToString(actualEvents), Arrays.deepToString(events)));
+ }
+
+ public void cleanMetamerEventsVariable() {
+ // since metamerEvents variable stored on session too, make sure that cleaned both of them
+ executeJS("window.metamerEvents = \"\";");
+ executeJS("sessionStorage.removeItem('metamerEvents')");
+ }
+}
@@ -29,15 +29,15 @@
import java.net.URL;
import org.jboss.arquillian.graphene.spi.annotations.Page;
-import org.richfaces.tests.metamer.ftest.AbstractWebDriverTest;
+import org.richfaces.tests.metamer.ftest.webdriver.MetamerPage;
import org.testng.annotations.BeforeMethod;
/**
* @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
* @author <a href="mailto:jjamrich@redhat.com">Jan Jamrich</a>
* @since 4.3.1
*/
-public abstract class AbstractPanelMenuGroupTest extends AbstractWebDriverTest {
+public abstract class AbstractPanelMenuGroupTest extends AbstractPanelMenuCommonTest {
@Page
PanelMenuGroupPage page;
@@ -47,6 +47,11 @@ public URL getTestUrl() {
return buildUrl(contextPath, "faces/components/richPanelMenuGroup/simple.xhtml");
}
+ @Override
+ public MetamerPage getPage() {
+ return page;
+ }
+
@BeforeMethod
public void setupModes() {
panelMenuGroupAttributes.set(mode, ajax);
@@ -22,7 +22,6 @@
package org.richfaces.tests.metamer.ftest.richPanelMenuGroup;
import org.jboss.arquillian.graphene.enricher.findby.FindBy;
-import org.openqa.selenium.WebElement;
import org.richfaces.tests.metamer.ftest.webdriver.MetamerPage;
import org.richfaces.tests.page.fragments.impl.panelMenu.RichFacesPanelMenu;
import org.richfaces.tests.page.fragments.impl.panelMenuGroup.RichFacesPanelMenuGroup;
@@ -46,7 +45,4 @@
@FindBy(css = "div[id$=group23]")
public RichFacesPanelMenuGroup subGroup;
- @FindBy(css = "table[id$='attributes:attributes']")
- public WebElement attributesTable;
-
}
@@ -21,39 +21,23 @@
*******************************************************************************/
package org.richfaces.tests.metamer.ftest.richPanelMenuGroup;
-import static java.text.MessageFormat.format;
import static org.jboss.arquillian.ajocado.utils.URLUtils.buildUrl;
import static org.richfaces.component.Mode.ajax;
import static org.richfaces.component.Mode.client;
import static org.richfaces.component.Mode.server;
import static org.richfaces.tests.metamer.ftest.richPanelMenuGroup.PanelMenuGroupAttributes.mode;
import static org.richfaces.tests.metamer.ftest.webdriver.AttributeList.panelMenuGroupAttributes;
-import static org.testng.Assert.assertEquals;
import java.net.URL;
-import java.util.Arrays;
-import java.util.LinkedList;
-import java.util.List;
-import javax.annotation.Nullable;
-
-import org.jboss.arquillian.graphene.Graphene;
-import org.jboss.test.selenium.support.ui.ElementPresent;
-import org.openqa.selenium.Alert;
-import org.openqa.selenium.By;
-import org.openqa.selenium.WebDriver;
-import org.openqa.selenium.WebElement;
import org.richfaces.tests.metamer.ftest.annotations.Inject;
import org.richfaces.tests.metamer.ftest.annotations.IssueTracking;
import org.richfaces.tests.metamer.ftest.annotations.RegressionTest;
import org.richfaces.tests.metamer.ftest.annotations.Templates;
import org.richfaces.tests.metamer.ftest.annotations.Use;
import org.richfaces.tests.metamer.ftest.webdriver.MetamerPage;
-import org.richfaces.tests.metamer.ftest.webdriver.MetamerPage.WaitRequestType;
import org.testng.annotations.Test;
-import com.google.common.base.Predicate;
-
/**
* @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
@@ -63,8 +47,6 @@
*/
public class TestPanelMenuGroupClientSideHandlers extends AbstractPanelMenuGroupTest {
- private static final String ATTR_INPUT_LOC_FORMAT = "input[id$=on{0}Input]";
-
@Inject
@Use(empty = true)
String event;
@@ -85,6 +67,10 @@ public URL getTestUrl() {
return buildUrl(contextPath, "faces/components/richPanelMenuGroup/simple.xhtml");
}
+ public MetamerPage getPage() {
+ return page;
+ }
+
@Test
@Use(field = "event", value = "ajaxCollapsionEvents")
public void testClientSideCollapsionEvent() {
@@ -134,7 +120,7 @@ public void testClientSideExpansionEventsOrderClient() {
testRequestEventsBefore(clientExpansionEvents);
page.topGroup.toggle();
page.group1.toggle();
- executeJS("window.metamerEvents = \"\";");
+ cleanMetamerEventsVariable();
page.topGroup.toggle();
testRequestEventsAfter(clientExpansionEvents);
}
@@ -159,7 +145,7 @@ public void testClientSideExpansionEventsOrderAjax() {
page.topGroup.setMode(ajax);
page.topGroup.toggle();
testRequestEventsBefore(ajaxExpansionEvents);
- executeJS("window.metamerEvents = \"\";");
+ cleanMetamerEventsVariable();
page.topGroup.toggle();
testRequestEventsAfter(ajaxExpansionEvents);
}
@@ -189,9 +175,11 @@ public void testClientSideExpansionEventsServerBeforeSwitch() {
page.topGroup.setMode(server);
page.topGroup.toggle();
page.topGroup.setMode(null);
- testRequestEventsBeforeByAlert(event);
+ // testRequestEventsBeforeByAlert(event);
+ testRequestEventsBefore(event);
page.topGroup.toggle();
- testRequestEventsAfterByAlert(event);
+ // testRequestEventsAfterByAlert(event);
+ testRequestEventsAfter(event);
}
@Test
@@ -204,9 +192,11 @@ public void testClientSideExpansionEventsServerBeforeExpand() {
page.topGroup.setMode(server);
page.topGroup.toggle();
page.topGroup.setMode(null);
- testRequestEventsBeforeByAlert(event);
+ // testRequestEventsBeforeByAlert(event);
+ testRequestEventsBefore(event);
page.topGroup.toggle();
- testRequestEventsAfterByAlert(event);
+ // testRequestEventsAfterByAlert(event);
+ testRequestEventsAfter(event);
}
@Test
@@ -223,77 +213,11 @@ public void testClientSideExpansionEventsServerBeforeExpandIterationComponents()
public void testClientSideCollapsionEventsServer() {
panelMenuGroupAttributes.set(mode, server);
page.topGroup.setMode(null);
- testRequestEventsBeforeByAlert(event);
+ // testRequestEventsBeforeByAlert(event);
+ testRequestEventsBefore(event);
page.topGroup.toggle();
- testRequestEventsAfterByAlert(event);
- }
-
- public void testRequestEventsBefore(String... events) {
- for (String event : events) {
- String inputExp = format(ATTR_INPUT_LOC_FORMAT, event);
- WebElement input = page.attributesTable.findElement(By.cssSelector(inputExp));
- String inputVal = format("metamerEvents += \"{0} \"", event);
- // even there would be some events (in params) twice, don't expect handle routine to be executed twice
- input.clear();
- waiting(1000);
- input = page.attributesTable.findElement(By.cssSelector(inputExp));
- input.sendKeys(inputVal);
- // sendKeys triggers page reload automatically
- waiting(300);
- Graphene.waitAjax().until(ElementPresent.getInstance().element(page.attributesTable));
- input = page.attributesTable.findElement(By.cssSelector(inputExp));
- MetamerPage.waitRequest(input, WaitRequestType.HTTP).submit();
- }
- executeJS("window.metamerEvents = \"\";");
- }
-
- public void testRequestEventsAfter(String... events) {
- String[] actualEvents = ((String)executeJS("return window.metamerEvents")).split(" ");
- assertEquals(actualEvents, events, format("The events ({0}) don't came in right order ({1})",
- Arrays.deepToString(actualEvents), Arrays.deepToString(events)));
- }
-
- public void testRequestEventsBeforeByAlert(String... events) {
- for (String event : events) {
- String inputExp = format(ATTR_INPUT_LOC_FORMAT, event);
- WebElement input = page.attributesTable.findElement(By.cssSelector(inputExp));
-
- input.sendKeys(format("alert(\"{0}\")", event));
- // sendKeys triggers page reload automatically
- waiting(300);
- Graphene.waitAjax().until(ElementPresent.getInstance().element(page.attributesTable));
- input = page.attributesTable.findElement(By.cssSelector(inputExp));
- MetamerPage.waitRequest(input, WaitRequestType.HTTP).submit();
- }
- }
-
- public void testRequestEventsAfterByAlert(String... events) {
- List<String> list = new LinkedList<String>();
-
- for (int i = 0; i < events.length; i++) {
- AlertPresent ap = new AlertPresent();
- Graphene.waitGui().until(ap);
- if (ap.apply(driver)) {
- list.add(ap.getAlert().getText());
- ap.getAlert().accept();
- }
- }
-
- String[] actualEvents = list.toArray(new String[list.size()]);
- assertEquals(actualEvents, events, format("The events ({0}) don't came in right order ({1})",
- Arrays.deepToString(actualEvents), Arrays.deepToString(events)));
- }
-
- private class AlertPresent implements Predicate<WebDriver> {
- private Alert alert;
-
- @Override
- public boolean apply(@Nullable WebDriver driver) {
- alert = driver.switchTo().alert();
- return alert != null;
- }
-
- public Alert getAlert() { return alert; }
+ // testRequestEventsAfterByAlert(event);
+ testRequestEventsAfter(event);
}
}
@@ -22,7 +22,6 @@
package org.richfaces.tests.metamer.ftest.richPanelMenuItem;
import org.jboss.arquillian.graphene.enricher.findby.FindBy;
-import org.openqa.selenium.WebElement;
import org.richfaces.tests.metamer.ftest.webdriver.MetamerPage;
import org.richfaces.tests.page.fragments.impl.panelMenuItem.RichFacesPanelMenuItem;
@@ -36,6 +35,4 @@
@FindBy(jquery = "div[id$=item12]")
RichFacesPanelMenuItem item;
- @FindBy(css = "table[id$='attributes:attributes']")
- public WebElement attributesTable;
}
Oops, something went wrong.

0 comments on commit f355ed0

Please sign in to comment.