JBoss Rich Faces SVN: r22529 - modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTabPanel.
by richfaces-svn-commits@lists.jboss.org
Author: jjamrich
Date: 2011-06-13 03:14:29 -0400 (Mon, 13 Jun 2011)
New Revision: 22529
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTabPanel/TestRichTabPanelAddPanel1.java
Log:
Update selenium tests for dynamic tab creating.
Now should tests fit current state: tests fails only on not working
features.
Modified: modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTabPanel/TestRichTabPanelAddPanel1.java
===================================================================
--- modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTabPanel/TestRichTabPanelAddPanel1.java 2011-06-06 22:02:56 UTC (rev 22528)
+++ modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTabPanel/TestRichTabPanelAddPanel1.java 2011-06-13 07:14:29 UTC (rev 22529)
@@ -24,8 +24,6 @@
import static org.jboss.test.selenium.guard.request.RequestTypeGuardFactory.guardNoRequest;
import static org.jboss.test.selenium.guard.request.RequestTypeGuardFactory.guardXhr;
import static org.jboss.test.selenium.utils.URLUtils.buildUrl;
-import static org.testng.Assert.assertFalse;
-import static org.testng.Assert.assertTrue;
import java.net.URL;
@@ -40,79 +38,83 @@
* @version $Revision$
*/
public class TestRichTabPanelAddPanel1 extends AbstractMetamerTest {
-
- private JQueryLocator panel = pjq("div[id$=tabPanel]");
- private JQueryLocator[] items = {pjq("div[id$=tab1]"), pjq("div[id$=tab2]"), pjq("div[id$=tab3]"), pjq("div[id$=tab4]"),
- pjq("div[id$=tab5]")};
- private JQueryLocator[] itemContents = {pjq("div[id$=tab1] > div.rf-tab-cnt"), pjq("div[id$=tab2] > div.rf-tab-cnt"),
- pjq("div[id$=tab3] > div.rf-tab-cnt"), pjq("div[id$=tab4] > div.rf-tab-cnt"), pjq("div[id$=tab5] > div.rf-tab-cnt"),
- pjq("div[id$=tab6] > div.rf-tab-cnt"), pjq("div[id$=tab7] > div.rf-tab-cnt"), pjq("div[id$=tab8] > div.rf-tab-cnt")};
- private JQueryLocator[] activeHeaders = {pjq("td[id$=tab1:header:active]"), pjq("td[id$=tab2:header:active]"),
- pjq("td[id$=tab3:header:active]"), pjq("td[id$=tab4:header:active]"), pjq("td[id$=tab5:header:active]")};
- private JQueryLocator[] inactiveHeaders = {pjq("td[id$=tab1:header:inactive]"), pjq("td[id$=tab2:header:inactive]"),
- pjq("td[id$=tab3:header:inactive]"), pjq("td[id$=tab4:header:inactive]"), pjq("td[id$=tab5:header:inactive]"),
- pjq("td[id$=tab6:header:inactive]"), pjq("td[id$=tab7:header:inactive]"), pjq("td[id$=tab8:header:inactive]") };
- private JQueryLocator[] disabledHeaders = {pjq("td[id$=tab1:header:disabled]"), pjq("td[id$=tab2:header:disabled]"),
- pjq("td[id$=tab3:header:disabled]"), pjq("td[id$=tab4:header:disabled]"), pjq("td[id$=tab5:header:disabled]")};
+ private static final String SWITCH_TYPE_CLIENT = "client";
+ private static final String SWITCH_TYPE_SERVER = "server";
+ private static final String SWITCH_TYPE_AJAX = "ajax";
+
+ private static final int MAX_NEW_TAB_COUNT = 3;
+ private static final int STATIC_TAB_COUNT = 5;
+
+ private JQueryLocator itemContentsFormat = pjq("div[id$=tab{0}:content]");
+
+ private JQueryLocator inactiveHeadersFormat = pjq("td[id$=tab{0}:header:inactive]");
+
private JQueryLocator hCreateTabBtn = pjq("input[id$=hCreateTabButton]");
- private JQueryLocator aa4jCreateTabBtn = pjq("input[id$=a4jCreateTabButton]");
+ private JQueryLocator a4jCreateTabBtn = pjq("input[id$=a4jCreateTabButton]");
private JQueryLocator tabsCount = pjq("table.rf-tab-hdr-tabs td.rf-tab-hdr-inact");
-
+
+ private JQueryLocator switchTypeFormat = pjq("input[name$=switchTypeInput][value={0}]");
+
@Override
public URL getTestUrl() {
- return buildUrl(contextPath, "faces/components/richTabPanel/addTab.xhtml");
+ return buildUrl(contextPath, "faces/components/richTabPanel/addTab2.xhtml");
}
-
- @Test
- public void testInit() {
- boolean displayed = selenium.isDisplayed(panel);
- assertTrue(displayed, "Tab panel is not present on the page.");
-
- displayed = selenium.isDisplayed(activeHeaders[0]);
- assertTrue(displayed, "Header of tab1 should be active.");
- for (int i = 1; i < 5; i++) {
- displayed = selenium.isDisplayed(activeHeaders[i]);
- assertFalse(displayed, "Header of tab " + (i + 1) + " should not be active.");
- }
-
- displayed = selenium.isDisplayed(inactiveHeaders[0]);
- assertFalse(displayed, "Header of tab1 should not be inactive.");
- displayed = selenium.isDisplayed(inactiveHeaders[1]);
- assertTrue(displayed, "Header of tab2 should be inactive.");
-
- displayed = selenium.isDisplayed(disabledHeaders[3]);
- assertTrue(displayed, "Header of tab4 should be disabled.");
- for (int i = 0; i < 3; i++) {
- displayed = selenium.isDisplayed(disabledHeaders[i]);
- assertFalse(displayed, "Header of tab " + (i + 1) + " should not be disabled.");
- }
-
- displayed = selenium.isDisplayed(itemContents[0]);
- assertTrue(displayed, "Content of item1 should be visible.");
-
- for (int i = 1; i < 5; i++) {
- displayed = selenium.isDisplayed(items[i]);
- assertFalse(displayed, "Tab" + (i + 1) + "'s content should not be visible.");
- }
- }
- @Test(dependsOnMethods = {"testInit"})
- public void testCreateTab() {
- selenium.click(pjq("input[name$=switchTypeInput][value=client]"));
- selenium.waitForPageToLoad();
+ private void verifyCreateTab(JQueryLocator addTabBtn) {
int baseTabsCount = selenium.getCount(tabsCount);
// add 3 new tabs
- for (int i=1; i<4; ++i){
- selenium.click(hCreateTabBtn);
- selenium.waitForPageToLoad();
+ for (int i = 1; i <= MAX_NEW_TAB_COUNT; ++i) {
+ selenium.click(addTabBtn);
waitGui.until(countEquals.count(baseTabsCount + i).locator(tabsCount));
+ }
+ }
+
+ private void verifyContentOfNewTab(JQueryLocator addTabBtn) {
+
+ verifyCreateTab(addTabBtn);
+
+ // tab switch work at least with "client" option
+ selenium.click(switchTypeFormat.format(SWITCH_TYPE_CLIENT));
+
+ System.out.println("testSwitchTypeAjax: tab count: " + selenium.getCount(tabsCount));
+
+ for (int i = STATIC_TAB_COUNT + MAX_NEW_TAB_COUNT - 1; i >= STATIC_TAB_COUNT; i--) {
+ selenium.click(inactiveHeadersFormat.format(i + 1));
+ waitGui.failWith("Tab " + (i + 1) + " doesn't display correct content.")
+ .until(textEquals.text("Content of dynamicaly created tab" + (i + 1))
+ .locator(itemContentsFormat.format(i + 1)));
}
}
+
+ /**
+ * Create new tab by clicking on h:commandButton
+ */
+ @Test
+ public void testCreateTabJSF() {
+ verifyCreateTab(hCreateTabBtn);
+ }
+
+ /**
+ * Create new tab by clicking on a4j:commandButton
+ */
+ @Test
+ public void testCreateTabAjax() {
+ verifyCreateTab(a4jCreateTabBtn);
+ }
+
+ /**
+ * Verify that all tabs displays correct content when switch tab
+ */
+ @Test
+ public void testContentOfDynamicTab() {
+ verifyContentOfNewTab(hCreateTabBtn);
+ }
+
/*
* Test plan:
* 1. click on 'create tab' btn 3 time and verify that new tabs appeared
@@ -120,32 +122,60 @@
* 3. verify a4j ajax btn to create new tabs
*/
+ @Test
public void testSwitchTypeNull() {
- for (int i = 7; i >= 5; i--) {
+
+ verifyCreateTab(hCreateTabBtn);
+
+ for (int i = STATIC_TAB_COUNT + MAX_NEW_TAB_COUNT - 1; i >= STATIC_TAB_COUNT; i--) {
final int index = i;
- guardXhr(selenium).click(inactiveHeaders[index]);
- waitGui.failWith("Tab " + (index + 1) + " is not displayed.").until(isDisplayed.locator(itemContents[index]));
+ guardXhr(selenium).click(inactiveHeadersFormat.format(index + 1));
+ waitGui.failWith("Tab " + (index + 1) + " is not displayed.")
+ .until(isDisplayed.locator(itemContentsFormat.format(index + 1)));
}
}
- @Test(dependsOnMethods = {"testCreateTab"})
+ @Test
public void testSwitchTypeAjax() {
- selenium.click(pjq("input[name$=switchTypeInput][value=ajax]"));
+
+ verifyCreateTab(hCreateTabBtn);
+
+ selenium.click(switchTypeFormat.format(SWITCH_TYPE_AJAX));
selenium.waitForPageToLoad();
testSwitchTypeNull();
}
- @Test(dependsOnMethods = {"testCreateTab"})
+ @Test
public void testSwitchTypeClient() {
- selenium.click(pjq("input[name$=switchTypeInput][value=client]"));
+
+ verifyCreateTab(hCreateTabBtn);
+
+ selenium.click(switchTypeFormat.format(SWITCH_TYPE_CLIENT));
selenium.waitForPageToLoad();
-
- for (int i = 7; i >= 5; i--) {
+
+ for (int i = STATIC_TAB_COUNT + MAX_NEW_TAB_COUNT - 1; i >= STATIC_TAB_COUNT; i--) {
final int index = i;
- guardNoRequest(selenium).click(inactiveHeaders[index]);
- waitGui.failWith("Tab " + (index + 1) + " is not displayed.").until(isDisplayed.locator(itemContents[index]));
+ guardNoRequest(selenium).click(inactiveHeadersFormat.format(index + 1));
+ waitGui.failWith("Tab " + (index + 1) + " is not displayed.")
+ .until(isDisplayed.locator(itemContentsFormat.format(index + 1)));
}
}
+
+ @Test
+ public void testSwitchTypeServer() {
+
+ verifyCreateTab(hCreateTabBtn);
+
+ selenium.click(switchTypeFormat.format(SWITCH_TYPE_SERVER));
+ selenium.waitForPageToLoad();
+
+ for (int i = STATIC_TAB_COUNT + MAX_NEW_TAB_COUNT - 1; i >= STATIC_TAB_COUNT; i--) {
+ final int index = i;
+ guardNoRequest(selenium).click(inactiveHeadersFormat.format(index + 1));
+ waitGui.failWith("Tab " + (index + 1) + " is not displayed.")
+ .until(isDisplayed.locator(itemContentsFormat.format(index + 1)));
+ }
+ }
}