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
017 package edu.samplu.common;
018
019 import org.junit.rules.TestName;
020 import org.openqa.selenium.WebDriver;
021 import org.openqa.selenium.chrome.ChromeDriverService;
022
023 import java.io.File;
024 import java.util.concurrent.TimeUnit;
025
026 /**
027 * @author Kuali Rice Team (rice.collab@kuali.org)
028 */
029
030 public class WebDriverUtil {
031
032 public static int DEFAULT_IMPLICIT_WAIT_TIME = 30;
033 public static int SHORT_IMPLICIT_WAIT_TIME = 1;
034
035 /**
036 *
037 * @param username
038 * @param url
039 * @return
040 * @throws Exception
041 */
042 public static WebDriver setUp(String username, String url) throws Exception {
043 return setUp(username, url, null, null);
044 }
045
046 /**
047 * Setup the WebDriver test, login and load the tested web page
048 *
049 * @throws Exception
050 */
051 public static WebDriver setUp(String username, String url, String className, TestName testName) throws Exception {
052 WebDriver driver = null;
053 if (System.getProperty("remote.driver.saucelabs") == null) {
054 driver = ITUtil.getWebDriver();
055 // } else {
056 // SauceLabsWebDriverHelper saucelabs = new SauceLabsWebDriverHelper();
057 // saucelabs.setUp(className, testName);
058 // driver = saucelabs.getDriver();
059 }
060 driver.manage().timeouts().implicitlyWait(120, TimeUnit.SECONDS);
061 driver.get(url);
062 ITUtil.login(driver, username);
063 driver.manage().timeouts().implicitlyWait(DEFAULT_IMPLICIT_WAIT_TIME, TimeUnit.SECONDS);
064 return driver;
065 }
066
067 public static void checkForIncidentReport(WebDriver driver, String locator) {
068 checkForIncidentReport(driver, locator, "");
069 }
070
071 public static void checkForIncidentReport(WebDriver driver, String locator, String message) {
072 ITUtil.checkForIncidentReport(driver.getPageSource(), locator, message);
073 }
074
075 public static ChromeDriverService createAndStartService() {
076 String driverParam = System.getProperty("remote.public.driver");
077 if (driverParam != null && "chrome".equals(driverParam.toLowerCase())) {
078 if (System.getProperty("webdriver.chrome.driver") == null) {
079 if (System.getProperty("remote.public.chrome") != null) {
080 System.setProperty("webdriver.chrome.driver", System.getProperty("remote.public.chrome"));
081 }
082 }
083 ChromeDriverService chromeDriverService = new ChromeDriverService.Builder()
084 .usingChromeDriverExecutable(new File(System.getProperty("remote.public.chrome")))
085 .usingAnyFreePort()
086 .build();
087 return chromeDriverService;
088 }
089 return null;
090 }
091 }