Author: andrei_exadel
Date: 2009-03-12 10:15:48 -0400 (Thu, 12 Mar 2009)
New Revision: 12934
Added:
trunk/test-applications/realworld2/tests/src/test/java/org/richfaces/realworld/RealWorldHelper.java
trunk/test-applications/realworld2/tests/src/test/java/org/richfaces/realworld/testng/ShelfsImagesUseCasesTest.java
Modified:
trunk/test-applications/realworld2/tests/
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:
Test refactoring; Add test for album opening
Property changes on: trunk/test-applications/realworld2/tests
___________________________________________________________________
Name: svn:ignore
+ target
test-output
Added:
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
(rev 0)
+++
trunk/test-applications/realworld2/tests/src/test/java/org/richfaces/realworld/RealWorldHelper.java 2009-03-12
14:15:48 UTC (rev 12934)
@@ -0,0 +1,90 @@
+/**
+ *
+ */
+package org.richfaces.realworld;
+
+import org.testng.Assert;
+
+import com.thoughtworks.selenium.DefaultSelenium;
+
+/**
+ * @author Andrey Markavtsov
+ *
+ */
+public class RealWorldHelper {
+
+
+ public static interface HtmlConstants {
+ 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_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 AlbumArea {
+ String ALBUM_HEADER_NAME =
"//table[@class='album-header-table']/tbody/tr/td/h1";
+ String IMAGES_CONTAINER = "//span[@id='mainform:userAlbumImages']";
+ }
+
+ public static interface TreeArea {
+
+ }
+ };
+
+
+ public static void Login(DefaultSelenium selenium) {
+ selenium.click("id=" + HtmlConstants.LoginPage.loginLinkId);
+ 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");
+
+ String type =
selenium.getAttribute("//*[@id='"+HtmlConstants.LoginPage.passwordId+"']/(a)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.click(HtmlConstants.LoginPage.loginButtonPath);
+ selenium.waitForPageToLoad("10000");
+
+ String loggedText = selenium.getText(HtmlConstants.IndexPage.loggedUserPath);
+ if (!loggedText.contains(HtmlConstants.LoginPage.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 AssertVisible(DefaultSelenium selenium, String id, String message) {
+ Assert.assertTrue(selenium.isVisible("id=" + id), message);
+ }
+
+ 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));
+ }
+
+}
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-03-12
14:02:55 UTC (rev 12933)
+++
trunk/test-applications/realworld2/tests/src/test/java/org/richfaces/realworld/SeleniumTestBase.java 2009-03-12
14:15:48 UTC (rev 12934)
@@ -58,6 +58,8 @@
private Object[][] data;
private int seleniumServerPort = 5556;
+
+ static final String STATUS_STOP_ID = "_viewRoot:status.stop";
/** Defines the name of current j2ee application name */
public static final String APPLICATION_NAME = "realworld";
@@ -289,8 +291,7 @@
* time to wait
*/
public void waitForAjaxCompletion(int miliseconds) {
- selenium.waitForCondition(WINDOW_JS_RESOLVER + "done==true",
String.valueOf(miliseconds));
- runScript("window.done=false");
+ selenium.waitForCondition(WINDOW_JS_RESOLVER + "$('" +
STATUS_STOP_ID + "').style.display != 'none'",
String.valueOf(miliseconds));
}
/**
@@ -310,7 +311,8 @@
* time to wait
*/
public void waitForPageToLoad(int miliseconds) {
- selenium.waitForPageToLoad(String.valueOf(miliseconds));
+ //selenium.waitForPageToLoad(String.valueOf(miliseconds));
+
}
/**
@@ -845,7 +847,9 @@
*
* @return
*/
- public abstract String getTestUrl();
+ public String getTestUrl() {
+ return "/index.seam";
+ }
/**
* Simulates mouse event for element
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-03-12
14:02:55 UTC (rev 12933)
+++
trunk/test-applications/realworld2/tests/src/test/java/org/richfaces/realworld/testng/LoginTest.java 2009-03-12
14:15:48 UTC (rev 12934)
@@ -3,8 +3,8 @@
*/
package org.richfaces.realworld.testng;
+import org.richfaces.realworld.RealWorldHelper;
import org.richfaces.realworld.SeleniumTestBase;
-import org.testng.Assert;
import org.testng.annotations.Test;
/**
@@ -13,61 +13,12 @@
*/
public class LoginTest extends SeleniumTestBase {
- static final String usernameId = "loginPanelForm:username";
- static final String passwordId = "loginPanelForm:password";
- static final String loginButtonPath=
"//td[@class='login-table-col']/input[1]";
- static final String loggedUserPath = "//a[@class='logged-user']";
- static final String loginLinkId = "j_id27:loginPanelShowlink";
- static final String shelfCountPath =
"//table[@id='menuform:menu']/tbody/tr/td[2]";
-
- static final int SHELF_COUNT = 2;
-
- static final String LOGIN_NAME = "amarkhel";
- static final String LOGIN_PASSWORD = "12345";
-
+
@Test
public void testAuthentication() {
renderPage();
- selenium.click("id=" + loginLinkId);
- try {
- Thread.sleep(5000);
- }catch (Exception e) {
- Assert.fail("Test failed caused by: " + e);
- }
+ RealWorldHelper.Login(selenium);
- AssertVisible(usernameId, "Input for username in not visible");
- AssertVisible(passwordId, "Input for password in not visible");
-
- String type =
selenium.getAttribute("//*[@id='"+passwordId+"']/@type");
- if (!"password".equals(type)) {
- Assert.fail("Password input should be of 'password' type");
- }
-
- setValueById(usernameId, LOGIN_NAME);
- setValueById(passwordId, LOGIN_PASSWORD);
-
- selenium.click(loginButtonPath);
- waitForPageToLoad();
-
- String loggedText = selenium.getText(loggedUserPath);
- if (!loggedText.contains(LOGIN_NAME)) {
- Assert.fail("Authentication was not succesfull. Logged user text should contain
typed login name");
- }
-
- String shelfCount = selenium.getText(shelfCountPath);
- if (!String.valueOf(SHELF_COUNT).equals(shelfCount)) {
- Assert.fail("Shelf count for user [" + LOGIN_NAME + "] should be "
+ SHELF_COUNT + ".But was " + shelfCount);
- }
-
}
-
- /* (non-Javadoc)
- * @see org.richfaces.realworld.SeleniumTestBase#getTestUrl()
- */
- @Override
- public String getTestUrl() {
- return "/index.seam";
- }
-
}
Added:
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
(rev 0)
+++
trunk/test-applications/realworld2/tests/src/test/java/org/richfaces/realworld/testng/ShelfsImagesUseCasesTest.java 2009-03-12
14:15:48 UTC (rev 12934)
@@ -0,0 +1,33 @@
+/**
+ *
+ */
+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.");
+
+ }
+}
Show replies by date