001: /***************************************************************
002: * This file is part of the [fleXive](R) project.
003: *
004: * Copyright (c) 1999-2008
005: * UCS - unique computing solutions gmbh (http://www.ucs.at)
006: * All rights reserved
007: *
008: * The [fleXive](R) project is free software; you can redistribute
009: * it and/or modify it under the terms of the GNU General Public
010: * License as published by the Free Software Foundation;
011: * either version 2 of the License, or (at your option) any
012: * later version.
013: *
014: * The GNU General Public License can be found at
015: * http://www.gnu.org/copyleft/gpl.html.
016: * A copy is found in the textfile GPL.txt and important notices to the
017: * license from the author are found in LICENSE.txt distributed with
018: * these libraries.
019: *
020: * This library is distributed in the hope that it will be useful,
021: * but WITHOUT ANY WARRANTY; without even the implied warranty of
022: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
023: * GNU General Public License for more details.
024: *
025: * For further information about UCS - unique computing solutions gmbh,
026: * please see the company website: http://www.ucs.at
027: *
028: * For further information about [fleXive](R), please see the
029: * project website: http://www.flexive.org
030: *
031: *
032: * This copyright notice MUST APPEAR in all copies of the file!
033: ***************************************************************/package com.flexive.tests.browser;
034:
035: import org.testng.annotations.AfterClass;
036: import org.testng.annotations.BeforeClass;
037:
038: /**
039: * Base class for backend browser tests.
040: * Context menu support needs a patched server as described at http://forums.openqa.org/thread.jspa?messageID=20582.
041: *
042: * @author Daniel Lichtenberger (daniel.lichtenberger@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at)
043: * @version $Rev: 229 $
044: */
045: public abstract class AbstractBackendBrowserTest extends
046: AbstractSeleniumTest {
047: protected static final String WND = "selenium.browserbot.getCurrentWindow()";
048: private static final String CONTEXTPATH = "/flexive";
049:
050: /**
051: * All IFrames available in the backend administration.
052: */
053: protected enum Frame {
054: Content("contentFrame"), Top("relative=top"), NavContent(
055: "treeNavFrame_0"), NavStructures("treeNavFrame_1"), NavSearch(
056: "treeNavFrame_2"), NavAdministration("treeNavFrame_3");
057:
058: private String name;
059:
060: private Frame(String name) {
061: this .name = name;
062: }
063:
064: public String getName() {
065: return name;
066: }
067: }
068:
069: /**
070: * The available navigation tabs of the main navigation frame.
071: */
072: protected enum NavigationTab {
073: // the order of the navigation tabs must match the actual layout
074: // since the position determines the ID
075:
076: Content(Frame.NavContent), Structure(Frame.NavStructures), Search(
077: Frame.NavSearch), Administration(
078: Frame.NavAdministration);
079:
080: private Frame frame;
081:
082: NavigationTab(Frame frame) {
083: this .frame = frame;
084: }
085: }
086:
087: public AbstractBackendBrowserTest() {
088: super (null, "browser.properties");
089: }
090:
091: @Override
092: @BeforeClass
093: public void beforeClass() {
094: super .beforeClass();
095: }
096:
097: @Override
098: @AfterClass
099: public void afterClass() {
100: super .afterClass();
101: }
102:
103: protected void login(String userName, String password) {
104: selenium.open(CONTEXTPATH + "/adm/pub/login.jsf");
105: selenium.type("loginForm:username", userName);
106: selenium.type("loginForm:password", password);
107: selenium.click("loginForm:takeOver");
108: selenium.click("loginForm:loginImage");
109: // wait for the loading screen to disappear
110: selenium
111: .waitForCondition(
112: WND
113: + ".document.getElementById('loading') != null "
114: + "&& "
115: + WND
116: + ".document.getElementById('loading').style.display == 'none'",
117: "120000");
118: }
119:
120: protected void loginSupervisor() {
121: login("supervisor", "supervisor");
122: }
123:
124: protected void logout() {
125: selectFrame(Frame.Top);
126: selenium.click("searchForm:logoutImage");
127: selectFrame(Frame.Content);
128: selenium.waitForPageToLoad("30000");
129: selenium.click("frm:logoutButton");
130: selenium.waitForPageToLoad("30000");
131: }
132:
133: protected void navigateTo(NavigationTab tab) {
134: selectFrame(Frame.Top);
135: final String result = selenium.getEval(WND + ".gotoNavMenu("
136: + tab.ordinal() + ")");
137: selectFrame(tab.frame);
138: if ("false".equals(result)) {
139: // frame not loaded yet, wait for loading to complete
140: selenium.waitForPageToLoad("30000");
141: }
142: }
143:
144: protected void selectFrame(Frame frame) {
145: if (frame != Frame.Top) {
146: selectFrame(Frame.Top); // select top frame first
147: }
148: selenium.selectFrame(frame.getName());
149: }
150:
151: protected void loadContentPage(String url) {
152: selectFrame(Frame.Content);
153: selenium.open(CONTEXTPATH
154: + (url.startsWith("/") ? url : "/" + url));
155: selenium.waitForPageToLoad("30000");
156: }
157: }
|