1 /** 2 * Copyright 2005-2015 The Kuali Foundation 3 * 4 * Licensed under the Educational Community License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.opensource.org/licenses/ecl2.php 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package org.kuali.rice.testtools.selenium; 17 18 import org.junit.runner.RunWith; 19 20 /** 21 * <p> 22 * Automated Functional Tests should extend this Base class or have it in their class hierarchy, enables 23 * bookmark mode for test methods ending in Bookmark and navigation mode for test methods ending in Nav. 24 * </p><p> 25 * The abstract method getBookmarkUrl should be implemented to return the Bookmark URL 26 * of the page under test. The abstract method navigate should be implemented to Navigate 27 * through the UI to the page under test. {@see #navigateInternal} should be called from a setUp. 28 * </p><p> 29 * Runs With {@see AutomatedFunctionalTestRunner}. 30 * </p> 31 * @author Kuali Rice Team (rice.collab@kuali.org) 32 */ 33 @RunWith(AutomatedFunctionalTestRunner.class) 34 public abstract class AutomatedFunctionalTestBase { 35 36 /** 37 * testUrl set by {@see #enableBookmarkMode} and {@see #enableNavigationMode}, if there are test methods that 38 * do not end with Bookmark or Nav then testUrl must be defined in the test. 39 */ 40 protected String testUrl; 41 42 /** 43 * Set to true by {@see #enableNavigationMode} and false by {@see #enableBookmarkMode}. 44 */ 45 protected boolean shouldNavigate = false; 46 47 /** 48 * Called by {see #enableBookmarkMode}. 49 * 50 * @return Bookmark url where test will start. 51 */ 52 protected abstract String getBookmarkUrl(); 53 54 /** 55 * Called by {see #enableBookmarkMode}. 56 * 57 * @return Navigation url where test will start navigating from. 58 */ 59 protected abstract String getNavigationUrl(); 60 61 /** 62 * Called by {@see #navigateInternal}, should navigate from the testUrl. 63 * 64 * @throws Exception 65 */ 66 protected abstract void navigate() throws Exception; 67 68 /** 69 * Called by {@see AutomatedFunctionalTestRunner#methodInvoker} if test method ends with Bookmark. 70 */ 71 protected void enableBookmarkMode() { 72 this.shouldNavigate = false; 73 this.testUrl = getBookmarkUrl(); 74 } 75 76 /** 77 * Called by {@see AutomatedFunctionalTestRunner#methodInvoker} if test method ends with Nav. 78 */ 79 protected void enableNavigationMode() { 80 this.shouldNavigate = true; 81 this.testUrl = getNavigationUrl(); 82 } 83 84 /** 85 * @return testUrl 86 */ 87 protected String getTestUrl() { 88 return testUrl; 89 } 90 91 /** 92 * Calls {@see #navigate} if {@see #shouldNavigate} is true. 93 * 94 * @throws Exception 95 */ 96 protected void navigateInternal() throws Exception { 97 if (this.shouldNavigate) { 98 navigate(); 99 } 100 } 101 }