Author: lfryc(a)redhat.com
Date: 2009-09-01 15:13:48 -0400 (Tue, 01 Sep 2009)
New Revision: 15425
Modified:
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/java/org/jboss/richfaces/integrationTest/ajaxForm/AjaxFormTestCase.java
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/resources/org/jboss/richfaces/integrationTest/ajaxForm/locators.properties
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/resources/org/jboss/richfaces/integrationTest/ajaxForm/messages.properties
Log:
- refactored Ajax Form test cases to follow conventions
Modified:
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/java/org/jboss/richfaces/integrationTest/ajaxForm/AjaxFormTestCase.java
===================================================================
---
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/java/org/jboss/richfaces/integrationTest/ajaxForm/AjaxFormTestCase.java 2009-09-01
15:56:05 UTC (rev 15424)
+++
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/java/org/jboss/richfaces/integrationTest/ajaxForm/AjaxFormTestCase.java 2009-09-01
19:13:48 UTC (rev 15425)
@@ -1,7 +1,28 @@
+/**
+ * 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.ajaxForm;
import org.jboss.richfaces.integrationTest.AbstractSeleniumRichfacesTestCase;
-import org.testng.Assert;
+import static org.testng.Assert.*;
+import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import com.thoughtworks.selenium.Wait;
@@ -11,37 +32,39 @@
* @version $Revision$
*/
public class AjaxFormTestCase extends AbstractSeleniumRichfacesTestCase {
- /**
- * Opens specified page
- */
- private void openPage() {
- selenium.open(contextPath + "/richfaces/form.jsf?c=form&tab=usage");
- scrollIntoView(header, true);
- }
+ private String LOC_LEGEND_HEADER = getLoc("LEGEND_HEADER");
+ private String LOC_BUTTON_AJAX = getLoc("BUTTON_AJAX");
+ private String LOC_BUTTON_NON_AJAX = getLoc("BUTTON_NON_AJAX");
+ private String LOC_OUTPUT_TEXT_RELATIVE = getLoc("OUTPUT_TEXT_RELATIVE");
+ private String LOC_OUTPUT_AJAX = format(LOC_OUTPUT_TEXT_RELATIVE, LOC_BUTTON_AJAX);
+ private String LOC_OUTPUT_NON_AJAX = format(LOC_OUTPUT_TEXT_RELATIVE,
LOC_BUTTON_NON_AJAX);
- private String header = "//legend[text()='AjaxForm Demo']";
- private String ajaxButton = getLoc("ajax-form--ajax-button");
- private String nonAjaxButton = getLoc("ajax-form--non-ajax-button");
- private String textRelative = "ajax-form--text-relative";
- private String ajaxText = formatLoc(textRelative, ajaxButton);
- private String nonAjaxText = formatLoc(textRelative, nonAjaxButton);
+ private final String MSG_OUTPUT_NON_AJAX = getMsg("OUTPUT_NON_AJAX");
+ private final String MSG_OUTPUT_AJAX = getMsg("OUTPUT_AJAX");
+ /**
+ * Sends non-Ajax request and check that it changes both of output fields.
+ */
@Test
public void testNonAjaxSubmit() {
- openPage();
nonAjaxSubmit();
}
+ /**
+ * Sends Ajax request and check that it changes only ajax-rendered field.
+ */
@Test
public void testAjaxSubmit() {
- openPage();
ajaxSubmit();
}
+ /**
+ * Test interleaving of non-Ajax and Ajax requested changes and checks that
+ * it is rendered in right way.
+ */
@Test
public void testInterleaving() {
- openPage();
ajaxSubmit();
nonAjaxSubmit();
ajaxSubmit();
@@ -49,28 +72,39 @@
}
public void nonAjaxSubmit() {
- String expected = getMess("ajax-form--non-ajax-result");
-
- selenium.click(nonAjaxButton);
+ selenium.click(LOC_BUTTON_NON_AJAX);
selenium.waitForPageToLoad(String.valueOf(Wait.DEFAULT_TIMEOUT));
- scrollIntoView(header, true);
- String actual = selenium.getText(ajaxText);
- Assert.assertEquals(actual, expected);
+ scrollIntoView(LOC_LEGEND_HEADER, true);
- actual = selenium.getText(nonAjaxText);
- Assert.assertEquals(actual, expected);
+ // both of outputs should be same
+ String actual = selenium.getText(LOC_OUTPUT_AJAX);
+ assertEquals(actual, MSG_OUTPUT_NON_AJAX);
+
+ actual = selenium.getText(LOC_OUTPUT_NON_AJAX);
+ assertEquals(actual, MSG_OUTPUT_NON_AJAX);
}
public void ajaxSubmit() {
- String expected = getMess("ajax-form--ajax-result");
+ String startingNonAjaxText = selenium.getText(LOC_OUTPUT_NON_AJAX);
- String startingNonAjaxText = selenium.getText(nonAjaxText);
+ // ajax-rendered output should be set right
+ selenium.click(LOC_BUTTON_AJAX);
+ waitForTextEquals(LOC_OUTPUT_AJAX, MSG_OUTPUT_AJAX);
- selenium.click(ajaxButton);
- waitForTextEquals(ajaxText, expected);
+ // non-ajax output should stay same like before the request
+ String actual = selenium.getText(LOC_OUTPUT_NON_AJAX);
+ assertEquals(actual, startingNonAjaxText);
+ }
- String actual = selenium.getText(nonAjaxText);
- Assert.assertEquals(actual, startingNonAjaxText);
+ /**
+ * Opens specific component's page
+ */
+ @SuppressWarnings("unused")
+ @BeforeMethod
+ private void loadPage() {
+ openComponent("Ajax Form");
+
+ scrollIntoView(LOC_LEGEND_HEADER, true);
}
}
Modified:
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/resources/org/jboss/richfaces/integrationTest/ajaxForm/locators.properties
===================================================================
---
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/resources/org/jboss/richfaces/integrationTest/ajaxForm/locators.properties 2009-09-01
15:56:05 UTC (rev 15424)
+++
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/resources/org/jboss/richfaces/integrationTest/ajaxForm/locators.properties 2009-09-01
19:13:48 UTC (rev 15425)
@@ -1,3 +1,4 @@
-ajax-form--ajax-button=//input[@type\='submit' and @value\="Set Local Name
to John (Ajax)"]
-ajax-form--non-ajax-button=//input[@type\='submit' and @value\="Set Both
Name to Mark (non-Ajax)"]
-ajax-form--text-relative={0}/../../../tr[2]/*/*/text()
\ No newline at end of file
+LEGEND_HEADER=//legend[text()\='AjaxForm Demo']
+BUTTON_AJAX=//input[@type\='submit' and @value\="Set Local Name to John
(Ajax)"]
+BUTTON_NON_AJAX=//input[@type\='submit' and @value\="Set Both Name to Mark
(non-Ajax)"]
+OUTPUT_TEXT_RELATIVE={0}/../../../tr[2]/*/*/text()
\ No newline at end of file
Modified:
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/resources/org/jboss/richfaces/integrationTest/ajaxForm/messages.properties
===================================================================
---
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/resources/org/jboss/richfaces/integrationTest/ajaxForm/messages.properties 2009-09-01
15:56:05 UTC (rev 15424)
+++
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/resources/org/jboss/richfaces/integrationTest/ajaxForm/messages.properties 2009-09-01
19:13:48 UTC (rev 15425)
@@ -1,2 +1,2 @@
-ajax-form--ajax-result=Name\:John
-ajax-form--non-ajax-result=Name\:Mark
\ No newline at end of file
+OUTPUT_AJAX=Name\:John
+OUTPUT_NON_AJAX=Name\:Mark
\ No newline at end of file