Author: dsvyatobatsko
Date: 2008-08-14 11:58:05 -0400 (Thu, 14 Aug 2008)
New Revision: 10101
Modified:
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/testng/PickListTest.java
Log:
PickListTest fixed and extended
Modified:
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/testng/PickListTest.java
===================================================================
---
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/testng/PickListTest.java 2008-08-14
15:26:02 UTC (rev 10100)
+++
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/testng/PickListTest.java 2008-08-14
15:58:05 UTC (rev 10101)
@@ -7,17 +7,25 @@
public class PickListTest extends SeleniumTestBase {
+ private static final String PICK_LIST = "pickList";
+ private static final String COPY_BTN = "copy";
+ private static final String COPY_ALL_BTN = "copyAll";
+ private static final String REMOVE_BTN = "remove";
+ private static final String REMOVE_ALL_BTN = "removeAll";
+ private static final String SRC_ELEM_PREFIX = ":source::";
+
@Test
public void testPickListComponent(Template template) {
renderPage(template);
String parentId = getParentId() + "_form:";
- String pickListId = "pickList";
- String copyElemId = parentId + pickListId + "discopy";
- String copyAllElemId = parentId + pickListId + "copyAll";
- String removeElemId = parentId + pickListId + "disremove";
- String removeAllElemId = parentId + pickListId + "removeAll";
+ String pickListId = parentId + PICK_LIST;
+ String copyElemId = pickListId + COPY_BTN;
+ String copyAllElemId = pickListId + COPY_ALL_BTN;
+ String removeElemId = pickListId + REMOVE_BTN;
+ String removeAllElemId = pickListId + REMOVE_ALL_BTN;
+
writeStatus("Check move controls customized labels");
AssertTextEquals(copyElemId, "MOVE");
@@ -25,8 +33,8 @@
AssertTextEquals(removeElemId, "TAKE AWAY");
AssertTextEquals(removeAllElemId, "TAKE ALL AWAY");
- String destListId = parentId + pickListId + "tlTbody";
- String srcListId = parentId + pickListId + "tbody";
+ String destListId = parentId + PICK_LIST + "tlTbody";
+ String srcListId = parentId + PICK_LIST + "tbody";
writeStatus("Check initial disposition");
@@ -38,31 +46,67 @@
Assert.assertEquals(selenium.getText("xpath=//tbody[@id='" +
destListId + "']/tr[1]"), "ZHURIK");
Assert.assertEquals(selenium.getText("xpath=//tbody[@id='" +
destListId + "']/tr[2]"), "MELESHKO");
- writeStatus("Try to select first item and check state thereafter");
+ writeStatus("Check buttons state");
- selenium.doubleClick("xpath=//tbody[@id='" + srcListId +
"']/tr/td");
+ assertButtonEnabled(COPY_ALL_BTN);
+ assertButtonDisabled(COPY_BTN);
+ assertButtonDisabled(REMOVE_BTN);
+ assertButtonEnabled(REMOVE_ALL_BTN);
+ writeStatus("Try to move the first item and check state thereafter");
+
+ String srcElemPrefix = parentId + PICK_LIST + SRC_ELEM_PREFIX;
+ fireMouseEvent(srcElemPrefix + "1", "click", 0, 0, false);
+ clickById(copyElemId);
+
Assert.assertEquals(getNumberOfChildren(srcListId), 5);
Assert.assertEquals(getNumberOfChildren(destListId), 3);
Assert.assertEquals(selenium.getText("xpath=//tbody[@id='" +
destListId + "']/tr[3]"), "LEONTIEV");
+ writeStatus("Test 'MOVE ALL' button");
+
+ clickById(copyAllElemId);
+
+ Assert.assertEquals(getNumberOfChildren(srcListId), 0);
+ Assert.assertEquals(getNumberOfChildren(destListId), 8);
+
+ assertButtonDisabled(COPY_ALL_BTN);
+ assertButtonDisabled(COPY_BTN);
+ assertButtonDisabled(REMOVE_BTN);
+ assertButtonEnabled(REMOVE_ALL_BTN);
+
+ writeStatus("Test 'REMOVE ALL' button");
+
+ clickById(removeAllElemId);
+
+ Assert.assertEquals(getNumberOfChildren(srcListId), 8);
+ Assert.assertEquals(getNumberOfChildren(destListId), 0);
+
+ assertButtonEnabled(COPY_ALL_BTN);
+ assertButtonDisabled(COPY_BTN);
+ assertButtonDisabled(REMOVE_BTN);
+ assertButtonDisabled(REMOVE_ALL_BTN);
}
+ private void assertButtonEnabled(String btnId) {
+ String id = getParentId() + "_form:" + PICK_LIST;
+ Assert.assertTrue(isVisibleById(id + btnId));
+ Assert.assertFalse(isVisibleById(id + "dis" + btnId));
+ }
+
+ private void assertButtonDisabled(String btnId) {
+ String id = getParentId() + "_form:" + PICK_LIST;
+ Assert.assertFalse(isVisibleById(id + btnId));
+ Assert.assertTrue(isVisibleById(id + "dis" + btnId));
+ }
+
/**
* Returns number of children for DOM element with given id.
* @param elemId DOM element id
* @return number of children
*/
private int getNumberOfChildren(String elemId) {
- int retVal = -1;
- try {
- retVal =
Integer.parseInt(runScript("dom=selenium.browserbot.getCurrentWindow().$('"
+ elemId
- + "').childElements().size()"));
- } catch (Exception e) {
- Assert.fail(e.getMessage());
- }
-
- return retVal;
+ return selenium.getXpathCount("//*[@id='" + elemId +
"']/*").intValue();
}
public String getTestUrl() {
Show replies by date