aboutsummaryrefslogtreecommitdiff
path: root/src/batchtools/webdrivers
diff options
context:
space:
mode:
authorGravatar Rogan Creswick <creswick@gmail.com>2013-06-07 16:00:22 -0700
committerGravatar Rogan Creswick <creswick@gmail.com>2013-06-07 16:00:22 -0700
commit88c95d18a81e4f107cc4e5967bfa45d1bf4882a1 (patch)
treef1b8f5bb1bffd8ea84078d829248dddbdc2f3544 /src/batchtools/webdrivers
parent04d3c6e96ed4dd528418fe71a85e72316ae5bba4 (diff)
cleaned up some test files that broke during a merge
Diffstat (limited to 'src/batchtools/webdrivers')
-rw-r--r--src/batchtools/webdrivers/.classpath36
-rw-r--r--src/batchtools/webdrivers/.gitignore1
-rw-r--r--src/batchtools/webdrivers/.settings/org.eclipse.jdt.core.prefs5
-rw-r--r--src/batchtools/webdrivers/.settings/org.eclipse.m2e.core.prefs4
-rw-r--r--src/batchtools/webdrivers/pom.xml43
-rw-r--r--src/batchtools/webdrivers/src/main/java/com/galois/fiveui/drivers/Drivers.java149
6 files changed, 238 insertions, 0 deletions
diff --git a/src/batchtools/webdrivers/.classpath b/src/batchtools/webdrivers/.classpath
new file mode 100644
index 0000000..75e85b7
--- /dev/null
+++ b/src/batchtools/webdrivers/.classpath
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" output="target/classes" path="src/main/java">
+ <attributes>
+ <attribute name="optional" value="true"/>
+ <attribute name="maven.pomderived" value="true"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="src" output="target/test-classes" path="src/test/java">
+ <attributes>
+ <attribute name="optional" value="true"/>
+ <attribute name="maven.pomderived" value="true"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
+ <attributes>
+ <attribute name="maven.pomderived" value="true"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
+ <attributes>
+ <attribute name="maven.pomderived" value="true"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5">
+ <attributes>
+ <attribute name="maven.pomderived" value="true"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
+ <attributes>
+ <attribute name="maven.pomderived" value="true"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="output" path="target/classes"/>
+</classpath>
diff --git a/src/batchtools/webdrivers/.gitignore b/src/batchtools/webdrivers/.gitignore
new file mode 100644
index 0000000..eb5a316
--- /dev/null
+++ b/src/batchtools/webdrivers/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/src/batchtools/webdrivers/.settings/org.eclipse.jdt.core.prefs b/src/batchtools/webdrivers/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..abec6ca
--- /dev/null
+++ b/src/batchtools/webdrivers/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,5 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
+org.eclipse.jdt.core.compiler.source=1.5
diff --git a/src/batchtools/webdrivers/.settings/org.eclipse.m2e.core.prefs b/src/batchtools/webdrivers/.settings/org.eclipse.m2e.core.prefs
new file mode 100644
index 0000000..f897a7f
--- /dev/null
+++ b/src/batchtools/webdrivers/.settings/org.eclipse.m2e.core.prefs
@@ -0,0 +1,4 @@
+activeProfiles=
+eclipse.preferences.version=1
+resolveWorkspaceProjects=true
+version=1
diff --git a/src/batchtools/webdrivers/pom.xml b/src/batchtools/webdrivers/pom.xml
new file mode 100644
index 0000000..4d8847f
--- /dev/null
+++ b/src/batchtools/webdrivers/pom.xml
@@ -0,0 +1,43 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>com.galois.fiveui</groupId>
+ <artifactId>webdrivers</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <name>Web Drivers</name>
+ <description>Wrapper around Selenium Web Driver creation to handle configuration details that we wish to be uniform across all FiveUI applications.</description>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.3.2</version>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.9</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.seleniumhq.selenium</groupId>
+ <artifactId>selenium-java</artifactId>
+ <version>2.25.0</version>
+ </dependency>
+
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ <version>10.0.1</version>
+ </dependency>
+ </dependencies>
+</project>
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
new file mode 100644
index 0000000..db73fec
--- /dev/null
+++ b/src/batchtools/webdrivers/src/main/java/com/galois/fiveui/drivers/Drivers.java
@@ -0,0 +1,149 @@
+/**
+ * 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
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.galois.fiveui.drivers;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.openqa.selenium.chrome.ChromeDriver;
+import org.openqa.selenium.chrome.ChromeOptions;
+import org.openqa.selenium.firefox.FirefoxBinary;
+import org.openqa.selenium.firefox.FirefoxDriver;
+import org.openqa.selenium.firefox.FirefoxProfile;
+
+/**
+ * @author creswick
+ *
+ */
+public class Drivers {
+ private static final String FIREFOX_BIN_PATH = "FIREFOX_BIN_PATH";
+ private static final String CHROME_BIN_PATH = "CHROME_BIN_PATH";
+
+ 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 final String firefoxExtensionPath = "binaries/fiveui.xpi";
+ private static final String chromeExtensionPath = "binaries/fiveui.crx";
+
+ /**
+ * 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;
+ }
+
+ public static FirefoxDriver buildFFDriver() {
+ // Extracted into a method so we can set up profiles
+
+ String rootPath = getRootPath();
+
+ File profileDir = new File(rootPath+firefoxProfilePath);
+ FirefoxProfile profile = new FirefoxProfile(profileDir);
+
+ File fiveuiXpi = new File(rootPath+firefoxExtensionPath);
+ try {
+ profile.addExtension(fiveuiXpi);
+ } catch (IOException e) {
+ System.err.println("could not load firefox with FiveUI");
+ e.printStackTrace();
+ }
+
+ String ffBinaryPath = System.getProperty(FIREFOX_BIN_PATH);
+
+ FirefoxDriver driver;
+ if (null == ffBinaryPath) {
+ System.err
+ .println("WARNING: Running essentially random version of FireFox!");
+ System.err.println(" set a path to firefox with -D"
+ + FIREFOX_BIN_PATH + "=<path to firefox>");
+ driver = new FirefoxDriver(profile);
+ } else {
+ FirefoxBinary binary = new FirefoxBinary(new File(ffBinaryPath));
+ driver = new FirefoxDriver(binary, profile);
+ }
+
+ return driver;
+ }
+
+ public static ChromeDriver buildChromeDriver() {
+
+ String rootPath = getRootPath();
+
+ // set the chrome driver path:
+ String chromeDriverPth =
+ mkPath(CD_BASE_PATH, osNameArch(), CD_BINARY_NAME);
+ System.setProperty("webdriver.chrome.driver", chromeDriverPth);
+
+ // setting the path to chrome also seems to cause issues:
+ ChromeOptions options = new ChromeOptions();
+ options.addArguments("--user-data-dir=" + rootPath + chromeProfilePath); // ,
+ // "--enable-logging",
+ // "--v=1");
+ options.addExtensions(new File(rootPath + chromeExtensionPath));
+
+ String chromeBinaryPath = System.getProperty(CHROME_BIN_PATH);
+ if (null == chromeBinaryPath) {
+ System.err
+ .println("WARNING: Running essentially random version of Chrome!");
+ System.err.println(" set a path to Chrome with -D"
+ + CHROME_BIN_PATH + "=<path to chrome>");
+ } else {
+ options.setBinary(new File(chromeBinaryPath));
+ }
+ // For use with ChromeDriver:
+ return new ChromeDriver(options);
+ }
+
+ private static String mkPath(String... components) {
+ StringBuilder path = new StringBuilder();
+ int remaining = components.length;
+ for (String c : components) {
+ path.append(c);
+ remaining--;
+ if (remaining != 0) {
+ path.append(File.separator);
+ }
+ }
+
+ return path.toString();
+ }
+
+ /**
+ * 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() {
+ String rawOsName = System.getProperty("os.name").toLowerCase();
+ String osName = rawOsName.substring(0, 3);
+ boolean is64bit = System.getProperty("os.arch").indexOf("64") >= 0;
+
+ if (osName.equals("lin")) {
+ osName += is64bit ? "64" : "32";
+ }
+ return osName;
+ }
+
+}