From bdf70b78470f5ecea832d10ec39b11a5bc408168 Mon Sep 17 00:00:00 2001 From: Sean Flanigan Date: Thu, 15 Jan 2015 10:35:03 +1000 Subject: [PATCH] Look for chromedriver on the system PATH too Squashed commit of the following: commit cf1c1ecd2e05cb8641c253d9a61558e5ae02fedd Author: Sean Flanigan Date: Tue Jan 13 16:56:33 2015 +1000 Add suggestions from djansen commit be3e8a4645b9ae38e7cd47e8e37560a9bc6c67f7 Author: Sean Flanigan Date: Fri Dec 19 15:13:58 2014 +1000 Look for chromedriver on the system PATH too --- .../org/zanata/page/WebDriverFactory.java | 40 ++++++++++++++++++- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/functional-test/src/main/java/org/zanata/page/WebDriverFactory.java b/functional-test/src/main/java/org/zanata/page/WebDriverFactory.java index c8c333f255..f237312da8 100644 --- a/functional-test/src/main/java/org/zanata/page/WebDriverFactory.java +++ b/functional-test/src/main/java/org/zanata/page/WebDriverFactory.java @@ -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; @@ -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 @@ -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 @@ -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