aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Benjamin Jones <bjones@galois.com>2013-07-05 15:42:49 -0700
committerGravatar Benjamin Jones <bjones@galois.com>2013-07-05 15:42:49 -0700
commit136075d19f72d5855def9a49e37ea885403155c5 (patch)
tree59da90ca74c08d1fa84aaa37b5cacb84a33a5c3e
parent0455574b16410cc0241e749071f7b242a65ba94e (diff)
if firefox profile given is null, create and use a temporary profile
-rw-r--r--src/batchtools/webdrivers/src/main/java/com/galois/fiveui/drivers/Drivers.java57
1 files changed, 36 insertions, 21 deletions
diff --git a/src/batchtools/webdrivers/src/main/java/com/galois/fiveui/drivers/Drivers.java b/src/batchtools/webdrivers/src/main/java/com/galois/fiveui/drivers/Drivers.java
index 8ac41d1..7e53d06 100644
--- a/src/batchtools/webdrivers/src/main/java/com/galois/fiveui/drivers/Drivers.java
+++ b/src/batchtools/webdrivers/src/main/java/com/galois/fiveui/drivers/Drivers.java
@@ -1,14 +1,14 @@
/**
* Module : Drivers.java Copyright : (c) 2011-2012, Galois, Inc.
- *
+ *
* Maintainer : Stability : Provisional Portability: Portable
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
@@ -19,6 +19,8 @@ package com.galois.fiveui.drivers;
import java.io.File;
import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
@@ -26,9 +28,11 @@ import org.openqa.selenium.firefox.FirefoxBinary;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
+import com.google.common.io.Files;
+
/**
* @author creswick
- *
+ *
*/
public class Drivers {
private static final String FIREFOX_BIN_PATH = "FIREFOX_BIN_PATH";
@@ -37,28 +41,39 @@ public class Drivers {
private static final String CD_BINARY_NAME = "chromedriver";
private static final String CD_BASE_PATH = mkPath("..", "tools",
"seleniumChromeDrivers");
-
+
private static final String FIVEUI_ROOT_PATH = "FIVEUI_ROOT_PATH";
private static final String defaultFiveuiRootPath = "../../../";
private static final String firefoxProfilePath = "profiles/firefox";
private static final String chromeProfilePath = "profiles/chrome";
+ private static List<File> tmpDirs = new ArrayList<File>();
+
/**
* Query the OS environment for the FiveUI root path, or return a default.
*/
public static String getRootPath() {
- String rootPath = System.getProperty(FIVEUI_ROOT_PATH);
- return (null != rootPath) ? rootPath + File.separator : defaultFiveuiRootPath;
+ String rootPath = System.getProperty(FIVEUI_ROOT_PATH);
+ return (null != rootPath) ? rootPath + File.separator : defaultFiveuiRootPath;
}
-
- public static FirefoxDriver buildFFDriver(String ffProfile) {
- // Extracted into a method so we can set up profiles
- String rootPath = getRootPath();
-
- File profileDir = new File(ffProfile);
+ /**
+ * Return a new Firefox webdriver.
+ * @param ffProfile Directory path for the desired Firefox profile to use. If
+ * null a temporary blank profile is used.
+ * @return
+ */
+ public static FirefoxDriver buildFFDriver(String ffProfile) {
+ File profileDir;
+ if (null == ffProfile) {
+ profileDir = Files.createTempDir();
+ profileDir.deleteOnExit();
+ } else {
+ profileDir = new File(ffProfile);
+ }
+ System.out.println("com.galois.fiveui.drivers: using directory for Firefox profile: " + profileDir);
FirefoxProfile profile = new FirefoxProfile(profileDir);
-
+
String ffBinaryPath = System.getProperty(FIREFOX_BIN_PATH);
@@ -78,10 +93,10 @@ public class Drivers {
}
public static ChromeDriver buildChromeDriver() {
-
- String rootPath = getRootPath();
-
- // set the chrome driver path:
+
+ String rootPath = getRootPath();
+
+ // set the chrome driver path:
String chromeDriverPth =
mkPath(CD_BASE_PATH, osNameArch(), CD_BINARY_NAME);
System.setProperty("webdriver.chrome.driver", chromeDriverPth);
@@ -122,7 +137,7 @@ public class Drivers {
/**
* Determine the name of the directory that the chromedriver is in, based on
* os.name and os.arch.
- *
+ *
* @return The name of the directory containing 'chromedriver'
*/
private static String osNameArch() {
@@ -135,5 +150,5 @@ public class Drivers {
}
return osName;
}
-
+
}