001 /* 002 * Copyright 2006-2012 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 */ 016 package edu.samplu.common; 017 018 import com.thoughtworks.selenium.Selenium; 019 import junit.framework.Assert; 020 import org.junit.After; 021 import org.junit.Before; 022 import org.openqa.selenium.WebDriver; 023 import org.openqa.selenium.WebDriverBackedSelenium; 024 import org.openqa.selenium.firefox.FirefoxDriver; 025 026 import static junit.framework.Assert.fail; 027 028 /** 029 * @deprecated Use WebDriverITBase for new tests. 030 * @author Kuali Rice Team (rice.collab@kuali.org) 031 */ 032 public abstract class UpgradedSeleniumITBase { 033 public final static String PORTAL = "/portal.do"; 034 protected Selenium selenium; 035 protected WebDriver driver; 036 037 /** 038 * Returns the URL to be used with this test 039 * 040 * @return URL of the test 041 */ 042 public abstract String getTestUrl(); 043 044 @Before 045 public void setUp() throws Exception { 046 driver = new FirefoxDriver(); 047 if (!getTestUrl().startsWith("/")) { 048 fail("getTestUrl does not start with /"); // TODO add it? 049 } 050 selenium = new WebDriverBackedSelenium(driver, getBaseUrlString() + getTestUrl()); 051 052 // Login 053 selenium.open(getBaseUrlString() + getTestUrl()); 054 login(selenium); 055 } 056 057 public static String getBaseUrlString() { 058 String baseUrl = System.getProperty("remote.public.url"); 059 if (baseUrl == null) { 060 baseUrl = "http://localhost:8080"; 061 } else if (baseUrl.endsWith("/")) { 062 baseUrl = baseUrl.substring(0, baseUrl.length() - 1); 063 } else if (!baseUrl.startsWith("http")) { 064 baseUrl = "http://" + baseUrl; 065 } 066 return baseUrl; 067 } 068 069 public static void login(Selenium selenium) { 070 if (System.getProperty("remote.autologin") == null) { 071 Assert.assertEquals("Login", selenium.getTitle()); 072 selenium.type("__login_user", "admin"); 073 selenium.click("//input[@value='Login']"); 074 selenium.waitForPageToLoad("30000"); 075 } 076 } 077 078 /** 079 * Useful to set -Dremote.driver.dontTearDown=f -Dremote.driver.dontTearDown=n to not shutdown the browser when 080 * working on tests. 081 * @throws Exception 082 */ 083 @After 084 public void tearDown() throws Exception { 085 if (System.getProperty("remote.driver.dontTearDown") == null || 086 "f".startsWith(System.getProperty("remote.driver.dontTearDown").toLowerCase()) || 087 "n".startsWith(System.getProperty("remote.driver.dontTearDown").toLowerCase())) { 088 selenium.stop(); 089 driver.quit(); // TODO not tested with chrome, the service stop might need this check too 090 } 091 } 092 }