Author: lfryc(a)redhat.com
Date: 2009-09-02 10:24:38 -0400 (Wed, 02 Sep 2009)
New Revision: 15439
Modified:
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/java/org/jboss/richfaces/integrationTest/keepAlive/KeepAliveTestCase.java
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/resources/org/jboss/richfaces/integrationTest/keepAlive/locators.properties
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/resources/org/jboss/richfaces/integrationTest/keepAlive/messages.properties
Log:
- refactored Keep Alive test cases to follow conventions
Modified:
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/java/org/jboss/richfaces/integrationTest/keepAlive/KeepAliveTestCase.java
===================================================================
---
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/java/org/jboss/richfaces/integrationTest/keepAlive/KeepAliveTestCase.java 2009-09-02
12:34:47 UTC (rev 15438)
+++
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/java/org/jboss/richfaces/integrationTest/keepAlive/KeepAliveTestCase.java 2009-09-02
14:24:38 UTC (rev 15439)
@@ -1,12 +1,33 @@
+/**
+ * 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.keepAlive;
-import junit.framework.Assert;
+import static org.testng.Assert.*;
import org.apache.commons.lang.StringUtils;
import org.jboss.richfaces.integrationTest.AbstractSeleniumRichfacesTestCase;
import org.jboss.test.selenium.dom.Event;
import org.jboss.test.selenium.waiting.Condition;
import org.jboss.test.selenium.waiting.Wait;
+import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
/**
@@ -14,90 +35,93 @@
* @version $Revision$
*/
public class KeepAliveTestCase extends AbstractSeleniumRichfacesTestCase {
+ private final String LOC_INPUT_INCORRECT1 = getLoc("INPUT_INCORRECT1");
+ private final String LOC_INPUT_INCORRECT2 = getLoc("INPUT_INCORRECT2");
+ private final String LOC_BUTTON_INCORRECT = getLoc("BUTTON_INCORRECT");
+ private final String LOC_OUTPUT_INCORRECT = getLoc("OUTPUT_INCORRECT");
+ private final String LOC_INPUT_CORRECT1 = getLoc("INPUT_CORRECT1");
+ private final String LOC_INPUT_CORRECT2 = getLoc("INPUT_CORRECT2");
+ private final String LOC_BUTTON_CORRECT = getLoc("BUTTON_CORRECT");
+ private final String LOC_OUTPUT_CORRECT = getLoc("OUTPUT_CORRECT");
+
+ private final String MSG_INPUT_FIRST_NUMBER = getMsg("INPUT_FIRST_NUMBER");
+ private final String MSG_INPUT_SECOND_NUMBER = getMsg("INPUT_SECOND_NUMBER");
+ private final String MSG_OUTPUT_RESULT_NUMBER =
getMsg("OUTPUT_RESULT_NUMBER");
+
/**
- * Opens specified page
+ * Type two summands to incorrect way form, wait for button became enabled
+ * and checks that after click will appear no result.
*/
- private void openPage() {
- selenium.open(contextPath
- + "/richfaces/keepAlive.jsf?c=keepAlive&tab=usage");
- }
-
- private String header = getLoc("keep-alive--header");
- private String inputIncorrect1 = getLoc("keep-alive--input--incorrect1");
- private String inputIncorrect2 = getLoc("keep-alive--input--incorrect2");
- private String buttonIncorrect = getLoc("keep-alive--button--incorrect");
- private String outputIncorrect = getLoc("keep-alive--output--incorrect");
- private String inputCorrect1 = getLoc("keep-alive--input--correct1");
- private String inputCorrect2 = getLoc("keep-alive--input--correct2");
- private String buttonCorrect = getLoc("keep-alive--button--correct");
- private String outputCorrect = getLoc("keep-alive--output--correct");
- private String firstNumber = getMess("keep-alive--input--first-number");
- private String secondNumber = getMess("keep-alive--input--second-number");
- private String expectedResultNumber =
getMess("keep-alive--output--expected-result-number");
-
@Test
- public void usingIncorrectWay() {
- openPage();
- scrollIntoView(header, true);
+ public void testUsingIncorrectWay() {
// fill first two summands
- selenium.type(inputIncorrect1, firstNumber);
- selenium.fireEvent(inputIncorrect1, Event.KEYUP);
- selenium.type(inputIncorrect2, secondNumber);
- selenium.fireEvent(inputIncorrect2, Event.KEYUP);
+ scrollIntoView(LOC_INPUT_INCORRECT1, true);
+
+ selenium.type(LOC_INPUT_INCORRECT1, MSG_INPUT_FIRST_NUMBER);
+ selenium.fireEvent(LOC_INPUT_INCORRECT1, Event.KEYUP);
+ selenium.type(LOC_INPUT_INCORRECT2, MSG_INPUT_SECOND_NUMBER);
+ selenium.fireEvent(LOC_INPUT_INCORRECT2, Event.KEYUP);
+
// wait for "equal sign" button became enabled (lost disabled status)
- Wait.until(new Condition() {
+ Wait.failWith("Button \"=\" never became enabled").until(new
Condition() {
public boolean isTrue() {
- boolean result = selenium.isElementPresent(format(
- "{0}/@disabled", buttonIncorrect));
- return !result;
+ return !selenium.isElementPresent(format("{0}/@disabled",
LOC_BUTTON_INCORRECT));
}
});
// try to count result
- selenium.click(buttonIncorrect);
+ selenium.click(LOC_BUTTON_INCORRECT);
// TODO: try to find exact way to catch "progress done" event
// waiting for summarization is processed
waitFor(5000);
-
+
// get a result and validate it
- String result = selenium.getText(outputIncorrect);
- Assert.assertTrue(StringUtils.isBlank(result));
+ String result = selenium.getText(LOC_OUTPUT_INCORRECT);
+ assertTrue(StringUtils.isBlank(result), "Result should be blank");
}
+ /**
+ * Type two summands into correct way form, waits for button became enabled
+ * and check that after click will appear right result.
+ */
@Test
- public void usingCorrectWay() {
- openPage();
- scrollIntoView(header, true);
-
+ public void testUsingCorrectWay() {
// fill first two summands
- selenium.type(inputCorrect1, firstNumber);
- selenium.fireEvent(inputCorrect1, Event.KEYUP);
- selenium.type(inputCorrect2, secondNumber);
- selenium.fireEvent(inputCorrect2, Event.KEYUP);
+ scrollIntoView(LOC_INPUT_CORRECT1, true);
+
+ selenium.type(LOC_INPUT_CORRECT1, MSG_INPUT_FIRST_NUMBER);
+ selenium.fireEvent(LOC_INPUT_CORRECT1, Event.KEYUP);
+ selenium.type(LOC_INPUT_CORRECT2, MSG_INPUT_SECOND_NUMBER);
+ selenium.fireEvent(LOC_INPUT_CORRECT2, Event.KEYUP);
+
// wait for "equal sign" button became enabled (lost disabled status)
- Wait.until(new Condition() {
+ Wait.failWith("Button \"=\" never became enabled").until(new
Condition() {
public boolean isTrue() {
- boolean result = selenium.isElementPresent(format(
- "{0}/@disabled", buttonCorrect));
- return !result;
-
+ return !selenium.isElementPresent(format("{0}/@disabled",
LOC_BUTTON_CORRECT));
}
});
// try to count result
- selenium.click(buttonCorrect);
+ selenium.click(LOC_BUTTON_CORRECT);
- // waiting for result became right - If this not happen, waiting timeouts and test
fail
- Wait.until(new Condition() {
+ // waiting for result became right - If this not happen, waiting
+ // timeouts and test fail
+ Wait.failWith("Result never became correct").until(new Condition() {
public boolean isTrue() {
- String result = selenium.getText(outputCorrect);
- return expectedResultNumber.equals(result);
+ String result = selenium.getText(LOC_OUTPUT_CORRECT);
+ return MSG_OUTPUT_RESULT_NUMBER.equals(result);
}
});
}
+
+ @SuppressWarnings("unused")
+ @BeforeMethod
+ private void loadPage() {
+ openComponent("Keep Alive");
+ }
}
Modified:
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/resources/org/jboss/richfaces/integrationTest/keepAlive/locators.properties
===================================================================
---
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/resources/org/jboss/richfaces/integrationTest/keepAlive/locators.properties 2009-09-02
12:34:47 UTC (rev 15438)
+++
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/resources/org/jboss/richfaces/integrationTest/keepAlive/locators.properties 2009-09-02
14:24:38 UTC (rev 15439)
@@ -1,9 +1,8 @@
-keep-alive--header=//legend[text()\='KeepAlive demo']
-keep-alive--input--incorrect1=//fieldset/div/table/tbody/tr[2]/td[1]/form/input[@type\='text'][1]
-keep-alive--input--incorrect2=//fieldset/div/table/tbody/tr[2]/td[1]/form/input[@type\='text'][2]
-keep-alive--button--incorrect=//fieldset/div/table/tbody/tr[2]/td[1]/form/*[@type\='button']
-keep-alive--output--incorrect=//fieldset/div/table/tbody/tr[2]/td[1]/form/*[contains(@id,
'sum')]
-keep-alive--input--correct1=//fieldset/div/table/tbody/tr[2]/td[2]/form/input[@type\='text'][1]
-keep-alive--input--correct2=//fieldset/div/table/tbody/tr[2]/td[2]/form/input[@type\='text'][2]
-keep-alive--button--correct=//fieldset/div/table/tbody/tr[2]/td[2]/form/*[@type\='button']
-keep-alive--output--correct=//fieldset/div/table/tbody/tr[2]/td[2]/form/*[contains(@id,
'sum')]
+INPUT_INCORRECT1=//fieldset/div/table/tbody/tr[2]/td[1]/form/input[@type\='text'][1]
+INPUT_INCORRECT2=//fieldset/div/table/tbody/tr[2]/td[1]/form/input[@type\='text'][2]
+BUTTON_INCORRECT=//fieldset/div/table/tbody/tr[2]/td[1]/form/*[@type\='button']
+OUTPUT_INCORRECT=//fieldset/div/table/tbody/tr[2]/td[1]/form/*[contains(@id,
'sum')]
+INPUT_CORRECT1=//fieldset/div/table/tbody/tr[2]/td[2]/form/input[@type\='text'][1]
+INPUT_CORRECT2=//fieldset/div/table/tbody/tr[2]/td[2]/form/input[@type\='text'][2]
+BUTTON_CORRECT=//fieldset/div/table/tbody/tr[2]/td[2]/form/*[@type\='button']
+OUTPUT_CORRECT=//fieldset/div/table/tbody/tr[2]/td[2]/form/*[contains(@id,
'sum')]
Modified:
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/resources/org/jboss/richfaces/integrationTest/keepAlive/messages.properties
===================================================================
---
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/resources/org/jboss/richfaces/integrationTest/keepAlive/messages.properties 2009-09-02
12:34:47 UTC (rev 15438)
+++
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/resources/org/jboss/richfaces/integrationTest/keepAlive/messages.properties 2009-09-02
14:24:38 UTC (rev 15439)
@@ -1,3 +1,3 @@
-keep-alive--input--first-number=2
-keep-alive--input--second-number=3
-keep-alive--output--expected-result-number=5
+INPUT_FIRST_NUMBER=2
+INPUT_SECOND_NUMBER=3
+OUTPUT_RESULT_NUMBER=5