Author: konstantin.mishin
Date: 2009-04-25 10:47:35 -0400 (Sat, 25 Apr 2009)
New Revision: 13868
Modified:
trunk/examples/photoalbum/tests/src/test/java/org/richfaces/photoalbum/RealWorldHelper.java
trunk/examples/photoalbum/tests/src/test/java/org/richfaces/photoalbum/testng/OpenAreasUseCasesTest.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-04-25
14:42:40 UTC (rev 13867)
+++
trunk/examples/photoalbum/tests/src/test/java/org/richfaces/photoalbum/RealWorldHelper.java 2009-04-25
14:47:35 UTC (rev 13868)
@@ -31,14 +31,20 @@
//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";
+ public static interface LoginPanel {
+ String FORM_ID = "loginPanelForm";
+ String usernameId = FORM_ID + ":username";
+ String passwordId = FORM_ID + ":password";
String loginButtonPath=
"//*[@class='login-table-col']//*[@type='image']";
}
+ public static interface ConfirmationPanel {
+ String FORM_ID = "confirmForm";
+ String OK_PATH = "//*[@id='" + FORM_ID +
":firstButton']//input";
+ String CANCEL_PATH = "//*[@id='" + FORM_ID +
":secondButton']//input";
+ }
+
public static interface LogInOutArea {
String LOGIN_LINK_ID = "loginPanelShowlink";
String LOGOUT_LINK_PATH = "//*[@id='logInOutMenu']//div/a";
@@ -46,33 +52,37 @@
}
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]";
+ String PATH = "//*[@class='dr-toolbar-int rich-toolbar-item
main-menu-toolbar-content']";
+ String VIEW_SHELFS_PATH = PATH + "/div[2]";
+ String VIEW_ALBUMS_PATH = PATH + "/div[3]";
+ String VIEW_IMAGES_PATH = PATH + "/div[4]";
+ String ADD_IMAGE_LINK_PATH = 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']";
+ String HEADER_NAME_PATH_SUFIX = "//h1";
+ String HEADER_NAME_PATH = HEADER_PATH + HEADER_NAME_PATH_SUFIX;
+ String DELETE_BUTTON_PATH =
"//*[@class='shelf-header-table-col2']/a[2]";
}
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 HEADER_NAME_PATH = HEADER_PATH + "//h1";
+ String PREVIEW_PATH = "//*[@class='preview_box_album_120']";
+ String PREVIEW_LINK_PATH_SUFFIX = "//a";
+ String PREVIEW_NAME_PATH_SUFFIX = "/*[@class='album_name']";
+ String DELETE_BUTTON_PATH =
"//*[@class='album-header-table-col2']/a[2]";
//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";
+ String HEADER_NAME_PATH = HEADER_PATH + "//h1";
+ String PREVIEW_PATH = "//*[@class='preview_box_photo_120']";
+ String PREVIEW_LINK_PATH_SUFFIX = "//a";
+ String PREVIEW_NAME_PATH_SUFFIX = "/*[@class='photo_name']";
+ String DELETE_BUTTON_PATH =
"//*[@class='mainImage-table-col3']/div[2]/input";
}
public static interface UserProfileArea {
@@ -97,18 +107,18 @@
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");
+ Assert.assertTrue(selenium.isVisible(HtmlConstants.LoginPanel.usernameId), "Input
for username in not visible");
+ Assert.assertTrue(selenium.isVisible(HtmlConstants.LoginPanel.passwordId), "Input
for password in not visible");
- String type =
selenium.getAttribute("//*[@id='"+HtmlConstants.LoginPage.passwordId+"']/(a)type");
+ String type =
selenium.getAttribute("//*[@id='"+HtmlConstants.LoginPanel.passwordId+"']/(a)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.type(HtmlConstants.LoginPanel.usernameId, UserInfoConstants.LOGIN_NAME);
+ selenium.type(HtmlConstants.LoginPanel.passwordId, UserInfoConstants.LOGIN_PASSWORD);
- selenium.click(HtmlConstants.LoginPage.loginButtonPath);
+ selenium.click(HtmlConstants.LoginPanel.loginButtonPath);
waitForAjaxCompletion(selenium);
if (!isLogined(selenium, UserInfoConstants.LOGIN_NAME)) {
@@ -139,18 +149,60 @@
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");
+ String text =
selenium.getText(RealWorldHelper.HtmlConstants.ShelfArea.HEADER_NAME_PATH);
+ Assert.assertTrue(text.contains(shelfName), "Incorrect data was opened on shelf
area.");
}
}
- public static void openAlbumFromShelfArea(Selenium selenium) {
- String albumName =
selenium.getText(RealWorldHelper.HtmlConstants.ShelfArea.ALBUM_NAME_PATH);
-
- selenium.click(RealWorldHelper.HtmlConstants.ShelfArea.ALBUM_LINK_PATH);
+ 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();
+ for (int i = 1; i <= xpathCount && !presented; i++) {
+ presented = selenium.getText(HtmlConstants.ShelfArea.HEADER_PATH
+ + "[" + i + "]" +
HtmlConstants.ShelfArea.HEADER_NAME_PATH_SUFIX)
+ .contains(shelfName);
+
+ }
+ } else {
+ Assert.fail("ShelfName shouldn't be null.");
+ }
+ return presented;
+ }
+
+ public static void deleteCurrentShelf(Selenium selenium) {
+ selenium.click(HtmlConstants.ShelfArea.DELETE_BUTTON_PATH);
waitForAjaxCompletion(selenium);
+ confirm(selenium);
+ testShelfArea(selenium);
+ }
+
+ public static void openAlbumFromPreview(Selenium selenium) {
+ openAlbumFromPreview(selenium, null);
+ }
+
+ public static void openAlbumFromPreview(Selenium selenium, String albumName) {
+ if (albumName == null) {
+ albumName = selenium.getText(HtmlConstants.AlbumArea.PREVIEW_PATH +
HtmlConstants.AlbumArea.PREVIEW_NAME_PATH_SUFFIX);
+ }
+ boolean presented = false;
+ int xpathCount =
selenium.getXpathCount(HtmlConstants.AlbumArea.PREVIEW_PATH).intValue();
+ for (int i = 1; i <= xpathCount && !presented; i++) {
+ presented = selenium.getText(HtmlConstants.AlbumArea.PREVIEW_PATH
+ + "[" + i + "]" +
HtmlConstants.AlbumArea.PREVIEW_NAME_PATH_SUFFIX)
+ .contains(albumName);
+ if (presented) {
+ selenium.click(HtmlConstants.AlbumArea.PREVIEW_PATH + "[" + i +
"]" + HtmlConstants.AlbumArea.PREVIEW_LINK_PATH_SUFFIX);
+ waitForAjaxCompletion(selenium);
+ testAlbumArea(selenium, albumName);
+ }
+
+ }
+ if (!presented) {
+ Assert.fail("Album with name '" + albumName + "' doesn't
exist on this page.");
+ }
- testAlbumArea(selenium, albumName);
}
public static void testAlbumArea(Selenium selenium) {
@@ -160,17 +212,60 @@
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");
+ String text =
selenium.getText(RealWorldHelper.HtmlConstants.AlbumArea.HEADER_NAME_PATH);
+ Assert.assertTrue(text.contains(albumName), "Incorrect data was opened on album
area.");
}
}
- public static void openImageFromAlbumArea(Selenium selenium) {
- String imageName =
selenium.getText(RealWorldHelper.HtmlConstants.AlbumArea.IMAGE_NAME_PATH);
- selenium.click(RealWorldHelper.HtmlConstants.AlbumArea.IMAGE_LINK_PATH);
+ 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();
+ for (int i = 1; i <= xpathCount && !presented; i++) {
+ presented = selenium.getText(HtmlConstants.AlbumArea.PREVIEW_PATH
+ + "[" + i + "]" +
HtmlConstants.AlbumArea.PREVIEW_NAME_PATH_SUFFIX)
+ .contains(albumName);
+
+ }
+ } else {
+ Assert.fail("AlbumName shouldn't be null.");
+ }
+ return presented;
+ }
+
+ public static void deleteCurrentAlbum(Selenium selenium) {
+ selenium.click(HtmlConstants.AlbumArea.DELETE_BUTTON_PATH);
waitForAjaxCompletion(selenium);
- testImageArea(selenium, imageName);
+ confirm(selenium);
+ testAlbumArea(selenium);
}
+
+ public static void openImageFromPreview(Selenium selenium) {
+ openImageFromPreview(selenium, null);
+ }
+
+ public static void openImageFromPreview(Selenium selenium, String imageName) {
+ if (imageName == null) {
+ imageName = selenium.getText(HtmlConstants.ImageArea.PREVIEW_PATH +
HtmlConstants.ImageArea.PREVIEW_NAME_PATH_SUFFIX);
+ }
+ boolean presented = false;
+ int xpathCount =
selenium.getXpathCount(HtmlConstants.ImageArea.PREVIEW_PATH).intValue();
+ for (int i = 1; i <= xpathCount && !presented; i++) {
+ presented = selenium.getText(HtmlConstants.ImageArea.PREVIEW_PATH
+ + "[" + i + "]" +
HtmlConstants.ImageArea.PREVIEW_NAME_PATH_SUFFIX)
+ .contains(imageName);
+ if (presented) {
+ selenium.click(HtmlConstants.ImageArea.PREVIEW_PATH + "[" + i +
"]" + HtmlConstants.ImageArea.PREVIEW_LINK_PATH_SUFFIX);
+ waitForAjaxCompletion(selenium);
+ testImageArea(selenium, imageName);
+ }
+
+ }
+ if (!presented) {
+ Assert.fail("Image with name '" + imageName + "' doesn't
exist on this page.");
+ }
+ }
public static void testImageArea(Selenium selenium) {
testImageArea(selenium, null);
@@ -179,11 +274,35 @@
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");
+ String text =
selenium.getText(RealWorldHelper.HtmlConstants.ImageArea.HEADER_NAME_PATH);
+ Assert.assertTrue(text.contains(imageName), "Incorrect data was opened on image
area.");
}
}
+ 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();
+ for (int i = 1; i <= xpathCount && !presented; i++) {
+ presented = selenium.getText(HtmlConstants.ImageArea.PREVIEW_PATH
+ + "[" + i + "]" +
HtmlConstants.ImageArea.PREVIEW_NAME_PATH_SUFFIX)
+ .contains(imageName);
+
+ }
+ } else {
+ Assert.fail("ImageName shouldn't be null.");
+ }
+ return presented;
+ }
+
+ public static void deleteCurrentImage(Selenium selenium) {
+ selenium.click(HtmlConstants.ImageArea.DELETE_BUTTON_PATH);
+ waitForAjaxCompletion(selenium);
+ confirm(selenium);
+ testAlbumArea(selenium);
+ }
+
public static void waitForAjaxCompletion(Selenium selenium) {
waitForAjaxCompletion(selenium, TIMEOUT);
}
@@ -191,6 +310,11 @@
selenium.waitForCondition(WINDOW_JS_RESOLVER +
"document.getElementById('" + STATUS_START_ID + "').style.display
== 'none'", String.valueOf(miliseconds));
}
+ public static void confirm(Selenium selenium) {
+ selenium.click(HtmlConstants.ConfirmationPanel.OK_PATH);
+ waitForAjaxCompletion(selenium);
+ }
+
public static boolean isLogined(Selenium selenium) {
return isLogined(selenium, null);
}
Modified:
trunk/examples/photoalbum/tests/src/test/java/org/richfaces/photoalbum/testng/OpenAreasUseCasesTest.java
===================================================================
---
trunk/examples/photoalbum/tests/src/test/java/org/richfaces/photoalbum/testng/OpenAreasUseCasesTest.java 2009-04-25
14:42:40 UTC (rev 13867)
+++
trunk/examples/photoalbum/tests/src/test/java/org/richfaces/photoalbum/testng/OpenAreasUseCasesTest.java 2009-04-25
14:47:35 UTC (rev 13868)
@@ -3,6 +3,8 @@
*/
package org.richfaces.photoalbum.testng;
+import junit.framework.Assert;
+
import org.richfaces.photoalbum.RealWorldHelper;
import org.richfaces.photoalbum.SeleniumTestBase;
import org.richfaces.photoalbum.RealWorldHelper.HtmlConstants;
@@ -17,16 +19,16 @@
@Test
public void testOpenAlbumAndImageWithoutAuthentication() {
renderPage();
- RealWorldHelper.openAlbumFromShelfArea(selenium);
- RealWorldHelper.openImageFromAlbumArea(selenium);
+ RealWorldHelper.openAlbumFromPreview(selenium);
+ RealWorldHelper.openImageFromPreview(selenium);
}
@Test
public void testOpenAlbumAndImageWithAuthentication() {
renderPage();
RealWorldHelper.login(selenium);
- RealWorldHelper.openAlbumFromShelfArea(selenium);
- RealWorldHelper.openImageFromAlbumArea(selenium);
+ RealWorldHelper.openAlbumFromPreview(selenium);
+ RealWorldHelper.openImageFromPreview(selenium);
}
@Test
@@ -65,4 +67,46 @@
waitForAjaxCompletion();
RealWorldHelper.testImageArea(selenium);
}
+
+ @Test
+ public void testDeleteImage() {
+ renderPage();
+ RealWorldHelper.login(selenium);
+ selenium.click(HtmlConstants.ToolBarArea.VIEW_IMAGES_PATH);
+ waitForAjaxCompletion();
+ String imageName = selenium.getText(HtmlConstants.ImageArea.PREVIEW_PATH +
HtmlConstants.ImageArea.PREVIEW_NAME_PATH_SUFFIX);
+ RealWorldHelper.openImageFromPreview(selenium);
+ RealWorldHelper.deleteCurrentImage(selenium);
+ selenium.click(HtmlConstants.ToolBarArea.VIEW_IMAGES_PATH);
+ waitForAjaxCompletion();
+ Assert.assertFalse(RealWorldHelper.isImagePresentOnPage(selenium, imageName));
+ }
+
+ @Test
+ public void testDeleteAlbum() {
+ renderPage();
+ RealWorldHelper.login(selenium);
+ selenium.click(HtmlConstants.ToolBarArea.VIEW_ALBUMS_PATH);
+ waitForAjaxCompletion();
+ String albumName = selenium.getText(HtmlConstants.AlbumArea.PREVIEW_PATH +
HtmlConstants.AlbumArea.PREVIEW_NAME_PATH_SUFFIX);
+ RealWorldHelper.openAlbumFromPreview(selenium);
+ RealWorldHelper.deleteCurrentAlbum(selenium);
+ selenium.click(HtmlConstants.ToolBarArea.VIEW_ALBUMS_PATH);
+ waitForAjaxCompletion();
+ Assert.assertFalse(RealWorldHelper.isAlbumPresentOnPage(selenium, albumName));
+ }
+
+ //TODO @Test
+ public void testDeleteShelf() {
+ renderPage();
+ RealWorldHelper.login(selenium);
+ selenium.click(HtmlConstants.ToolBarArea.VIEW_ALBUMS_PATH);
+ waitForAjaxCompletion();
+ String albumName = selenium.getText(HtmlConstants.AlbumArea.PREVIEW_PATH +
HtmlConstants.AlbumArea.PREVIEW_NAME_PATH_SUFFIX);
+ RealWorldHelper.openAlbumFromPreview(selenium);
+ RealWorldHelper.deleteCurrentAlbum(selenium);
+ selenium.click(HtmlConstants.ToolBarArea.VIEW_ALBUMS_PATH);
+ waitForAjaxCompletion();
+ Assert.assertFalse(RealWorldHelper.isAlbumPresentOnPage(selenium, albumName));
+ }
}