Author: lfryc(a)redhat.com
Date: 2010-07-10 16:54:34 -0400 (Sat, 10 Jul 2010)
New Revision: 17880
Added:
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/richfaces/tests/testapp/a4jActionListener/
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/richfaces/tests/testapp/a4jActionListener/A4JActionListenerTestCase.java
Modified:
root/tests/metamer/trunk/ftest/src/test/resources/testng.xml
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/richfaces/tests/testapp/AbstractTestappTestCase.java
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/richfaces/tests/testapp/commandButton/CommandButtonTestCase.java
Log:
* added new test case for a4j:actionListener * test case for command button refactored *
added factory method for jQuery selectors
Modified: root/tests/metamer/trunk/ftest/src/test/resources/testng.xml
===================================================================
--- root/tests/metamer/trunk/ftest/src/test/resources/testng.xml 2010-07-10 20:53:48 UTC
(rev 17879)
+++ root/tests/metamer/trunk/ftest/src/test/resources/testng.xml 2010-07-10 20:54:34 UTC
(rev 17880)
@@ -1,10 +1,10 @@
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="seleniumTest">
- <test name="SimpleComponents">
- <parameter name="templates" value="plain redDiv redDiv,blueDiv
"/>
+ <test name="Component Tests">
+ <parameter name="templates" value="plain richDataTable1,redDiv
richDataTable2,redDiv a4jRepeat1 a4jRepeat2 hDataTable1 hDataTable2 uiRepeat1
uiRepeat2"/>
<packages>
- <package name="org.richfaces.tests.testapp.commandButton" />
+ <package name="org.richfaces.tests.testapp" />
</packages>
</test>
Modified:
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/richfaces/tests/testapp/AbstractTestappTestCase.java
===================================================================
---
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/richfaces/tests/testapp/AbstractTestappTestCase.java 2010-07-10
20:53:48 UTC (rev 17879)
+++
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/richfaces/tests/testapp/AbstractTestappTestCase.java 2010-07-10
20:54:34 UTC (rev 17880)
@@ -22,7 +22,6 @@
package org.richfaces.tests.testapp;
-import static org.jboss.test.selenium.locator.LocatorFactory.jq;
import static org.jboss.test.selenium.utils.URLUtils.buildUrl;
import java.net.URL;
@@ -109,17 +108,18 @@
urlParams = "?templates=" + templates[0];
}
selenium.open(buildUrl(getTestUrl() + urlParams));
+ selenium.waitForPageToLoad(TIMEOUT);
}
/**
* Invalidates session by clicking on a button on tested page.
*/
public void invalidateSession() {
- JQueryLocator invalidateButton = jq("#form input[value=Invalidate
Session]");
+ JQueryLocator invalidateButton = new JQueryLocator("input[value=Invalidate
Session]");
selenium.click(invalidateButton);
selenium.waitForPageToLoad(TIMEOUT);
}
-
+
/**
* Forces the current thread sleep for given time.
*
@@ -134,4 +134,19 @@
e.printStackTrace();
}
}
+
+ /**
+ * Factory method for creating instances of class JQueryLocator which locates the
element using <a
+ *
href="http://api.jquery.com/category/selectors/">JQuery
Selector</a> syntax. It adds "div.content " in front of
+ * each selector.
+ *
+ * @param jquerySelector
+ * the jquery selector
+ * @return the j query locator
+ * @see JQueryLocator
+ */
+ public static JQueryLocator pjq(String jquerySelector) {
+ return new JQueryLocator("div.content " + jquerySelector);
+ }
+
}
Added:
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/richfaces/tests/testapp/a4jActionListener/A4JActionListenerTestCase.java
===================================================================
---
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/richfaces/tests/testapp/a4jActionListener/A4JActionListenerTestCase.java
(rev 0)
+++
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/richfaces/tests/testapp/a4jActionListener/A4JActionListenerTestCase.java 2010-07-10
20:54:34 UTC (rev 17880)
@@ -0,0 +1,136 @@
+/*******************************************************************************
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, 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.testapp.a4jActionListener;
+
+import static org.jboss.test.selenium.utils.URLUtils.buildUrl;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+
+import java.net.URL;
+
+import org.jboss.test.selenium.locator.ElementLocator;
+import org.jboss.test.selenium.locator.JQueryLocator;
+import org.richfaces.tests.testapp.AbstractTestappTestCase;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.Test;
+
+/**
+ * Test case for page /faces/components/a4jActionListener/all.xhtml
+ *
+ * @author <a href="mailto:ppitonak@redhat.com">Pavol Pitonak</a>
+ * @version $Revision$
+ */
+public class A4JActionListenerTestCase extends AbstractTestappTestCase {
+
+ private ElementLocator invokeButtonType =
pjq("input[id$=invokeByTypeButton]");
+ private ElementLocator invokeButtonBinding =
pjq("input[id$=invokeByBindingButton]");
+ private ElementLocator invokeButtonMethod =
pjq("input[id$=invokeMethodButton]");
+ private ElementLocator invokeButtonCC =
pjq("input[id$=invokeFromCCButton:button]");
+ private JQueryLocator message = pjq("ul[id$=messages] li");
+
+ @Override
+ public URL getTestUrl() {
+ return buildUrl(contextPath,
"faces/components/a4jActionListener/all.xhtml");
+ }
+
+ @Override
+ @AfterMethod(alwaysRun = true)
+ public void invalidateSession() {
+ super.invalidateSession();
+ }
+
+ @Test(dataProvider = "templates")
+ public void testInvokeListenerByType(String templates) {
+ final String hashCodeRegExp = "@[0-9a-fA-F]{1,}$";
+ final String msg = "Implementation of ActionListener created and called:
"
+ +
"org.richfaces.testapp.bean.A4JActionListenerBean$ActionListenerImpl";
+
+ selenium.click(invokeButtonType);
+ waitGui.until(elementPresent.locator(message));
+ String output1 = selenium.getText(message);
+
+ assertEquals(output1.replaceAll(hashCodeRegExp, ""), msg, "Message
after first invocation of listener by type.");
+
+ int count = selenium.getCount(message);
+ assertEquals(count, 1, "Only one message should be displayed on the
page.");
+
+ // do the same once again
+
+ selenium.click(invokeButtonType);
+ waitGui.until(elementPresent.locator(message));
+ String output2 = selenium.getText(message);
+
+ assertEquals(output2.replaceAll(hashCodeRegExp, ""), msg, "Message
after second invocation of listener by type");
+
+ // check that a new object of ActionListenerImpl was created
+ String hashcode1 = output1.replace(msg, "");
+ String hashcode2 = output2.replace(msg, "");
+ assertFalse(hashcode1.equals(hashcode2), "New object of class
ActionListenerImpl should be instantiated.");
+
+ count = selenium.getCount(message);
+ assertEquals(count, 1, "Only one message should be displayed on the
page.");
+
+ }
+
+ @Test(dataProvider = "templates")
+ public void testInvokeListenerByBinding(String templates) {
+ final String msg = "Bound listener called";
+
+ selenium.click(invokeButtonBinding);
+ waitGui.until(elementPresent.locator(message));
+ String output = selenium.getText(message);
+
+ assertEquals(output, msg, "Message after first invocation of listener by
binding.");
+
+ int count = selenium.getCount(message);
+ assertEquals(count, 1, "Only one message should be displayed on the
page.");
+ }
+
+ @Test(dataProvider = "templates")
+ public void testInvokeListenerMethod(String templates) {
+ final String msg = "Method expression listener called";
+
+ selenium.click(invokeButtonMethod);
+ waitGui.until(elementPresent.locator(message));
+ String output = selenium.getText(message);
+
+ assertEquals(output, msg, "Message after first invocation of listener
method.");
+
+ int count = selenium.getCount(message);
+ assertEquals(count, 1, "Only one message should be displayed on the
page.");
+ }
+
+ @Test(dataProvider = "templates")
+ public void testInvokeListenerMethodCC(String templates) {
+ final String msg = "Method expression listener called from composite
component";
+
+ selenium.click(invokeButtonCC);
+ waitGui.until(elementPresent.locator(message));
+ String output = selenium.getText(message);
+
+ assertEquals(output, msg, "Message after first invocation of listener method
from composite component.");
+
+ int count = selenium.getCount(message);
+ assertEquals(count, 1, "Only one message should be displayed on the
page.");
+ }
+}
Modified:
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/richfaces/tests/testapp/commandButton/CommandButtonTestCase.java
===================================================================
---
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/richfaces/tests/testapp/commandButton/CommandButtonTestCase.java 2010-07-10
20:53:48 UTC (rev 17879)
+++
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/richfaces/tests/testapp/commandButton/CommandButtonTestCase.java 2010-07-10
20:54:34 UTC (rev 17880)
@@ -22,11 +22,10 @@
package org.richfaces.tests.testapp.commandButton;
-import static org.jboss.test.selenium.locator.LocatorFactory.jq;
+import static org.jboss.test.selenium.utils.URLUtils.buildUrl;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
-import static org.jboss.test.selenium.utils.URLUtils.buildUrl;
import java.net.URL;
@@ -36,7 +35,6 @@
import org.jboss.test.selenium.locator.JQueryLocator;
import org.richfaces.tests.testapp.AbstractTestappTestCase;
import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
/**
@@ -47,11 +45,11 @@
*/
public class CommandButtonTestCase extends AbstractTestappTestCase {
- private JQueryLocator input = jq("#form\\:input");
- private JQueryLocator button = jq("#form\\:commandButton");
- private JQueryLocator output1 = jq("#form\\:output1");
- private JQueryLocator output2 = jq("#form\\:output2");
- private JQueryLocator output3 = jq("#form\\:output3");
+ private JQueryLocator input = pjq("input[id$=input]");
+ private JQueryLocator button = pjq("input[id$=commandButton]");
+ private JQueryLocator output1 = pjq("span[id$=output1]");
+ private JQueryLocator output2 = pjq("span[id$=output2]");
+ private JQueryLocator output3 = pjq("span[id$=output3]");
@Override
public URL getTestUrl() {
@@ -59,7 +57,7 @@
}
@Override
- @BeforeMethod(alwaysRun=true)
+ @AfterMethod(alwaysRun=true)
public void invalidateSession() {
super.invalidateSession();
}
@@ -100,9 +98,9 @@
@Test(dataProvider = "templates")
public void testAction(String templates) {
- JQueryLocator doubleStringAction =
jq("#form\\:attributes\\:actionInput\\:0");
- JQueryLocator first6CharsAction =
jq("#form\\:attributes\\:actionInput\\:1");
- JQueryLocator toUpperCaseAction =
jq("#form\\:attributes\\:actionInput\\:2");
+ JQueryLocator doubleStringAction =
pjq("input[value=doubleStringAction]");
+ JQueryLocator first6CharsAction =
pjq("input[value=first6CharsAction]");
+ JQueryLocator toUpperCaseAction =
pjq("input[value=toUpperCaseAction]");
selenium.click(doubleStringAction);
selenium.waitForPageToLoad(TIMEOUT);
@@ -132,9 +130,9 @@
@Test(dataProvider = "templates")
public void testActionListener(String templates) {
- JQueryLocator doubleStringActionListener =
jq("input[value=doubleStringActionListener]");
- JQueryLocator first6CharsActionListener =
jq("input[value=first6CharsActionListener]");
- JQueryLocator toUpperCaseActionListener =
jq("input[value=toUpperCaseActionListener]");
+ JQueryLocator doubleStringActionListener =
pjq("input[value=doubleStringActionListener]");
+ JQueryLocator first6CharsActionListener =
pjq("input[value=first6CharsActionListener]");
+ JQueryLocator toUpperCaseActionListener =
pjq("input[value=toUpperCaseActionListener]");
selenium.click(doubleStringActionListener);
selenium.waitForPageToLoad(TIMEOUT);
@@ -165,7 +163,7 @@
@Test(dataProvider = "templates")
public void testDisabled(String templates) {
- JQueryLocator disabledChecbox =
jq("#form\\:attributes\\:disabledInput");
+ JQueryLocator disabledChecbox = pjq("input[id$=disabledInput]");
AttributeLocator disabledAttribute = button.getAttribute(new
Attribute("disabled"));
selenium.click(disabledChecbox);
@@ -177,7 +175,7 @@
@Test(dataProvider = "templates")
public void testOnclick(String templates) {
- JQueryLocator onclickInput = jq("#form\\:attributes\\:onclickInput");
+ JQueryLocator onclickInput = pjq("input[id$=onclickInput]");
final AttributeLocator onclickAttribute = button.getAttribute(new
Attribute("onclick"));
final String value = "alert('onclick')";
@@ -190,11 +188,11 @@
@Test(dataProvider = "templates")
public void testStyleClass(String templates) {
- JQueryLocator blue = jq("table#form\\:attributes\\:styleClassInput
input[value=blue]");
- JQueryLocator red = jq("table#form\\:attributes\\:styleClassInput
input[value=red]");
- JQueryLocator wide = jq("table#form\\:attributes\\:styleClassInput
input[value=wide]");
- JQueryLocator big = jq("table#form\\:attributes\\:styleClassInput
input[value=big]");
- JQueryLocator none = jq("table#form\\:attributes\\:styleClassInput
input[value=]");
+ JQueryLocator blue = pjq("input[name$=styleClassInput][value=blue]");
+ JQueryLocator red = pjq("input[name$=styleClassInput][value=red]");
+ JQueryLocator wide = pjq("input[name$=styleClassInput][value=wide]");
+ JQueryLocator big = pjq("input[name$=styleClassInput][value=big]");
+ JQueryLocator none = pjq("input[name$=styleClassInput][value=]");
final AttributeLocator classAttribute = button.getAttribute(new
Attribute("class"));
@@ -221,7 +219,7 @@
@Test(dataProvider = "templates")
public void testStyle(String templates) {
- JQueryLocator styleInput = jq("#form\\:attributes\\:styleInput");
+ JQueryLocator styleInput = pjq("input[id$=styleInput]");
final AttributeLocator attribute = button.getAttribute(new
Attribute("style"));
final String value = "font-size: 20px;";
@@ -234,7 +232,7 @@
@Test(dataProvider = "templates")
public void testValue(String templates) {
- JQueryLocator valueInput = jq("#form\\:attributes\\:valueInput");
+ JQueryLocator valueInput = pjq("input[id$=valueInput]");
final AttributeLocator attribute = button.getAttribute(new
Attribute("value"));
final String value = "new label";
@@ -245,22 +243,4 @@
assertEquals(selenium.getAttribute(attribute), value, "Value of the button
did not change");
}
- // functionality probably not implemented yet
- // @Test(dataProvider = "templates")
- public void testRender(String templates) {
- JQueryLocator renderInput = jq("#form\\:attributes\\:renderInput");
-
- selenium.typeKeys(renderInput, "output1");
- selenium.fireEvent(renderInput, Event.BLUR);
- selenium.waitForPageToLoad(TIMEOUT);
- selenium.typeKeys(input, "aaa");
- selenium.click(button);
-
- waitGui.until(textEquals.locator(output1).text("aaa"));
-
- assertTrue(selenium.isElementPresent(output1), "output1 should be
visible");
- assertFalse(selenium.isElementPresent(output2), "output2 should not be
visible");
- assertFalse(selenium.isElementPresent(output3), "output3 should not be
visible");
- }
-
}