Author: lfryc(a)redhat.com
Date: 2009-09-01 09:23:56 -0400 (Tue, 01 Sep 2009)
New Revision: 15418
Modified:
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/java/org/jboss/richfaces/integrationTest/actionParameter/ActionParameterTestCase.java
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/resources/org/jboss/richfaces/integrationTest/actionParameter/locators.properties
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/resources/org/jboss/richfaces/integrationTest/actionParameter/messages.properties
Log:
- ActionParameterTestCase - reformatted to follow conventions
Modified:
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/java/org/jboss/richfaces/integrationTest/actionParameter/ActionParameterTestCase.java
===================================================================
---
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/java/org/jboss/richfaces/integrationTest/actionParameter/ActionParameterTestCase.java 2009-09-01
13:19:58 UTC (rev 15417)
+++
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/java/org/jboss/richfaces/integrationTest/actionParameter/ActionParameterTestCase.java 2009-09-01
13:23:56 UTC (rev 15418)
@@ -1,12 +1,32 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces
+ *
+ * Copyright (C) 2009 Red Hat, Inc.
+ *
+ * This code is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This code 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 test suite; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
package org.jboss.richfaces.integrationTest.actionParameter;
-import java.util.HashMap;
-import java.util.Map;
-
+import org.apache.commons.lang.StringUtils;
import org.jboss.richfaces.integrationTest.AbstractSeleniumRichfacesTestCase;
import org.jboss.test.selenium.waiting.Condition;
import org.jboss.test.selenium.waiting.Wait;
-import org.testng.Assert;
+import static org.testng.Assert.*;
+
+import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
/**
@@ -15,94 +35,107 @@
*/
public class ActionParameterTestCase extends AbstractSeleniumRichfacesTestCase {
+ private final String LOC_OUTPUT_SELECTED_NAME_PREFORMATTED =
getLoc("OUTPUT_SELECTED_NAME_PREFORMATTED");
+ private final String LOC_BUTTON_SELECTED_NAME_PREFORMATTED =
getLoc("BUTTON_SELECTED_NAME_PREFORMATTED");
+ private final String LOC_LABEL_CHANGE_SKIN = getLoc("LABEL_CHANGE_SKIN");
+ private final String LOC_ANCHOR_SELECT_SKIN_RELATIVE =
getLoc("ANCHOR_SELECT_SKIN_RELATIVE");
+ private final String LOC_BUTTON_SCREEN_SIZE = getLoc("BUTTON_SCREEN_SIZE");
+ private final String LOC_OUTPUT_SCREEN_WIDTH =
formatLoc("OUTPUT_SCREEN_WIDTH", LOC_BUTTON_SCREEN_SIZE);
+ private final String LOC_OUTPUT_SCREEN_HEIGHT =
formatLoc("OUTPUT_SCREEN_HEIGHT", LOC_BUTTON_SCREEN_SIZE);
+
+ private final String MSG_LABEL_SELECTED_NAME = getMsg("LABEL_SELECTED_NAME");
+ private final String MSG_PATTERN_SELECTED_NAME =
getMsg("PATTERN_SELECTED_NAME");
+ private final String[] MSG_INPUT_GUYS_LIST =
StringUtils.split(getMsg("INPUT_GUYS_LIST"), ',');
+ private final String[] MSG_RELATION_SKINS_COLORS =
StringUtils.split(getMsg("RELATION_SKINS_COLORS"), '#');
+
/**
- * Opens specified page
+ * Gets initial selected name (check that it is only a label) and select
+ * each guy by pressing the button and waiting for output changes
*/
- private void openPage() {
- selenium.open(contextPath
- + "/richfaces/actionparam.jsf?c=actionparam&tab=usage");
- }
-
@Test
- public void selectingNames() {
- openPage();
+ public void testSelectingNames() {
+ final String locSelectedName = format(LOC_OUTPUT_SELECTED_NAME_PREFORMATTED,
MSG_LABEL_SELECTED_NAME);
- String prefix = getMess("selected-name--prefix");
- final String selectedName = formatLoc("selected-name--text", prefix);
+ scrollIntoView(locSelectedName, true);
- Assert.assertEquals(prefix, selenium.getText(selectedName));
+ // get initial selected name (should be only label)
+ String selectedName = selenium.getText(locSelectedName);
- String[] guys = new String[] { getMess("first-guy"),
- getMess("second-guy") };
+ assertEquals(selectedName, MSG_LABEL_SELECTED_NAME, format(
+ "Initial selected name '{0}' doesn't match expected
'{1}'", selectedName, MSG_LABEL_SELECTED_NAME));
- for (String guy : guys) {
- String button = formatLoc("selected-name--button", guy);
- final String expect = formatMess("selected-name--pattern", prefix,
- guy);
+ // for each guy press button and wait for output changes
+ for (String msgOutputGuy : MSG_INPUT_GUYS_LIST) {
+ final String locButton = format(LOC_BUTTON_SELECTED_NAME_PREFORMATTED, msgOutputGuy);
+ final String expected = format(MSG_PATTERN_SELECTED_NAME, MSG_LABEL_SELECTED_NAME,
msgOutputGuy);
- selenium.click(button);
+ scrollIntoView(locButton, true);
- Wait.until(new Condition() {
+ selenium.click(locButton);
+
+ Wait.failWith(format("Selected name never changed to '{0}'",
expected)).until(new Condition() {
public boolean isTrue() {
- return expect.equals(selenium.getText(selectedName));
+ return expected.equals(selenium.getText(locSelectedName));
}
});
}
}
+ /**
+ * Switching between skins and waiting for actual skin changes (detected by
+ * label's background color changes).
+ */
@Test
- @SuppressWarnings("serial")
- public void selectingSkin() {
- openPage();
+ public void testSelectingSkin() {
+ for (String relation : MSG_RELATION_SKINS_COLORS) {
+ final String[] msgSkinColor = StringUtils.split(relation, '|');
+ final String msgInputSkin = msgSkinColor[0];
+ final String msgOutputColor = msgSkinColor[1];
+ final String locAnchorSelectSkin = format(LOC_ANCHOR_SELECT_SKIN_RELATIVE,
LOC_LABEL_CHANGE_SKIN, msgInputSkin);
+
+ scrollIntoView(locAnchorSelectSkin, false);
+
+ selenium.click(locAnchorSelectSkin);
- final String changeSkinLabel = getLoc("change-skin--label");
+ Wait.failWith(format("Color never changed to '{0}'",
msgOutputColor)).until(new Condition() {
+ public boolean isTrue() {
+ String actualColor = getStyle(LOC_LABEL_CHANGE_SKIN, "background-color");
- Map<String, String> skins = new HashMap<String, String>() {
- {
- put(getMess("skin-1-name"), getMess("skin-1-color"));
- put(getMess("skin-2-name"), getMess("skin-2-color"));
- }
- };
-
- for (String skin : skins.keySet()) {
- final String expected = skins.get(skin);
-
- String skinAnchor = formatLoc("change-skin--link-relative",
- changeSkinLabel, skin);
-
- selenium.click(skinAnchor);
-
- Wait.until(new Condition() {
- public boolean isTrue() {
- String actual = getStyle(changeSkinLabel,
- "background-color");
- return expected.equals(actual);
+ return msgOutputColor.equals(actualColor);
}
});
}
}
+ /**
+ * Gets a expected width and height of the screen (by javascript evaluation)
+ * and try to evaluate it by click on the button. Wait for output values
+ * matches expected.
+ */
@Test
- public void showScreenSize() {
- openPage();
-
- String screenSizeButton = getLoc("screen-size--button");
-
- final String widthText = formatLoc("screen-size--width--text-relative",
- screenSizeButton);
- final String heightText = formatLoc(
- "screen-size--height--text-relative", screenSizeButton);
-
+ public void testShowScreenSize() {
final String expectedWidth = selenium.getEval("screen.width");
final String expectedHeight = selenium.getEval("screen.height");
+
+ scrollIntoView(LOC_BUTTON_SCREEN_SIZE, true);
- selenium.click(screenSizeButton);
+ selenium.click(LOC_BUTTON_SCREEN_SIZE);
+
+ Wait.failWith(format("Screen sizes never match expected value {0}x{1}",
expectedWidth, expectedHeight)).until(
+ new Condition() {
+ public boolean isTrue() {
+ return expectedWidth.equals(selenium.getText(LOC_OUTPUT_SCREEN_WIDTH))
+ && expectedHeight.equals(selenium.getText(LOC_OUTPUT_SCREEN_HEIGHT));
+ }
+ });
+ }
- Wait.until(new Condition() {
- public boolean isTrue() {
- return expectedWidth.equals(selenium.getText(widthText))
- && expectedHeight.equals(selenium.getText(heightText));
- }
- });
+ /**
+ * Loads a specific component's page
+ */
+ @SuppressWarnings("unused")
+ @BeforeMethod
+ private void loadPage() {
+ openComponent("Action Parameter");
}
}
Modified:
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/resources/org/jboss/richfaces/integrationTest/actionParameter/locators.properties
===================================================================
---
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/resources/org/jboss/richfaces/integrationTest/actionParameter/locators.properties 2009-09-01
13:19:58 UTC (rev 15417)
+++
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/resources/org/jboss/richfaces/integrationTest/actionParameter/locators.properties 2009-09-01
13:23:56 UTC (rev 15418)
@@ -1,7 +1,7 @@
-selected-name--text=//text()[starts-with(.,'{0}')]/..
-selected-name--button=//input[@type\='button' and @value\='Set Name to
{0}']
-change-skin--label=//div[text()\='Change Demo Appplication Skin To\: ']
-change-skin--link-relative={0}/../div[2]/a[text()\='{1}']
-screen-size--button=//input[@type\='button' and @value\='Show Screen
Size']
-screen-size--width--text-relative={0}/../div[1]//tr[1]/td[2]
-screen-size--height--text-relative={0}/../div[1]//tr[2]/td[2]
+OUTPUT_SELECTED_NAME_PREFORMATTED=//text()[starts-with(.,'{0}')]/..
+BUTTON_SELECTED_NAME_PREFORMATTED=//input[@type\='button' and @value\='Set
Name to {0}']
+LABEL_CHANGE_SKIN=//div[text()\='Change Demo Appplication Skin To\: ']
+ANCHOR_SELECT_SKIN_RELATIVE={0}/../div[2]/a[text()\='{1}']
+BUTTON_SCREEN_SIZE=//input[@type\='button' and @value\='Show Screen
Size']
+OUTPUT_SCREEN_WIDTH={0}/../div[1]//tr[1]/td[2]
+OUTPUT_SCREEN_HEIGHT={0}/../div[1]//tr[2]/td[2]
Modified:
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/resources/org/jboss/richfaces/integrationTest/actionParameter/messages.properties
===================================================================
---
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/resources/org/jboss/richfaces/integrationTest/actionParameter/messages.properties 2009-09-01
13:19:58 UTC (rev 15417)
+++
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/resources/org/jboss/richfaces/integrationTest/actionParameter/messages.properties 2009-09-01
13:23:56 UTC (rev 15418)
@@ -1,8 +1,4 @@
-selected-name--prefix=Selected Name\:
-selected-name--pattern={0}{1}
-first-guy=Alex
-second-guy=John
-skin-1-name=DeepMarine
-skin-1-color=rgb(0, 136, 148)
-skin-2-name=BlueSky
-skin-2-color=rgb(190, 214, 248)
\ No newline at end of file
+LABEL_SELECTED_NAME=Selected Name\:
+PATTERN_SELECTED_NAME={0}{1}
+INPUT_GUYS_LIST=Alex,John
+RELATION_SKINS_COLORS=DeepMarine|rgb(0, 136, 148)\#BlueSky|rgb(190, 214, 248)