[richfaces-svn-commits] JBoss Rich Faces SVN: r14095 - in trunk/examples/photoalbum/tests/src/test/java/org/richfaces/photoalbum: testng and 1 other directory.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Fri May 8 14:25:53 EDT 2009


Author: konstantin.mishin
Date: 2009-05-08 14:25:52 -0400 (Fri, 08 May 2009)
New Revision: 14095

Modified:
   trunk/examples/photoalbum/tests/src/test/java/org/richfaces/photoalbum/RealWorldHelper.java
   trunk/examples/photoalbum/tests/src/test/java/org/richfaces/photoalbum/testng/DnDUseCasesTest.java
Log:
RF-6909

Modified: trunk/examples/photoalbum/tests/src/test/java/org/richfaces/photoalbum/RealWorldHelper.java
===================================================================
--- trunk/examples/photoalbum/tests/src/test/java/org/richfaces/photoalbum/RealWorldHelper.java	2009-05-08 18:05:55 UTC (rev 14094)
+++ trunk/examples/photoalbum/tests/src/test/java/org/richfaces/photoalbum/RealWorldHelper.java	2009-05-08 18:25:52 UTC (rev 14095)
@@ -81,9 +81,10 @@
 			String HEADER_NAME_PATH_SUFFIX = "//h1//text()";
 			String HEADER_NAME_PATH = HEADER_PATH + HEADER_NAME_PATH_SUFFIX;
 			String DESCRIPTION_PATH = HEADER_PATH + "/following-sibling::p";
-			String CONTROLS_PATH = "//*[@class='shelf-header-table-col2']";
+			String CONTROLS_PATH = "//*[@class='content_box']/descendant::*[@class='shelf-header-table-col2']";
 			String EDIT_PATH = CONTROLS_PATH + "/a[1]";
 			String DELETE_PATH = CONTROLS_PATH + "/a[2]";
+			String VIEW_PATH_SUFFIX = "/a[3]";
 		}
 		
 		public static interface EditShelfArea {
@@ -149,7 +150,10 @@
 		}
 
 		public static interface TreeArea {
-
+			String CHILDREN_PATH = "//*[@id='treeform:tree']/*[@class='dr-tree rich-tree']/*[contains(@id, 'childs')]";
+			String SHELF_PATH_PART = CHILDREN_PATH + "/*[not(contains(@class, 'rich-tree-node-children'))]";
+			String ALBUM_PATH_PART = CHILDREN_PATH + "/*[contains(@class, 'rich-tree-node-children')]";
+			String TEXT_PATH_SUFFIX = "/descendant::*[contains(@id, 'text')]";
 		}
 
 		public static interface ResizeSlider {
@@ -183,7 +187,10 @@
 		login(selenium, UserInfoConstants.LOGIN_NAME, UserInfoConstants.LOGIN_PASSWORD);
 	}
 	
-	public static void login(Selenium selenium, String name, String password) {		
+	public static void login(Selenium selenium, String name, String password) {
+		if (isLogined(selenium)) {
+			logout(selenium);
+		}
 		selenium.click(HtmlConstants.LogInOutArea.LOGIN_ID);
 		try {
 			Thread.sleep(5000);
@@ -208,7 +215,6 @@
 		if (!isLogined(selenium, UserInfoConstants.LOGIN_NAME)) {
 			Assert.fail("Authentication was not succesfull. Logged user text should contain typed login name");
 		}
-
 	}
 	
 	public static void logout(Selenium selenium) {
@@ -232,6 +238,26 @@
 		Assert.assertTrue(selenium.isVisible(HtmlConstants.FilesUploadArea.FILE_UPLOAD_ID));
 	}
 	
+	public static void openShelf(Selenium selenium, String shelfName) {
+		boolean presented = false;
+		int xpathCount = selenium.getXpathCount(HtmlConstants.ShelfArea.HEADER_PATH).intValue();
+		for (int i = 2; i <= xpathCount && !presented; i++) {
+			presented = selenium.getText("" + HtmlConstants.ShelfArea.HEADER_PATH
+					+ "[" + i + "]" + HtmlConstants.ShelfArea.HEADER_NAME_PATH_SUFFIX)
+					.equals(shelfName);
+			
+			if (presented) {
+				selenium.click(HtmlConstants.ShelfArea.CONTROLS_PATH + "[" + (i - 1) + "]" +  HtmlConstants.ShelfArea.VIEW_PATH_SUFFIX);
+				waitForAjaxCompletion(selenium);
+				testShelfArea(selenium, shelfName);
+			}
+		}
+		if (!presented) {
+			Assert.fail("Shelf with name '" + shelfName + "' doesn't exist on this page.");
+		}
+		
+	}
+	
 	public static void testShelfArea(Selenium selenium) {
 		testShelfArea(selenium, null, null);
 	}
@@ -253,7 +279,6 @@
 	}
 	
 	public static boolean isShelfPresentOnPage(Selenium selenium, String shelfName) {
-		testShelfArea(selenium);
 		boolean presented = false;
 		if (shelfName != null) {
 			int xpathCount = selenium.getXpathCount(HtmlConstants.ShelfArea.HEADER_PATH).intValue();
@@ -285,6 +310,21 @@
 		testShelfArea(selenium, shelfName);
 	}
 
+	public static String getShelfTextPathInTree(Selenium selenium, String shelfName) {
+		String xPath = null;
+		int xpathCount = selenium.getXpathCount(HtmlConstants.TreeArea.SHELF_PATH_PART).intValue();
+		for (int i = 1; i <= xpathCount && xPath == null; i++) {
+			String path = HtmlConstants.TreeArea.SHELF_PATH_PART + "[" + i + "]" + HtmlConstants.TreeArea.TEXT_PATH_SUFFIX;
+			if (selenium.getText(path).contains(shelfName)) {
+				xPath = path;
+			}
+		}
+		if (xPath == null) {
+			Assert.fail("Shelf with name '" + shelfName + "' doesn't exist in tree.");
+		}
+		return xPath;
+	}
+
 	public static void openAlbumFromPreview(Selenium selenium) {
 		openAlbumFromPreview(selenium, selenium.getText(HtmlConstants.AlbumArea.PREVIEW_PATH + HtmlConstants.AlbumArea.PREVIEW_NAME_PATH_SUFFIX));
 	}
@@ -330,7 +370,6 @@
 	}
 	
 	public static boolean isAlbumPresentOnPage(Selenium selenium, String albumName) {
-		testAlbumArea(selenium);
 		boolean presented = false;
 		if (albumName != null) {
 			int xpathCount = selenium.getXpathCount(HtmlConstants.AlbumArea.PREVIEW_PATH).intValue();
@@ -362,6 +401,25 @@
 		testAlbumArea(selenium, albumName);
 	}
 
+	public static String getAlbumTextPathInTree(Selenium selenium, String albumName) {
+		String xPath = null;
+		int xpathCount = selenium.getXpathCount(HtmlConstants.TreeArea.ALBUM_PATH_PART).intValue();
+		for (int i = 1; i <= xpathCount && xPath == null; i++) {
+			String pathPart = HtmlConstants.TreeArea.ALBUM_PATH_PART + "[" + i + "]" + HtmlConstants.TreeArea.TEXT_PATH_SUFFIX;
+			int xpathCount2 = selenium.getXpathCount(pathPart).intValue();
+			for (int j = 1; j <= xpathCount2 && xPath == null; j++) {
+				String path = pathPart + "[" + j + "]";
+				if (selenium.getText(path).contains(albumName)) {
+					xPath = path;
+				}
+			}
+		}
+		if (xPath == null) {
+			Assert.fail("Album with name '" + albumName + "' doesn't exist in tree.");
+		}
+		return xPath;
+	}
+
 	public static void openImageFromPreview(Selenium selenium) {
 		openImageFromPreview(selenium, selenium.getText(HtmlConstants.ImageArea.PREVIEW_PATH + HtmlConstants.ImageArea.PREVIEW_NAME_PATH_SUFFIX));
 	}
@@ -406,7 +464,6 @@
 	}
 
 	public static boolean isImagePresentOnPage(Selenium selenium, String imageName) {
-		testImageArea(selenium);
 		boolean presented = false;
 		if (imageName != null) {
 			int xpathCount = selenium.getXpathCount(HtmlConstants.ImageArea.PREVIEW_PATH).intValue();

Modified: trunk/examples/photoalbum/tests/src/test/java/org/richfaces/photoalbum/testng/DnDUseCasesTest.java
===================================================================
--- trunk/examples/photoalbum/tests/src/test/java/org/richfaces/photoalbum/testng/DnDUseCasesTest.java	2009-05-08 18:05:55 UTC (rev 14094)
+++ trunk/examples/photoalbum/tests/src/test/java/org/richfaces/photoalbum/testng/DnDUseCasesTest.java	2009-05-08 18:25:52 UTC (rev 14095)
@@ -5,6 +5,8 @@
 
 import org.richfaces.photoalbum.RealWorldHelper;
 import org.richfaces.photoalbum.SeleniumTestBase;
+import org.richfaces.photoalbum.RealWorldHelper.HtmlConstants;
+import org.testng.Assert;
 import org.testng.annotations.Test;
 
 /**
@@ -13,18 +15,26 @@
  */
 public class DnDUseCasesTest extends SeleniumTestBase {
 	
-	//TODO @Test
-	public void testDnDAlbum() {
+	@Test
+	public void testDnDAlbumFromTree() {
 		renderPage();
-
 		RealWorldHelper.login(selenium);
+		String fromShelfName = selenium.getText(HtmlConstants.ShelfArea.HEADER_PATH + "[2]" + HtmlConstants.ShelfArea.HEADER_NAME_PATH_SUFFIX);
+		String toShelfName = selenium.getText(HtmlConstants.ShelfArea.HEADER_PATH + "[3]" + HtmlConstants.ShelfArea.HEADER_NAME_PATH_SUFFIX);
+		RealWorldHelper.openShelf(selenium, fromShelfName);
 		RealWorldHelper.openAlbumFromPreview(selenium);
-
-		String compId = "treeform:j_id148";
-
-		String natureAlbumXpath = "//*[@id='"+ compId + ":childs']/div[1]/table[1]/tbody/tr/td[3]";
-		String sportShelfXpath = "//*[@id='"+ compId + ":childs']/table[2]/tbody/tr/td[3]";
-		selenium.dragAndDropToObject(natureAlbumXpath, sportShelfXpath);
+		String albumName = selenium.getText(RealWorldHelper.HtmlConstants.AlbumArea.HEADER_NAME_PATH);
+		String shelfTextPath = RealWorldHelper.getShelfTextPathInTree(selenium, toShelfName);
+		String albumTextPath = RealWorldHelper.getAlbumTextPathInTree(selenium, albumName);
+		selenium.dragAndDropToObject(albumTextPath, shelfTextPath);
 		waitForAjaxCompletion();
+		selenium.click(HtmlConstants.ToolBarArea.VIEW_SHELFS_PATH);
+		waitForAjaxCompletion();
+		RealWorldHelper.openShelf(selenium, fromShelfName);
+		Assert.assertFalse(RealWorldHelper.isAlbumPresentOnPage(selenium, albumName));
+		selenium.click(HtmlConstants.ToolBarArea.VIEW_SHELFS_PATH);
+		waitForAjaxCompletion();
+		RealWorldHelper.openShelf(selenium, toShelfName);
+		Assert.assertTrue(RealWorldHelper.isAlbumPresentOnPage(selenium, albumName));
 	}
 }




More information about the richfaces-svn-commits mailing list