Author: lfryc(a)redhat.com
Date: 2010-07-10 16:52:23 -0400 (Sat, 10 Jul 2010)
New Revision: 17874
Added:
root/tests/metamer/trunk/ftest/test-source/src/
root/tests/metamer/trunk/ftest/test-source/src/main/
root/tests/metamer/trunk/ftest/test-source/src/main/java/
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/richfaces/
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/richfaces/tests/
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/richfaces/tests/testapp/
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/
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/richfaces/tests/testapp/commandButton/CommandButtonTestCase.java
Removed:
root/tests/metamer/trunk/ftest/src/test/java/org/richfaces/tests/testapp/AbstractTestappTestCase.java
root/tests/metamer/trunk/ftest/src/test/java/org/richfaces/tests/testapp/commandButton/CommandButtonTestCase.java
Log:
moved test sources to test-source module as main sources
Deleted:
root/tests/metamer/trunk/ftest/src/test/java/org/richfaces/tests/testapp/AbstractTestappTestCase.java
===================================================================
---
root/tests/metamer/trunk/ftest/src/test/java/org/richfaces/tests/testapp/AbstractTestappTestCase.java 2010-07-10
20:51:14 UTC (rev 17873)
+++
root/tests/metamer/trunk/ftest/src/test/java/org/richfaces/tests/testapp/AbstractTestappTestCase.java 2010-07-10
20:52:23 UTC (rev 17874)
@@ -1,137 +0,0 @@
-/*******************************************************************************
- * 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;
-
-import static org.jboss.test.selenium.locator.LocatorFactory.jq;
-import static org.jboss.test.selenium.utils.URLUtils.buildUrl;
-
-import java.net.URL;
-
-import org.jboss.test.selenium.AbstractTestCase;
-import org.jboss.test.selenium.locator.JQueryLocator;
-import org.testng.SkipException;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.DataProvider;
-import org.testng.annotations.Optional;
-import org.testng.annotations.Parameters;
-
-/**
- * Abstract test case used as a basis for majority of test cases.
- *
- * @author <a href="mailto:ppitonak@redhat.com">Pavol Pitonak</a>
- * @version $Revision$
- */
-public abstract class AbstractTestappTestCase extends AbstractTestCase {
-
- /**
- * timeout in miliseconds
- */
- public static final long TIMEOUT = 5000;
- private String[][] templates;
-
- /**
- * Returns the url to test page to be opened by Selenium
- *
- * @return absolute url to the test page to be opened by Selenium
- */
- public abstract URL getTestUrl();
-
- /**
- * Data provider for templates.
- *
- * @return array containing templates that should be used (defined in testng.xml) or
default array (containing only
- * plain template) if nothing is defined
- */
- @DataProvider(name = "templates")
- protected Object[][] getTemplates() {
- if (templates != null && templates.length > 0) {
- return templates;
- }
-
- return new Object[][]{{"plain"}};
- }
-
- /**
- * Loads and parses attribute "templates" from testng.xml.
- *
- * @param urlParams
- */
- @BeforeClass(alwaysRun = true)
- @Parameters({"templates"})
- public void initTemplates(@Optional String urlParams) {
- if (urlParams == null) {
- return;
- }
-
- String[] array = urlParams.split(" ");
- templates = new String[array.length][];
-
- for (int i = 0; i < array.length; i++) {
- templates[i] = new String[1];
- templates[i][0] = array[i];
- }
- }
-
- /**
- * Opens the tested page. If templates is not empty nor null, it appends url
parameter with templates.
- *
- * @param templates
- * templates that will be used for test, e.g. "red_div"
- */
- @BeforeMethod(alwaysRun = true)
- public void loadPage(Object[] templates) {
- if (selenium == null) {
- new SkipException("selenium isn't initialized");
- }
- String urlParams = "";
- if (templates != null && templates.length != 0) {
- urlParams = "?templates=" + templates[0];
- }
- selenium.open(buildUrl(getTestUrl() + urlParams));
- }
-
- /**
- * Invalidates session by clicking on a button on tested page.
- */
- public void invalidateSession() {
- JQueryLocator invalidateButton = jq("#form input[value=Invalidate
Session]");
- selenium.click(invalidateButton);
- selenium.waitForPageToLoad(TIMEOUT);
- }
-
- /**
- * Forces the current thread sleep for given time.
- *
- * @param millis
- * number of miliseconds for which the thread will sleep
- */
- @Deprecated
- protected void waitFor(long millis) {
- try {
- Thread.sleep(millis);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
-}
Deleted:
root/tests/metamer/trunk/ftest/src/test/java/org/richfaces/tests/testapp/commandButton/CommandButtonTestCase.java
===================================================================
---
root/tests/metamer/trunk/ftest/src/test/java/org/richfaces/tests/testapp/commandButton/CommandButtonTestCase.java 2010-07-10
20:51:14 UTC (rev 17873)
+++
root/tests/metamer/trunk/ftest/src/test/java/org/richfaces/tests/testapp/commandButton/CommandButtonTestCase.java 2010-07-10
20:52:23 UTC (rev 17874)
@@ -1,265 +0,0 @@
-/*******************************************************************************
- * 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.commandButton;
-
-import static org.jboss.test.selenium.locator.LocatorFactory.jq;
-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;
-
-import org.jboss.test.selenium.dom.Event;
-import org.jboss.test.selenium.locator.Attribute;
-import org.jboss.test.selenium.locator.AttributeLocator;
-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/commandButton/simple.xhtml
- *
- * @author <a href="mailto:ppitonak@redhat.com">Pavol Pitonak</a>
- * @version $Revision$
- */
-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");
-
- @Override
- public URL getTestUrl() {
- return buildUrl(contextPath,
"faces/components/commandButton/simple.xhtml");
- }
-
- @Override
- @AfterMethod
- public void invalidateSession() {
- super.invalidateSession();
- }
-
- @Test(dataProvider = "templates", groups = "client-side-perf")
- public void testSimpleClick(String templates) {
- selenium.typeKeys(input, "RichFaces 4");
- selenium.click(button);
-
- waitGui.until(textEquals.locator(output1).text("RichFaces 4"));
-
- String output = selenium.getText(output1);
- assertEquals(output, "RichFaces 4", "output1 when 'RichFaces
4' in input");
-
- output = selenium.getText(output2);
- assertEquals(output, "RichFa", "output2 when 'RichFaces 4'
in input");
-
- output = selenium.getText(output3);
- assertEquals(output, "RICHFACES 4", "output3 when 'RichFaces
4' in input");
- }
-
- @Test(dataProvider = "templates")
- public void testSimpleClickUnicode(String templates) {
- selenium.typeKeys(input, "ľščťžýáíéňô");
- selenium.click(button);
-
- waitGui.until(textEquals.locator(output1).text("ľščťžýáíéňô"));
-
- String output = selenium.getText(output1);
- assertEquals(output, "ľščťžýáíéňô", "output1 when
'ľščťžýáíéňô' in input");
-
- output = selenium.getText(output2);
- assertEquals(output, "ľščťžý", "output2 when 'ľščťžýáíéňô'
in input");
-
- output = selenium.getText(output3);
- assertEquals(output, "ĽŠČŤŽÝÁÍÉŇÔ", "output3 when
'ľščťžýáíéňô' in input");
- }
-
- @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");
-
- selenium.click(doubleStringAction);
- selenium.waitForPageToLoad(TIMEOUT);
- selenium.typeKeys(input, "RichFaces 4");
- selenium.click(button);
- waitGui.until(textEquals.locator(output1).text("RichFaces 4"));
- String output = selenium.getText(output2);
- assertEquals(output, "RichFaces 4RichFaces 4",
- "output2 when 'RichFaces 4' in input and doubleStringAction
selected");
-
- selenium.click(first6CharsAction);
- selenium.waitForPageToLoad(TIMEOUT);
- selenium.typeKeys(input, "RichFaces 4ň");
- selenium.click(button);
- waitGui.until(textEquals.locator(output1).text("RichFaces 4ň"));
- output = selenium.getText(output2);
- assertEquals(output, "RichFa", "output2 when 'RichFaces
4ň' in input and first6CharsAction selected");
-
- selenium.click(toUpperCaseAction);
- selenium.waitForPageToLoad(TIMEOUT);
- selenium.typeKeys(input, "RichFaces 4ě");
- selenium.click(button);
- waitGui.until(textEquals.locator(output1).text("RichFaces 4ě"));
- output = selenium.getText(output2);
- assertEquals(output, "RICHFACES 4Ě", "output2 when 'RichFaces
4ě' in input and toUpperCaseAction selected");
- }
-
- @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]");
-
- selenium.click(doubleStringActionListener);
- selenium.waitForPageToLoad(TIMEOUT);
- selenium.typeKeys(input, "RichFaces 4");
- selenium.click(button);
- waitGui.until(textEquals.locator(output1).text("RichFaces 4"));
- String output = selenium.getText(output3);
- assertEquals(output, "RichFaces 4RichFaces 4",
- "output2 when 'RichFaces 4' in input and
doubleStringActionListener selected");
-
- selenium.click(first6CharsActionListener);
- selenium.waitForPageToLoad(TIMEOUT);
- selenium.typeKeys(input, "RichFaces 4ň");
- selenium.click(button);
- waitGui.until(textEquals.locator(output1).text("RichFaces 4ň"));
- output = selenium.getText(output3);
- assertEquals(output, "RichFa", "output2 when 'RichFaces
4ň' in input and first6CharsActionListener selected");
-
- selenium.click(toUpperCaseActionListener);
- selenium.waitForPageToLoad(TIMEOUT);
- selenium.typeKeys(input, "RichFaces 4ě");
- selenium.click(button);
- waitGui.until(textEquals.locator(output1).text("RichFaces 4ě"));
- output = selenium.getText(output3);
- assertEquals(output, "RICHFACES 4Ě",
- "output2 when 'RichFaces 4ě' in input and
toUpperCaseActionListener selected");
- }
-
- @Test(dataProvider = "templates")
- public void testDisabled(String templates) {
- JQueryLocator disabledChecbox =
jq("#form\\:attributes\\:disabledInput");
- AttributeLocator disabledAttribute = button.getAttribute(new
Attribute("disabled"));
-
- selenium.click(disabledChecbox);
- selenium.waitForPageToLoad(TIMEOUT);
-
- String isDisabled = selenium.getAttribute(disabledAttribute);
- assertEquals(isDisabled.toLowerCase(), "disabled", "The value of
attribute disabled");
- }
-
- @Test(dataProvider = "templates")
- public void testOnclick(String templates) {
- JQueryLocator onclickInput = jq("#form\\:attributes\\:onclickInput");
- final AttributeLocator onclickAttribute = button.getAttribute(new
Attribute("onclick"));
- final String value = "alert('onclick')";
-
- selenium.type(onclickInput, value);
- selenium.fireEvent(onclickInput, Event.BLUR);
-
- selenium.waitForPageToLoad(TIMEOUT);
- assertEquals(selenium.getAttribute(onclickAttribute), value, "onclick
attribute did not change correctly");
- }
-
- @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=]");
-
- final AttributeLocator classAttribute = button.getAttribute(new
Attribute("class"));
-
- selenium.click(blue);
- selenium.waitForPageToLoad(TIMEOUT);
- assertTrue(selenium.belongsClass(button, "blue"), "Button's
class was not changed to 'blue'");
-
- selenium.click(red);
- selenium.waitForPageToLoad(TIMEOUT);
- assertTrue(selenium.belongsClass(button, "red"), "Button's
class was not changed to 'red'");
-
- selenium.click(wide);
- selenium.waitForPageToLoad(TIMEOUT);
- assertTrue(selenium.belongsClass(button, "wide"), "Button's
class was not changed to 'wide'");
-
- selenium.click(big);
- selenium.waitForPageToLoad(TIMEOUT);
- assertTrue(selenium.belongsClass(button, "big"), "Button's
class was not changed to 'big'");
-
- selenium.click(none);
- selenium.waitForPageToLoad(TIMEOUT);
- assertFalse(selenium.isAttributePresent(classAttribute), "Button's class
was not removed.");
- }
-
- @Test(dataProvider = "templates")
- public void testStyle(String templates) {
- JQueryLocator styleInput = jq("#form\\:attributes\\:styleInput");
- final AttributeLocator attribute = button.getAttribute(new
Attribute("style"));
- final String value = "font-size: 20px;";
-
- selenium.type(styleInput, value);
- selenium.fireEvent(styleInput, Event.BLUR);
-
- selenium.waitForPageToLoad(TIMEOUT);
- assertEquals(selenium.getAttribute(attribute), value, "Style of the button
did not change");
- }
-
- @Test(dataProvider = "templates")
- public void testValue(String templates) {
- JQueryLocator valueInput = jq("#form\\:attributes\\:valueInput");
- final AttributeLocator attribute = button.getAttribute(new
Attribute("value"));
- final String value = "new label";
-
- selenium.type(valueInput, value);
- selenium.fireEvent(valueInput, Event.BLUR);
-
- selenium.waitForPageToLoad(TIMEOUT);
- 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");
- }
-
-}
Copied:
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/richfaces/tests/testapp/AbstractTestappTestCase.java
(from rev 17873,
root/tests/metamer/trunk/ftest/src/test/java/org/richfaces/tests/testapp/AbstractTestappTestCase.java)
===================================================================
---
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/richfaces/tests/testapp/AbstractTestappTestCase.java
(rev 0)
+++
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/richfaces/tests/testapp/AbstractTestappTestCase.java 2010-07-10
20:52:23 UTC (rev 17874)
@@ -0,0 +1,137 @@
+/*******************************************************************************
+ * 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;
+
+import static org.jboss.test.selenium.locator.LocatorFactory.jq;
+import static org.jboss.test.selenium.utils.URLUtils.buildUrl;
+
+import java.net.URL;
+
+import org.jboss.test.selenium.AbstractTestCase;
+import org.jboss.test.selenium.locator.JQueryLocator;
+import org.testng.SkipException;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Optional;
+import org.testng.annotations.Parameters;
+
+/**
+ * Abstract test case used as a basis for majority of test cases.
+ *
+ * @author <a href="mailto:ppitonak@redhat.com">Pavol Pitonak</a>
+ * @version $Revision$
+ */
+public abstract class AbstractTestappTestCase extends AbstractTestCase {
+
+ /**
+ * timeout in miliseconds
+ */
+ public static final long TIMEOUT = 5000;
+ private String[][] templates;
+
+ /**
+ * Returns the url to test page to be opened by Selenium
+ *
+ * @return absolute url to the test page to be opened by Selenium
+ */
+ public abstract URL getTestUrl();
+
+ /**
+ * Data provider for templates.
+ *
+ * @return array containing templates that should be used (defined in testng.xml) or
default array (containing only
+ * plain template) if nothing is defined
+ */
+ @DataProvider(name = "templates")
+ protected Object[][] getTemplates() {
+ if (templates != null && templates.length > 0) {
+ return templates;
+ }
+
+ return new Object[][]{{"plain"}};
+ }
+
+ /**
+ * Loads and parses attribute "templates" from testng.xml.
+ *
+ * @param urlParams
+ */
+ @BeforeClass(alwaysRun = true)
+ @Parameters({"templates"})
+ public void initTemplates(@Optional String urlParams) {
+ if (urlParams == null) {
+ return;
+ }
+
+ String[] array = urlParams.split(" ");
+ templates = new String[array.length][];
+
+ for (int i = 0; i < array.length; i++) {
+ templates[i] = new String[1];
+ templates[i][0] = array[i];
+ }
+ }
+
+ /**
+ * Opens the tested page. If templates is not empty nor null, it appends url
parameter with templates.
+ *
+ * @param templates
+ * templates that will be used for test, e.g. "red_div"
+ */
+ @BeforeMethod(alwaysRun = true)
+ public void loadPage(Object[] templates) {
+ if (selenium == null) {
+ new SkipException("selenium isn't initialized");
+ }
+ String urlParams = "";
+ if (templates != null && templates.length != 0) {
+ urlParams = "?templates=" + templates[0];
+ }
+ selenium.open(buildUrl(getTestUrl() + urlParams));
+ }
+
+ /**
+ * Invalidates session by clicking on a button on tested page.
+ */
+ public void invalidateSession() {
+ JQueryLocator invalidateButton = jq("#form input[value=Invalidate
Session]");
+ selenium.click(invalidateButton);
+ selenium.waitForPageToLoad(TIMEOUT);
+ }
+
+ /**
+ * Forces the current thread sleep for given time.
+ *
+ * @param millis
+ * number of miliseconds for which the thread will sleep
+ */
+ @Deprecated
+ protected void waitFor(long millis) {
+ try {
+ Thread.sleep(millis);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+}
Copied:
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/richfaces/tests/testapp/commandButton/CommandButtonTestCase.java
(from rev 17873,
root/tests/metamer/trunk/ftest/src/test/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
(rev 0)
+++
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/richfaces/tests/testapp/commandButton/CommandButtonTestCase.java 2010-07-10
20:52:23 UTC (rev 17874)
@@ -0,0 +1,265 @@
+/*******************************************************************************
+ * 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.commandButton;
+
+import static org.jboss.test.selenium.locator.LocatorFactory.jq;
+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;
+
+import org.jboss.test.selenium.dom.Event;
+import org.jboss.test.selenium.locator.Attribute;
+import org.jboss.test.selenium.locator.AttributeLocator;
+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/commandButton/simple.xhtml
+ *
+ * @author <a href="mailto:ppitonak@redhat.com">Pavol Pitonak</a>
+ * @version $Revision$
+ */
+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");
+
+ @Override
+ public URL getTestUrl() {
+ return buildUrl(contextPath,
"faces/components/commandButton/simple.xhtml");
+ }
+
+ @Override
+ @AfterMethod
+ public void invalidateSession() {
+ super.invalidateSession();
+ }
+
+ @Test(dataProvider = "templates", groups = "client-side-perf")
+ public void testSimpleClick(String templates) {
+ selenium.typeKeys(input, "RichFaces 4");
+ selenium.click(button);
+
+ waitGui.until(textEquals.locator(output1).text("RichFaces 4"));
+
+ String output = selenium.getText(output1);
+ assertEquals(output, "RichFaces 4", "output1 when 'RichFaces
4' in input");
+
+ output = selenium.getText(output2);
+ assertEquals(output, "RichFa", "output2 when 'RichFaces 4'
in input");
+
+ output = selenium.getText(output3);
+ assertEquals(output, "RICHFACES 4", "output3 when 'RichFaces
4' in input");
+ }
+
+ @Test(dataProvider = "templates")
+ public void testSimpleClickUnicode(String templates) {
+ selenium.typeKeys(input, "ľščťžýáíéňô");
+ selenium.click(button);
+
+ waitGui.until(textEquals.locator(output1).text("ľščťžýáíéňô"));
+
+ String output = selenium.getText(output1);
+ assertEquals(output, "ľščťžýáíéňô", "output1 when
'ľščťžýáíéňô' in input");
+
+ output = selenium.getText(output2);
+ assertEquals(output, "ľščťžý", "output2 when 'ľščťžýáíéňô'
in input");
+
+ output = selenium.getText(output3);
+ assertEquals(output, "ĽŠČŤŽÝÁÍÉŇÔ", "output3 when
'ľščťžýáíéňô' in input");
+ }
+
+ @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");
+
+ selenium.click(doubleStringAction);
+ selenium.waitForPageToLoad(TIMEOUT);
+ selenium.typeKeys(input, "RichFaces 4");
+ selenium.click(button);
+ waitGui.until(textEquals.locator(output1).text("RichFaces 4"));
+ String output = selenium.getText(output2);
+ assertEquals(output, "RichFaces 4RichFaces 4",
+ "output2 when 'RichFaces 4' in input and doubleStringAction
selected");
+
+ selenium.click(first6CharsAction);
+ selenium.waitForPageToLoad(TIMEOUT);
+ selenium.typeKeys(input, "RichFaces 4ň");
+ selenium.click(button);
+ waitGui.until(textEquals.locator(output1).text("RichFaces 4ň"));
+ output = selenium.getText(output2);
+ assertEquals(output, "RichFa", "output2 when 'RichFaces
4ň' in input and first6CharsAction selected");
+
+ selenium.click(toUpperCaseAction);
+ selenium.waitForPageToLoad(TIMEOUT);
+ selenium.typeKeys(input, "RichFaces 4ě");
+ selenium.click(button);
+ waitGui.until(textEquals.locator(output1).text("RichFaces 4ě"));
+ output = selenium.getText(output2);
+ assertEquals(output, "RICHFACES 4Ě", "output2 when 'RichFaces
4ě' in input and toUpperCaseAction selected");
+ }
+
+ @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]");
+
+ selenium.click(doubleStringActionListener);
+ selenium.waitForPageToLoad(TIMEOUT);
+ selenium.typeKeys(input, "RichFaces 4");
+ selenium.click(button);
+ waitGui.until(textEquals.locator(output1).text("RichFaces 4"));
+ String output = selenium.getText(output3);
+ assertEquals(output, "RichFaces 4RichFaces 4",
+ "output2 when 'RichFaces 4' in input and
doubleStringActionListener selected");
+
+ selenium.click(first6CharsActionListener);
+ selenium.waitForPageToLoad(TIMEOUT);
+ selenium.typeKeys(input, "RichFaces 4ň");
+ selenium.click(button);
+ waitGui.until(textEquals.locator(output1).text("RichFaces 4ň"));
+ output = selenium.getText(output3);
+ assertEquals(output, "RichFa", "output2 when 'RichFaces
4ň' in input and first6CharsActionListener selected");
+
+ selenium.click(toUpperCaseActionListener);
+ selenium.waitForPageToLoad(TIMEOUT);
+ selenium.typeKeys(input, "RichFaces 4ě");
+ selenium.click(button);
+ waitGui.until(textEquals.locator(output1).text("RichFaces 4ě"));
+ output = selenium.getText(output3);
+ assertEquals(output, "RICHFACES 4Ě",
+ "output2 when 'RichFaces 4ě' in input and
toUpperCaseActionListener selected");
+ }
+
+ @Test(dataProvider = "templates")
+ public void testDisabled(String templates) {
+ JQueryLocator disabledChecbox =
jq("#form\\:attributes\\:disabledInput");
+ AttributeLocator disabledAttribute = button.getAttribute(new
Attribute("disabled"));
+
+ selenium.click(disabledChecbox);
+ selenium.waitForPageToLoad(TIMEOUT);
+
+ String isDisabled = selenium.getAttribute(disabledAttribute);
+ assertEquals(isDisabled.toLowerCase(), "disabled", "The value of
attribute disabled");
+ }
+
+ @Test(dataProvider = "templates")
+ public void testOnclick(String templates) {
+ JQueryLocator onclickInput = jq("#form\\:attributes\\:onclickInput");
+ final AttributeLocator onclickAttribute = button.getAttribute(new
Attribute("onclick"));
+ final String value = "alert('onclick')";
+
+ selenium.type(onclickInput, value);
+ selenium.fireEvent(onclickInput, Event.BLUR);
+
+ selenium.waitForPageToLoad(TIMEOUT);
+ assertEquals(selenium.getAttribute(onclickAttribute), value, "onclick
attribute did not change correctly");
+ }
+
+ @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=]");
+
+ final AttributeLocator classAttribute = button.getAttribute(new
Attribute("class"));
+
+ selenium.click(blue);
+ selenium.waitForPageToLoad(TIMEOUT);
+ assertTrue(selenium.belongsClass(button, "blue"), "Button's
class was not changed to 'blue'");
+
+ selenium.click(red);
+ selenium.waitForPageToLoad(TIMEOUT);
+ assertTrue(selenium.belongsClass(button, "red"), "Button's
class was not changed to 'red'");
+
+ selenium.click(wide);
+ selenium.waitForPageToLoad(TIMEOUT);
+ assertTrue(selenium.belongsClass(button, "wide"), "Button's
class was not changed to 'wide'");
+
+ selenium.click(big);
+ selenium.waitForPageToLoad(TIMEOUT);
+ assertTrue(selenium.belongsClass(button, "big"), "Button's
class was not changed to 'big'");
+
+ selenium.click(none);
+ selenium.waitForPageToLoad(TIMEOUT);
+ assertFalse(selenium.isAttributePresent(classAttribute), "Button's class
was not removed.");
+ }
+
+ @Test(dataProvider = "templates")
+ public void testStyle(String templates) {
+ JQueryLocator styleInput = jq("#form\\:attributes\\:styleInput");
+ final AttributeLocator attribute = button.getAttribute(new
Attribute("style"));
+ final String value = "font-size: 20px;";
+
+ selenium.type(styleInput, value);
+ selenium.fireEvent(styleInput, Event.BLUR);
+
+ selenium.waitForPageToLoad(TIMEOUT);
+ assertEquals(selenium.getAttribute(attribute), value, "Style of the button
did not change");
+ }
+
+ @Test(dataProvider = "templates")
+ public void testValue(String templates) {
+ JQueryLocator valueInput = jq("#form\\:attributes\\:valueInput");
+ final AttributeLocator attribute = button.getAttribute(new
Attribute("value"));
+ final String value = "new label";
+
+ selenium.type(valueInput, value);
+ selenium.fireEvent(valueInput, Event.BLUR);
+
+ selenium.waitForPageToLoad(TIMEOUT);
+ 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");
+ }
+
+}