Example usage for org.openqa.selenium.os ExecutableFinder ExecutableFinder

List of usage examples for org.openqa.selenium.os ExecutableFinder ExecutableFinder

Introduction

In this page you can find the example usage for org.openqa.selenium.os ExecutableFinder ExecutableFinder.

Prototype

ExecutableFinder

Source Link

Usage

From source file:com.github.mike10004.seleniumhelp.UnitTests.java

License:Apache License

/**
 * Locates the firefox binary by platform.
 * <p>/*from  ww w  .jav a  2 s  . c  o m*/
 * Copied from Selenium's FirefoxBinary.java. See license above.
 */
@SuppressWarnings("deprecation")
private static Stream<Executable> locateFirefoxBinariesFromPlatform() {
    ImmutableList.Builder<Executable> executables = new ImmutableList.Builder<>();

    Platform current = Platform.getCurrent();
    if (current.is(WINDOWS)) {
        executables.addAll(Stream
                .of(getPathsInProgramFiles("Mozilla Firefox\\firefox.exe"),
                        getPathsInProgramFiles("Firefox Developer Edition\\firefox.exe"),
                        getPathsInProgramFiles("Nightly\\firefox.exe"))
                .flatMap(List::stream).map(File::new).filter(File::exists).map(Executable::new)
                .collect(toList()));

    } else if (current.is(MAC)) {
        // system
        File binary = new File("/Applications/Firefox.app/Contents/MacOS/firefox-bin");
        if (binary.exists()) {
            executables.add(new Executable(binary));
        }

        // user home
        binary = new File(System.getProperty("user.home") + binary.getAbsolutePath());
        if (binary.exists()) {
            executables.add(new Executable(binary));
        }

    } else if (current.is(UNIX)) {
        String systemFirefoxBin = new ExecutableFinder().find("firefox-bin");
        if (systemFirefoxBin != null) {
            executables.add(new Executable(new File(systemFirefoxBin)));
        }
    }

    String systemFirefox = new ExecutableFinder().find("firefox");
    if (systemFirefox != null) {
        Path firefoxPath = new File(systemFirefox).toPath();
        if (Files.isSymbolicLink(firefoxPath)) {
            try {
                Path realPath = firefoxPath.toRealPath();
                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));
                    }
                }
            } catch (IOException e) {
                // ignore this path
            }

        } else {
            executables.add(new Executable(new File(systemFirefox)));
        }
    }

    return executables.build().stream();
}