Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Look for chromedriver on the system PATH too
Browse files Browse the repository at this point in the history
Squashed commit of the following:

commit cf1c1ec
Author: Sean Flanigan <sflaniga@redhat.com>
Date:   Tue Jan 13 16:56:33 2015 +1000

    Add suggestions from djansen

commit be3e8a4
Author: Sean Flanigan <sflaniga@redhat.com>
Date:   Fri Dec 19 15:13:58 2014 +1000

    Look for chromedriver on the system PATH too
  • Loading branch information
seanf committed Jan 15, 2015
1 parent 5a031ca commit bdf70b7
Showing 1 changed file with 38 additions and 2 deletions.
Expand Up @@ -29,6 +29,7 @@
import org.openqa.selenium.firefox.FirefoxBinary;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.os.CommandLine;
import org.openqa.selenium.remote.Augmenter;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
Expand Down Expand Up @@ -107,11 +108,19 @@ private WebDriver createPlainDriver() {
}

private WebDriver configureChromeDriver() {
// TODO can we use this? it will use less code, but it will use DISPLAY rather than webdriver.display
// System.setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY,
// getChromeDriver().getAbsolutePath()));
// System.setProperty(ChromeDriverService.CHROME_DRIVER_LOG_PROPERTY,
// PropertiesHolder.getProperty("webdriver.log"));
// driverService = ChromeDriverService.createDefaultService();

@SuppressWarnings("deprecation")
File chromeDriver = getChromeDriver();
driverService =
new ChromeDriverService.Builder()
.usingDriverExecutable(
new File(PropertiesHolder.properties
.getProperty("webdriver.chrome.driver")))
chromeDriver)
.usingAnyFreePort()
.withEnvironment(
ImmutableMap
Expand All @@ -121,6 +130,7 @@ private WebDriver configureChromeDriver() {
.withLogFile(
new File(PropertiesHolder.properties
.getProperty("webdriver.log"))).build();

DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities
.setCapability("chrome.binary", PropertiesHolder.properties
Expand All @@ -136,6 +146,32 @@ private WebDriver configureChromeDriver() {
capabilities)));
}

/**
* Returns a File pointing to a chromedriver binary, searching the PATH
* if necessary. If the property 'webdriver.chrome.driver' points to an
* executable, uses that. Otherwise, searches PATH for the specified
* executable. Searches for 'chromedriver' if the property is null or
* empty.
* @return a File pointing to the executable
* @deprecated use ChromeDriverService.createDefaultService() if you can
*/
@Deprecated
private File getChromeDriver() {
String exeName = PropertiesHolder.getProperty("webdriver.chrome.driver");
if (exeName == null || exeName.isEmpty()) {
exeName = CommandLine.find("chromedriver");
} else if (!new File(exeName).canExecute()) {
exeName = CommandLine.find(exeName);
}
if (exeName == null) {
throw new RuntimeException("Please ensure chromedriver is on " +
"your system PATH or specified by the property " +
"'webdriver.chrome.driver'. Get it here: " +
"http://chromedriver.storage.googleapis.com/index.html");
}
return new File(exeName);
}

private WebDriver configureFirefoxDriver() {
final String pathToFirefox =
Strings.emptyToNull(PropertiesHolder.properties
Expand Down

0 comments on commit bdf70b7

Please sign in to comment.