Author: vrockai
Date: 2009-01-14 09:42:34 -0500 (Wed, 14 Jan 2009)
New Revision: 12500
Modified:
branches/JBoss_Portal_Branch_2_7/testsuite/ui-tests/src/org/jboss/portal/test/selenium/portal/PortletInstancesTestCase.java
Log:
portlet instances fix
Modified:
branches/JBoss_Portal_Branch_2_7/testsuite/ui-tests/src/org/jboss/portal/test/selenium/portal/PortletInstancesTestCase.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/testsuite/ui-tests/src/org/jboss/portal/test/selenium/portal/PortletInstancesTestCase.java 2009-01-14
14:14:31 UTC (rev 12499)
+++
branches/JBoss_Portal_Branch_2_7/testsuite/ui-tests/src/org/jboss/portal/test/selenium/portal/PortletInstancesTestCase.java 2009-01-14
14:42:34 UTC (rev 12500)
@@ -10,6 +10,8 @@
public class PortletInstancesTestCase extends JBossPortalSeleniumTestCase {
+ private static final String TAB_PORTLET_INSTANCES = "instancesTable2";
+ private static final String UL_PAGINATOR = "//ul[@class='pagination
property-container']";
private static final String SUBMIT_SECURITY_UPDATE =
"//input[contains(@id,'common-edit-security-form:update')]";
private static final String SUBMIT_SECURITY_CANCEL =
"//input[contains(@id,'common-edit-security-form:cancel')]";
@@ -33,6 +35,7 @@
private static final String T_LINK_DELETENAME =
"//a[contains(@id,''instance-display-form:locale-datatable:{0}:delete-link'')]";
private static final String T_LINK_MODIFYNAME =
"//a[contains(@id,''instance-display-form:locale-datatable:{0}:edit-link'')]";
private static final String LINK_COUNTPORT =
"//a[contains(@id,'instances-form:CurrentUsersPortletInstance')]";
+ private static final String NAME_COUNTPORT = "CurrentUsersPortletInstance";
private static final String SUBMIT_MODIFY_NAME =
"//input[contains(@id,'add-display-name-form:addDisplay')]";
private static final String INPUT_NAME =
"//input[contains(@id,'add-display-name-form:newName')]";
private static final String SELECT_LANGUAGE =
"//select[contains(@id,'add-display-name-form:locales')]";
@@ -41,9 +44,13 @@
private static final String LINK_PI_MAIN =
"//a[contains(@id,'instance-form1:instance-link')]";
private static final String TABLE_DISPNAMES =
"//table[contains(@id,'instance-display-form:locale-datatable')]";
private static final String LNK_SEC_BUTTON =
"//table[contains(@id,''instancesTable2'')]/tbody/tr[{0}]/td/table/tbody/tr/td/a[contains(@class,''Security'')]";
- //private static final String LNK_PREF_WELCOMEPORT =
"//a[contains(@id,'security-JSPPortletInstance')]";
-
+ private static final String LNK_PREF_BUTTON =
"//table[contains(@id,''instancesTable2'')]/tbody/tr[{0}]/td/table/tbody/tr/td/a[contains(@class,''actionPreferences'')]";
+ private static final String LNK_DEL_BUTTON =
"//table[contains(@id,''instancesTable2'')]/tbody/tr[{0}]/td/table/tbody/tr/td/a[contains(@class,''actionDeleteInstance'')]";
+ private static final String LNK_INSTANCE_BUTTON =
"//table[contains(@id,''instancesTable2'')]/tbody/tr[{0}]/td[1]/a[1]";
+ // private static final String LNK_PREF_WELCOMEPORT =
+ // "//a[contains(@id,'security-JSPPortletInstance')]";
+
@BeforeMethod(groups = { "log" })
public void loginBeforeTest() {
logoutIfPossible();
@@ -53,16 +60,16 @@
@AfterMethod(groups = { "log" })
public void logoutAfterTest() {
-
+
}
-
+
@Test(enabled = true)
public void testAddName() {
- //selenium.click(LINK_20_PAGE);
- //selenium.waitForPageToLoad(PAGE_LOAD);
- clickAndWait(LINK_COUNTPORT);
+ int r = traversePortlets(NAME_COUNTPORT,0);
+ clickAndWait(MessageFormat.format(LNK_INSTANCE_BUTTON, r));
safeSelect(SELECT_LANGUAGE, "Czech");
+
final String name = "Administracny";
selenium.type(INPUT_NAME, name);
clickAndWait(SUBMIT_MODIFY_NAME);
@@ -72,7 +79,9 @@
@Test(enabled = true)
public void testDeleteName() {
// adding the name
- selenium.click(LINK_COUNTPORT);
+ int r = traversePortlets(NAME_COUNTPORT,0);
+ clickAndWait(MessageFormat.format(LNK_INSTANCE_BUTTON, r));
+
selenium.waitForPageToLoad(PAGE_LOAD);
selenium.select(SELECT_LANGUAGE, "label=Japanese");
final String name = "Aduminu";
@@ -82,7 +91,7 @@
// deleting name
- int r = findTableRow(TABLE_DISPNAMES, name, 1);
+ r = findTableRow(TABLE_DISPNAMES, name, 1);
selenium.click(MessageFormat.format(T_LINK_DELETENAME, r - 1));
selenium.waitForPageToLoad(PAGE_LOAD);
@@ -92,11 +101,9 @@
@Test(enabled = true)
public void testModifyName() {
- // adding the name
-// selenium.click(LINK_20_PAGE);
-// selenium.waitForPageToLoad(PAGE_LOAD);
- selenium.click(LINK_COUNTPORT);
- selenium.waitForPageToLoad(PAGE_LOAD);
+ int r = traversePortlets(NAME_COUNTPORT,0);
+ clickAndWait(MessageFormat.format(LNK_INSTANCE_BUTTON, r));
+
selenium.select(SELECT_LANGUAGE, "label=Japanese");
final String name = "Adminisimo";
final String nameNew = "Adminiprisimo";
@@ -107,7 +114,7 @@
// midifying name
- int r = findTableRow(TABLE_DISPNAMES, name, 1);
+ r = findTableRow(TABLE_DISPNAMES, name, 1);
selenium.click(MessageFormat.format(T_LINK_MODIFYNAME, r - 1));
selenium.waitForPageToLoad(PAGE_LOAD);
@@ -119,17 +126,20 @@
Assert.assertTrue(findTableRow(TABLE_DISPNAMES, nameNew, 1) >= 0);
}
+
+
@Test(enabled = true)
public void testSecure() {
String instance_name = "JSPPortletInstance";
- String table = "instancesTable2";
+ String table = TAB_PORTLET_INSTANCES;
+
+ // selenium.click(LINK_20_PAGE);
+ // selenium.waitForPageToLoad(PAGE_LOAD);
+
+ //int r = findTableRow(table, instance_name, 0);
+ int r = traversePortlets(instance_name,0);
+ selenium.click(MessageFormat.format(LNK_SEC_BUTTON, r));
- //selenium.click(LINK_20_PAGE);
- //selenium.waitForPageToLoad(PAGE_LOAD);
-
- int r = findTableRow(table, instance_name, 0);
-
- selenium.click(MessageFormat.format(LNK_SEC_BUTTON, r));
selenium.waitForPageToLoad("30000");
selenium.click("//input[contains(@name,'common-edit-security-form:cars_2')]");
selenium.click("//input[contains(@name,'common-edit-security-form:cars_1')]");
@@ -145,12 +155,14 @@
Assert.assertTrue(selenium.isTextPresent("Greetings !"));
// then cancel
-
+
goToPI();
-// selenium.click(LINK_20_PAGE);
-// selenium.waitForPageToLoad(PAGE_LOAD);
+ // selenium.click(LINK_20_PAGE);
+ // selenium.waitForPageToLoad(PAGE_LOAD);
- r = findTableRow(table, instance_name, 0);
+ //r = findTableRow(table, instance_name, 0);
+ r = traversePortlets(instance_name,0);
+
selenium.click(MessageFormat.format(LNK_SEC_BUTTON, r));
selenium.waitForPageToLoad("30000");
selenium.click("//input[contains(@name,'common-edit-security-form:cars_0')]");
@@ -166,10 +178,11 @@
// then really stop the greetings portlet
goToPI();
- //selenium.setSpeed("5000");
-// selenium.click(LINK_20_PAGE);
- // selenium.waitForPageToLoad(PAGE_LOAD);
- r = findTableRow(table, instance_name, 0);
+ // selenium.setSpeed("5000");
+ // selenium.click(LINK_20_PAGE);
+ // selenium.waitForPageToLoad(PAGE_LOAD);
+ //r = findTableRow(table, instance_name, 0);
+ r = traversePortlets(instance_name,0);
selenium.click(MessageFormat.format(LNK_SEC_BUTTON, r));
selenium.waitForPageToLoad("30000");
selenium.click("//input[contains(@name,'common-edit-security-form:cars_0')]");
@@ -188,35 +201,48 @@
@Test(enabled = true)
public void testDeleteInstance() {
// cancel first
- Assert.assertTrue(selenium.isElementPresent(LINK_DEL_EXCEPTPORT), "Exception
portlet not found.");
- selenium.click(LINK_DEL_EXCEPTPORT);
- selenium.waitForPageToLoad(PAGE_LOAD);
+ String instance_name = "WeatherPortletInstance";
+ //selenium.setSpeed("5000");
+ int r = traversePortlets(instance_name,1);
+
+ Assert.assertTrue(selenium.isElementPresent(MessageFormat.format(LNK_INSTANCE_BUTTON,
r)), instance_name+" portlet not found.");
+ clickAndWait(MessageFormat.format(LNK_DEL_BUTTON, r));
+
Assert.assertTrue(selenium.isTextPresent("WARNING!"));
Assert.assertTrue(selenium.isTextPresent("Are you sure you want to delete this
portlet instance ?"));
selenium.click(SUBMIT_PI_DELETE_CANC);
selenium.waitForPageToLoad(PAGE_LOAD);
+
// delete
- goToPI();
- Assert.assertTrue(selenium.isElementPresent(LINK_DEL_EXCEPTPORT), "Exception
portlet not found.");
- selenium.click(LINK_DEL_EXCEPTPORT);
- selenium.waitForPageToLoad(PAGE_LOAD);
+ goToPI();
+ r = traversePortlets(instance_name,1);
+ Assert.assertTrue(selenium.isElementPresent(MessageFormat.format(LNK_INSTANCE_BUTTON,
r)), instance_name+" portlet not found.");
+ clickAndWait(MessageFormat.format(LNK_DEL_BUTTON, r));
+
Assert.assertTrue(selenium.isTextPresent("WARNING!"));
Assert.assertTrue(selenium.isTextPresent("Are you sure you want to delete this
portlet instance ?"));
selenium.click(SUBMIT_PI_DELETE_CONF);
selenium.waitForPageToLoad(PAGE_LOAD);
- Assert.assertFalse(selenium.isElementPresent(LINK_DEL_EXCEPTPORT), "Exception
portlet found after deletition.");
+
+ r = traversePortlets(instance_name,1);
+ Assert.assertFalse(selenium.isElementPresent(MessageFormat.format(LNK_INSTANCE_BUTTON,
r)), "previously deleted "+instance_name+" portlet found.");
+
}
@Test(enabled = true)
public void testPreferences() {
- int r;
- // selenium.click(LINK_20_PAGE);
- // selenium.waitForPageToLoad(PAGE_LOAD);
- selenium.click(LINK_CURUSER_PREFERENCES);
+
+ int r = traversePortlets(NAME_COUNTPORT,0);
+ clickAndWait(MessageFormat.format(LNK_PREF_BUTTON, r));
+ //selenium.click(LINK_CURUSER_PREFERENCES);
+
selenium.waitForPageToLoad(PAGE_LOAD);
selenium.click(SUBMIT_PREF_CANCEL);
selenium.waitForPageToLoad(PAGE_LOAD);
- selenium.click(LINK_CURUSER_PREFERENCES);
+
+ r = traversePortlets(NAME_COUNTPORT,0);
+ clickAndWait(MessageFormat.format(LNK_PREF_BUTTON, r));
+
selenium.waitForPageToLoad(PAGE_LOAD);
Assert.assertTrue(findTableRow(TABLE_PREF_KEY, "guestNumber", 0) >= 0);
selenium.click(LINK_PREF_GUESTNUM);
@@ -244,7 +270,43 @@
selenium.click(SUBMIT_PREF_SAVE);
selenium.waitForPageToLoad(PAGE_LOAD);
}
+
+ // acquiring link names from paginator
+ private String[] getPages(String paginator_location) {
+ String pagi = selenium.getText(paginator_location);
+ String[] pages = pagi.split(" ");
+
+ return pages;
+ }
+
+ /*
+ * function for traversing the portles in the portles table. when a string in
+ * selected columns is not found, links form paginator are used to look to the next
page
+ */
+ private int traversePortlets(String instance_name,int row) {
+
+ int r = -1;
+
+ r = findTableRow(TAB_PORTLET_INSTANCES, instance_name, row);
+
+ if (r >= 0)
+ return r;
+
+ String pages[] = getPages(UL_PAGINATOR);
+ for (String page : pages) {
+ if ("".equals(page.trim()))
+ continue;
+ selenium.click("link=" + page);
+ selenium.waitForPageToLoad(PAGE_LOAD);
+ r = findTableRow(TAB_PORTLET_INSTANCES, instance_name, row);
+
+ if (r >= 0)
+ break;
+ }
+
+ return r;
+ }
private void goToPI() {
selenium.open(ADDR_PORTAL);
clickIfVisible(LINK_ADMIN);