[richfaces-svn-commits] JBoss Rich Faces SVN: r13758 - trunk/examples/photoalbum/tests/src/test/java/org/richfaces/photoalbum.
richfaces-svn-commits at lists.jboss.org
richfaces-svn-commits at lists.jboss.org
Wed Apr 22 07:38:59 EDT 2009
Author: Alex.Kolonitsky
Date: 2009-04-22 07:38:59 -0400 (Wed, 22 Apr 2009)
New Revision: 13758
Added:
trunk/examples/photoalbum/tests/src/test/java/org/richfaces/photoalbum/RealWorldHelper.java
Log:
add helper
Added: trunk/examples/photoalbum/tests/src/test/java/org/richfaces/photoalbum/RealWorldHelper.java
===================================================================
--- trunk/examples/photoalbum/tests/src/test/java/org/richfaces/photoalbum/RealWorldHelper.java (rev 0)
+++ trunk/examples/photoalbum/tests/src/test/java/org/richfaces/photoalbum/RealWorldHelper.java 2009-04-22 11:38:59 UTC (rev 13758)
@@ -0,0 +1,207 @@
+/**
+ *
+ */
+package org.richfaces.photoalbum;
+
+import org.testng.Assert;
+
+import com.thoughtworks.selenium.Selenium;
+
+/**
+ * @author Andrey Markavtsov
+ *
+ */
+public class RealWorldHelper {
+
+
+ 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 LOGIN_FORM_ID = "loginPanelForm";
+ String usernameId = LOGIN_FORM_ID + ":username";
+ String passwordId = LOGIN_FORM_ID + ":password";
+ String loginButtonPath= "//*[@class='login-table-col']//*[@type='image']";
+
+ }
+
+ 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 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(Selenium selenium) {
+ selenium.click(HtmlConstants.LogInOutArea.LOGIN_LINK_ID);
+ try {
+ Thread.sleep(5000);
+ }catch (Exception e) {
+ Assert.fail("Test failed caused by: " + e);
+ }
+
+ 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");
+ }
+
+ selenium.type(HtmlConstants.LoginPage.usernameId, UserInfoConstants.LOGIN_NAME);
+ selenium.type(HtmlConstants.LoginPage.passwordId, UserInfoConstants.LOGIN_PASSWORD);
+
+ selenium.click(HtmlConstants.LoginPage.loginButtonPath);
+ selenium.waitForPageToLoad("10000");
+
+ 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) {
+ 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 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 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;
+ }
+}
More information about the richfaces-svn-commits
mailing list