001/**
002 * Copyright 2005-2017 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.rice.testtools.selenium;
017
018import org.junit.runner.RunWith;
019
020/**
021 * <p>
022 * Automated Functional Tests should extend this Base class or have it in their class hierarchy, enables
023 * bookmark mode for test methods ending in Bookmark and navigation mode for test methods ending in Nav.
024 * </p><p>
025 * The abstract method getBookmarkUrl should be implemented to return the Bookmark URL
026 * of the page under test.  The abstract method navigate should be implemented to Navigate
027 * through the UI to the page under test.  {@see #navigateInternal} should be called from a setUp.
028 * </p><p>
029 * Runs With {@see AutomatedFunctionalTestRunner}.
030 * </p>
031 * @author Kuali Rice Team (rice.collab@kuali.org)
032 */
033@RunWith(AutomatedFunctionalTestRunner.class)
034public abstract class AutomatedFunctionalTestBase {
035
036    /**
037     * testUrl set by {@see #enableBookmarkMode} and {@see #enableNavigationMode}, if there are test methods that
038     * do not end with Bookmark or Nav then testUrl must be defined in the test.
039     */
040    protected String testUrl;
041
042    /**
043     * Set to true by {@see #enableNavigationMode} and false by {@see #enableBookmarkMode}.
044     */
045    protected boolean shouldNavigate = false;
046
047    /**
048     * Called by {see #enableBookmarkMode}.
049     *
050     * @return Bookmark url where test will start.
051     */
052    protected abstract String getBookmarkUrl();
053
054    /**
055     * Called by {see #enableBookmarkMode}.
056     *
057     * @return Navigation url where test will start navigating from.
058     */
059    protected abstract String getNavigationUrl();
060
061    /**
062     * Called by {@see #navigateInternal}, should navigate from the testUrl.
063     *
064     * @throws Exception
065     */
066    protected abstract void navigate() throws Exception;
067
068    /**
069     * Called by {@see AutomatedFunctionalTestRunner#methodInvoker} if test method ends with Bookmark.
070     */
071    protected void enableBookmarkMode() {
072        this.shouldNavigate = false;
073        this.testUrl = getBookmarkUrl();
074    }
075
076    /**
077     * Called by {@see AutomatedFunctionalTestRunner#methodInvoker} if test method ends with Nav.
078     */
079    protected void enableNavigationMode() {
080        this.shouldNavigate = true;
081        this.testUrl = getNavigationUrl();
082    }
083
084    /**
085     * @return testUrl
086     */
087    protected String getTestUrl() {
088        return testUrl;
089    }
090
091    /**
092     * Calls {@see #navigate} if {@see #shouldNavigate} is true.
093     *
094     * @throws Exception
095     */
096    protected void navigateInternal() throws Exception {
097        if (this.shouldNavigate) {
098            navigate();
099        }
100    }
101}