[richfaces-svn-commits] JBoss Rich Faces SVN: r13612 - in trunk/test-applications/realworld2/tests/src/test/java/org/richfaces/realworld: testng and 1 other directory.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Thu Apr 16 12:43:39 EDT 2009


Author: konstantin.mishin
Date: 2009-04-16 12:43:39 -0400 (Thu, 16 Apr 2009)
New Revision: 13612

Added:
   trunk/test-applications/realworld2/tests/src/test/java/org/richfaces/realworld/testng/OpenAreasUseCasesTest.java
Removed:
   trunk/test-applications/realworld2/tests/src/test/java/org/richfaces/realworld/testng/ShelfsImagesUseCasesTest.java
Modified:
   trunk/test-applications/realworld2/tests/src/test/java/org/richfaces/realworld/RealWorldHelper.java
   trunk/test-applications/realworld2/tests/src/test/java/org/richfaces/realworld/SeleniumTestBase.java
   trunk/test-applications/realworld2/tests/src/test/java/org/richfaces/realworld/testng/LoginTest.java
Log:
add new tests

Modified: trunk/test-applications/realworld2/tests/src/test/java/org/richfaces/realworld/RealWorldHelper.java
===================================================================
--- trunk/test-applications/realworld2/tests/src/test/java/org/richfaces/realworld/RealWorldHelper.java	2009-04-16 14:59:39 UTC (rev 13611)
+++ trunk/test-applications/realworld2/tests/src/test/java/org/richfaces/realworld/RealWorldHelper.java	2009-04-16 16:43:39 UTC (rev 13612)
@@ -5,7 +5,7 @@
 
 import org.testng.Assert;
 
-import com.thoughtworks.selenium.DefaultSelenium;
+import com.thoughtworks.selenium.Selenium;
 
 /**
  * @author Andrey Markavtsov
@@ -14,77 +14,194 @@
 public class RealWorldHelper {
 	
 		
-	public static interface HtmlConstants {
+    private static final String WINDOW_JS_RESOLVER = "selenium.browserbot.getCurrentWindow().";
+    private static final String STATUS_START_ID = "_viewRoot:status.start";
+    private static final int TIMEOUT = 20000;
+    
+    public static interface UserInfoConstants {
+		String LOGIN_NAME = "amarkhel";
+		String LOGIN_PASSWORD = "12345";
+    }
+    
+    public static interface HtmlConstants {
+    	
+		public static interface IndexPage {
+			String MAIN_FORM_ID = "mainform";
+			//String shelfCountPath = "//table[@id='menuform:menu']/tbody/tr/td[2]";
+			//int SHELF_COUNT = 2;
+		}
+		
 		public static interface LoginPage {
-			String usernameId = "loginPanelForm:username";
-			String passwordId = "loginPanelForm:password";
-			String loginButtonPath= "//td[@class='login-table-col']/input[1]";
-			String loginLinkId = "j_id27:loginPanelShowlink";
+			String LOGIN_FORM_ID = "loginPanelForm";
+			String usernameId = LOGIN_FORM_ID + ":username";
+			String passwordId = LOGIN_FORM_ID + ":password";
+			String loginButtonPath= "//*[@class='login-table-col']//*[@type='image']";
 			
-			String LOGIN_NAME = "amarkhel";
-			String LOGIN_PASSWORD = "12345";
-		};
+		}
 		
-		public static interface IndexPage {
-			String loggedUserPath = "//a[@class='logged-user']";
-			String shelfCountPath = "//table[@id='menuform:menu']/tbody/tr/td[2]";
-			int SHELF_COUNT = 2;
-			String ALBUM_PATH = "//div[@class='preview_box_album_120']/table/tbody/tr/td/a";
-			String ALBUM_NAME_PATH = "//div[@class='preview_box_album_120']/div[@class='album_name']";
-
+		public static interface LogInOutArea {
+			String LOGIN_LINK_ID = "loginPanelShowlink";
+			String LOGOUT_LINK_PATH = "//*[@id='logInOutMenu']//div/a";
+			String USER_INFO_LINK_PATH = "//a[@class='logged-user']";
 		}
 		
+		public static interface ToolBarArea {
+			String TOOLBAR_PATH = "//*[@class='dr-toolbar-int rich-toolbar-item main-menu-toolbar-content']";
+			String VIEW_SHELFS_PATH = TOOLBAR_PATH + "/div[2]";
+			String VIEW_ALBUMS_PATH = TOOLBAR_PATH + "/div[3]";
+			String VIEW_IMAGES_PATH = TOOLBAR_PATH + "/div[4]";
+			String ADD_IMAGE_LINK_PATH = TOOLBAR_PATH + "/*[@id='menuform:add_icons_div_id']/a[3]";
+		}
+		
+		public static interface ShelfArea {
+			String HEADER_PATH = "//*[@class='shelf-header-table']";
+			String SHELF_NAME_PATH = HEADER_PATH + "//h1";
+			String ALBUM_PATH = "//*[@class='preview_box_album_120']";
+			String ALBUM_LINK_PATH = ALBUM_PATH + "//a";
+			String ALBUM_NAME_PATH = ALBUM_PATH + "/*[@class='album_name']";
+		}
+		
 		public static interface AlbumArea {
-			String ALBUM_HEADER_NAME = "//table[@class='album-header-table']/tbody/tr/td/h1";
-			String IMAGES_CONTAINER = "//span[@id='mainform:userAlbumImages']";
+			String HEADER_PATH = "//*[@class='album-header-table']";
+			String ALBUM_NAME_PATH = HEADER_PATH + "//h1";
+			String IMAGE_PATH = "//*[@class='preview_box_photo_120']";
+			String IMAGE_LINK_PATH = IMAGE_PATH + "//a";
+			String IMAGE_NAME_PATH = IMAGE_PATH + "/*[@class='photo_name']";
+			//String IMAGES_CONTAINER = "//span[@id='mainform:userAlbumImages']";
 		}
 		
+		public static interface ImageArea {
+			String HEADER_PATH = "//*[@class='image-header-table']";
+			String IMAGE_NAME_PATH = HEADER_PATH + "//h1";
+		}
+		
+		public static interface UserProfileArea {
+			String NAME_INPUT_ID = IndexPage.MAIN_FORM_ID + ":loginName";
+		}
+		
+		public static interface FilesUploadArea {
+			String FILE_UPLOAD_ID = IndexPage.MAIN_FORM_ID + ":fileUpload";
+		}
+		
 		public static interface TreeArea {
 			
 		}
-	};
+	}
 
 	
-	public static void Login(DefaultSelenium selenium) {
-		selenium.click("id=" + HtmlConstants.LoginPage.loginLinkId);
+	public static void login(Selenium selenium) {
+		selenium.click(HtmlConstants.LogInOutArea.LOGIN_LINK_ID);
 		try {
 			Thread.sleep(5000);
 		}catch (Exception e) {
 			Assert.fail("Test failed caused by: " + e);
 		}
 		
-		AssertVisible(selenium, HtmlConstants.LoginPage.usernameId, "Input for username in not visible");
-		AssertVisible(selenium, HtmlConstants.LoginPage.passwordId, "Input for password in not visible");
+		Assert.assertTrue(selenium.isVisible(HtmlConstants.LoginPage.usernameId), "Input for username in not visible");
+		Assert.assertTrue(selenium.isVisible(HtmlConstants.LoginPage.passwordId), "Input for password in not visible");
 		
 		String type = selenium.getAttribute("//*[@id='"+HtmlConstants.LoginPage.passwordId+"']/@type");
 		if (!"password".equals(type)) {
 			Assert.fail("Password input should be of 'password' type");
 		}
 		
-		setValueById(selenium, HtmlConstants.LoginPage.usernameId, HtmlConstants.LoginPage.LOGIN_NAME);
-		setValueById(selenium, HtmlConstants.LoginPage.passwordId, HtmlConstants.LoginPage.LOGIN_PASSWORD);
+		selenium.type(HtmlConstants.LoginPage.usernameId, UserInfoConstants.LOGIN_NAME);
+		selenium.type(HtmlConstants.LoginPage.passwordId, UserInfoConstants.LOGIN_PASSWORD);
 		
 		selenium.click(HtmlConstants.LoginPage.loginButtonPath);
 		selenium.waitForPageToLoad("10000");
 		
-		String loggedText = selenium.getText(HtmlConstants.IndexPage.loggedUserPath);
-		if (!loggedText.contains(HtmlConstants.LoginPage.LOGIN_NAME)) {
+		if (!isLogined(selenium, UserInfoConstants.LOGIN_NAME)) {
 			Assert.fail("Authentication was not succesfull. Logged user text should contain typed login name");
 		}
-		
-		String shelfCount = selenium.getText(HtmlConstants.IndexPage.shelfCountPath);
-		if (!String.valueOf(HtmlConstants.IndexPage.SHELF_COUNT).equals(shelfCount)) {
-			Assert.fail("Shelf count for user [" + HtmlConstants.LoginPage.LOGIN_NAME + "] should be "  + HtmlConstants.IndexPage.SHELF_COUNT + ".But was " + shelfCount);
+
+	}
+	
+	public static void logout(Selenium selenium) {
+		selenium.click(HtmlConstants.LogInOutArea.LOGOUT_LINK_PATH);
+		selenium.waitForPageToLoad(String.valueOf(TIMEOUT));
+		Assert.assertFalse(isLogined(selenium), "Logout was not succesfull.");
+	}
+	
+	public static void testUserProfile(Selenium selenium) {
+		String name = selenium.getValue(HtmlConstants.UserProfileArea.NAME_INPUT_ID);
+		Assert.assertEquals(name, UserInfoConstants.LOGIN_NAME);
+	}
+	
+	public static void testFilesUpload(Selenium selenium) {
+		Assert.assertTrue(selenium.isVisible(HtmlConstants.FilesUploadArea.FILE_UPLOAD_ID));
+	}
+	
+	public static void testShelfArea(Selenium selenium) {
+		testShelfArea(selenium, null);
+	}
+
+	public static void testShelfArea(Selenium selenium, String shelfName) {
+		Assert.assertTrue(selenium.isVisible(HtmlConstants.ShelfArea.HEADER_PATH));
+		if (shelfName != null) {
+			String text = selenium.getText(RealWorldHelper.HtmlConstants.ShelfArea.SHELF_NAME_PATH);
+			Assert.assertTrue(text.contains(shelfName), "Incorrect data was opened after click by album");
 		}
+	}
+	
+	public static void openAlbumFromShelfArea(Selenium selenium) {		
+		String albumName = selenium.getText(RealWorldHelper.HtmlConstants.ShelfArea.ALBUM_NAME_PATH);
 		
+		selenium.click(RealWorldHelper.HtmlConstants.ShelfArea.ALBUM_LINK_PATH);
+		waitForAjaxCompletion(selenium);
+		
+		testAlbumArea(selenium, albumName);
 	}
 	
-	public static void AssertVisible(DefaultSelenium selenium, String id, String message) {
-	        Assert.assertTrue(selenium.isVisible("id=" + id), message);
+	public static void testAlbumArea(Selenium selenium) {
+		testAlbumArea(selenium, null);
 	}
+
+	public static void testAlbumArea(Selenium selenium, String albumName) {
+		Assert.assertTrue(selenium.isVisible(HtmlConstants.AlbumArea.HEADER_PATH));
+		if (albumName != null) {
+			String text = selenium.getText(RealWorldHelper.HtmlConstants.AlbumArea.ALBUM_NAME_PATH);
+			Assert.assertTrue(text.contains(albumName), "Incorrect data was opened after click by album");
+		}
+	}
 	
-	public static void setValueById(DefaultSelenium selenium, String id, String value) {
-		selenium.getEval(String.format("selenium.browserbot.getCurrentWindow().document.getElementById('%1$s').value='%2$s';", id, value));
+	public static void openImageFromAlbumArea(Selenium selenium) {		
+		String imageName = selenium.getText(RealWorldHelper.HtmlConstants.AlbumArea.IMAGE_NAME_PATH);
+		
+		selenium.click(RealWorldHelper.HtmlConstants.AlbumArea.IMAGE_LINK_PATH);
+		waitForAjaxCompletion(selenium);
+		
+		testImageArea(selenium, imageName);
 	}
+		
+	public static void testImageArea(Selenium selenium) {
+		testImageArea(selenium, null);
+	}
+	
+	public static void testImageArea(Selenium selenium, String imageName) {
+		Assert.assertTrue(selenium.isVisible(HtmlConstants.ImageArea.HEADER_PATH));
+		if (imageName != null) {
+			String text = selenium.getText(RealWorldHelper.HtmlConstants.ImageArea.IMAGE_NAME_PATH);
+			Assert.assertTrue(text.contains(imageName), "Incorrect data was opened after click by image");
+		}
+	}
 
+	public static void waitForAjaxCompletion(Selenium selenium) {
+		waitForAjaxCompletion(selenium, TIMEOUT);
+    }
+    public static void waitForAjaxCompletion(Selenium selenium, int miliseconds) {
+        selenium.waitForCondition(WINDOW_JS_RESOLVER + "document.getElementById('" + STATUS_START_ID + "').style.display == 'none'", String.valueOf(miliseconds));
+    }
+    
+    public static boolean isLogined(Selenium selenium) {
+    	return isLogined(selenium, null);
+    }
+
+    public static boolean isLogined(Selenium selenium, String name) {
+    	boolean logined = !selenium.getXpathCount(HtmlConstants.LogInOutArea.USER_INFO_LINK_PATH).equals(0);
+    	if (logined && name != null) {
+    		logined = selenium.getText(HtmlConstants.LogInOutArea.USER_INFO_LINK_PATH).contains(name);
+    	}
+    	return logined;    	
+    }
 }

Modified: trunk/test-applications/realworld2/tests/src/test/java/org/richfaces/realworld/SeleniumTestBase.java
===================================================================
--- trunk/test-applications/realworld2/tests/src/test/java/org/richfaces/realworld/SeleniumTestBase.java	2009-04-16 14:59:39 UTC (rev 13611)
+++ trunk/test-applications/realworld2/tests/src/test/java/org/richfaces/realworld/SeleniumTestBase.java	2009-04-16 16:43:39 UTC (rev 13612)
@@ -848,7 +848,7 @@
      * @return
      */
     public String getTestUrl() {
-    	return "/index.seam";
+    	return "/index.seam?startConversation=1";
     }
     
     /**

Modified: trunk/test-applications/realworld2/tests/src/test/java/org/richfaces/realworld/testng/LoginTest.java
===================================================================
--- trunk/test-applications/realworld2/tests/src/test/java/org/richfaces/realworld/testng/LoginTest.java	2009-04-16 14:59:39 UTC (rev 13611)
+++ trunk/test-applications/realworld2/tests/src/test/java/org/richfaces/realworld/testng/LoginTest.java	2009-04-16 16:43:39 UTC (rev 13612)
@@ -18,7 +18,7 @@
 	public void testAuthentication() {
 		renderPage();
 		
-		RealWorldHelper.Login(selenium);
-		
+		RealWorldHelper.login(selenium);
+		RealWorldHelper.logout(selenium);
 	}
 }

Added: trunk/test-applications/realworld2/tests/src/test/java/org/richfaces/realworld/testng/OpenAreasUseCasesTest.java
===================================================================
--- trunk/test-applications/realworld2/tests/src/test/java/org/richfaces/realworld/testng/OpenAreasUseCasesTest.java	                        (rev 0)
+++ trunk/test-applications/realworld2/tests/src/test/java/org/richfaces/realworld/testng/OpenAreasUseCasesTest.java	2009-04-16 16:43:39 UTC (rev 13612)
@@ -0,0 +1,68 @@
+/**
+ * 
+ */
+package org.richfaces.realworld.testng;
+
+import org.richfaces.realworld.RealWorldHelper;
+import org.richfaces.realworld.SeleniumTestBase;
+import org.richfaces.realworld.RealWorldHelper.HtmlConstants;
+import org.testng.annotations.Test;
+
+/**
+ * @author Konstantin Mishin
+ *
+ */
+public class OpenAreasUseCasesTest extends SeleniumTestBase {
+
+	@Test
+	public void testOpenAlbumAndImageWithoutAuthentication() {
+		renderPage();
+		RealWorldHelper.openAlbumFromShelfArea(selenium);
+		RealWorldHelper.openImageFromAlbumArea(selenium);
+	}
+	
+	@Test
+	public void testOpenAlbumAndImageWithAuthentication() {
+		renderPage();
+		RealWorldHelper.login(selenium);
+		RealWorldHelper.openAlbumFromShelfArea(selenium);
+		RealWorldHelper.openImageFromAlbumArea(selenium);
+	}
+
+	@Test
+	public void testOpenUserProfile() {
+		renderPage();
+		RealWorldHelper.login(selenium);
+		selenium.click(HtmlConstants.LogInOutArea.USER_INFO_LINK_PATH);
+		waitForAjaxCompletion();
+		RealWorldHelper.testUserProfile(selenium);
+	}
+	
+	@Test
+	public void testOpenFilesUpload() {
+		renderPage();
+		RealWorldHelper.login(selenium);
+		selenium.click(HtmlConstants.ToolBarArea.ADD_IMAGE_LINK_PATH);
+		waitForAjaxCompletion();
+		RealWorldHelper.testFilesUpload(selenium);
+	}
+	
+	
+	@Test
+	public void testToolbarViewButtons() {
+		renderPage();
+		RealWorldHelper.login(selenium);
+		
+		selenium.click(HtmlConstants.ToolBarArea.VIEW_SHELFS_PATH);
+		waitForAjaxCompletion();
+		RealWorldHelper.testShelfArea(selenium);
+
+		selenium.click(HtmlConstants.ToolBarArea.VIEW_ALBUMS_PATH);
+		waitForAjaxCompletion();
+		RealWorldHelper.testAlbumArea(selenium);
+		
+		selenium.click(HtmlConstants.ToolBarArea.VIEW_IMAGES_PATH);
+		waitForAjaxCompletion();
+		RealWorldHelper.testImageArea(selenium);
+	}
+}

Deleted: trunk/test-applications/realworld2/tests/src/test/java/org/richfaces/realworld/testng/ShelfsImagesUseCasesTest.java
===================================================================
--- trunk/test-applications/realworld2/tests/src/test/java/org/richfaces/realworld/testng/ShelfsImagesUseCasesTest.java	2009-04-16 14:59:39 UTC (rev 13611)
+++ trunk/test-applications/realworld2/tests/src/test/java/org/richfaces/realworld/testng/ShelfsImagesUseCasesTest.java	2009-04-16 16:43:39 UTC (rev 13612)
@@ -1,33 +0,0 @@
-/**
- * 
- */
-package org.richfaces.realworld.testng;
-
-import org.richfaces.realworld.RealWorldHelper;
-import org.richfaces.realworld.SeleniumTestBase;
-import org.testng.Assert;
-import org.testng.annotations.Test;
-
-/**
- * @author Andrey Markavtsov
- *
- */
-public class ShelfsImagesUseCasesTest extends SeleniumTestBase {
-
-	@Test
-	public void testAlbumOpen () {
-		renderPage();
-		RealWorldHelper.Login(selenium);
-		
-		String shelfName = selenium.getText(RealWorldHelper.HtmlConstants.IndexPage.ALBUM_NAME_PATH);
-		
-		selenium.click(RealWorldHelper.HtmlConstants.IndexPage.ALBUM_PATH);
-		waitForAjaxCompletion();
-		
-		Assert.assertTrue(shelfName.equals(selenium.getText(RealWorldHelper.HtmlConstants.AlbumArea.ALBUM_HEADER_NAME)), "Incorrect data was opened after click by album");
-		
-		int imagesCount = selenium.getXpathCount(RealWorldHelper.HtmlConstants.AlbumArea.IMAGES_CONTAINER + "/div").intValue();
-		Assert.assertTrue(imagesCount > 0, "Opened album has no images, but should.");
-		
-	}
-}




More information about the richfaces-svn-commits mailing list