public FirefoxBinary(File pathToFirefoxBinary) { executable = new Executable(pathToFirefoxBinary); }
protected File getFile() { return executable.getFile(); }
@Override public String toString() { return "FirefoxBinary(" + executable.getPath() + ")"; }
private void loadApplicationIni() { Path applicationIni = getResource("application.ini"); if (Files.exists(applicationIni)) { try (BufferedReader reader = Files.newBufferedReader(applicationIni)) { version = reader.lines() .map(String::trim) .filter(line -> line.startsWith("Version=")) .findFirst() .map(line -> line.substring("Version=".length())) .orElseThrow(() -> new WebDriverException("Cannot get version info for Firefox binary " + binary)); } catch (IOException e) { throw new WebDriverException("Cannot get version info for Firefox binary " + binary, e); } } else { // Set version to something with a ridiculously high number. version = "1000.0 unknown"; } }
public FirefoxBinary.Channel getChannel() { if (channel == null) { loadChannelPref(); } return channel; }
public String getVersion() { if (version == null) { loadApplicationIni(); } return version; }
public FirefoxBinary(Channel channel) { Executable systemBinary = locateFirefoxBinaryFromSystemProperty(); if (systemBinary != null) { if (systemBinary.getChannel() == channel) { executable = systemBinary; return; } else { throw new WebDriverException( "Firefox executable specified by system property " + FirefoxDriver.SystemProperty.BROWSER_BINARY + " does not belong to channel '" + channel + "', it appears to be '" + systemBinary.getChannel() + "'"); } } executable = locateFirefoxBinariesFromPlatform() .filter(e -> e.getChannel() == channel) .findFirst().orElseThrow(() -> new WebDriverException( String.format("Cannot find firefox binary for channel '%s' in PATH", channel))); }
private void loadChannelPref() { Path channelPrefs = getResource("defaults/pref/channel-prefs.js"); if (Files.exists(channelPrefs)) { try (BufferedReader reader = Files.newBufferedReader(channelPrefs)) { channel = reader.lines() .map(String::trim) .filter(line -> line.startsWith("pref(\"app.update.channel\"")) .findFirst() .map(line -> FirefoxBinary.Channel.fromString( line.substring("pref(\"app.update.channel\", \"".length(), line.length() - "\");".length()))) .orElseThrow(() -> new WebDriverException("Cannot get channel info for Firefox binary " + binary)); } catch (IOException e) { throw new WebDriverException("Cannot get channel info for Firefox binary " + binary, e); } } else { // Pick a sane default channel = FirefoxBinary.Channel.RELEASE; } }
public String toJson() { return executable.getPath(); }
/** * Locates the firefox binary from a system property. Will throw an exception if the binary cannot * be found. */ private static Executable locateFirefoxBinaryFromSystemProperty() { String binaryName = System.getProperty(FirefoxDriver.SystemProperty.BROWSER_BINARY); if (binaryName == null) return null; File binary = new File(binaryName); if (binary.exists() && !binary.isDirectory()) return new Executable(binary); Platform current = Platform.getCurrent(); if (current.is(WINDOWS)) { if (!binaryName.endsWith(".exe")) { binaryName += ".exe"; } } else if (current.is(MAC)) { if (!binaryName.endsWith(".app")) { binaryName += ".app"; } binaryName += "/Contents/MacOS/firefox-bin"; } binary = new File(binaryName); if (binary.exists()) return new Executable(binary); throw new WebDriverException( String.format("'%s' property set, but unable to locate the requested binary: %s", FirefoxDriver.SystemProperty.BROWSER_BINARY, binaryName)); }
protected String getPath() { return executable.getPath(); }
executables.add(new Executable(binary)); executables.add(new Executable(binary)); String systemFirefoxBin = new ExecutableFinder().find("firefox-bin"); if (systemFirefoxBin != null) { executables.add(new Executable(new File(systemFirefoxBin))); File attempt1 = realPath.getParent().resolve("firefox").toFile(); if (attempt1.exists()) { executables.add(new Executable(attempt1)); } else { File attempt2 = realPath.getParent().resolve("firefox-bin").toFile(); if (attempt2.exists()) { executables.add(new Executable(attempt2)); executables.add(new Executable(new File(systemFirefox)));