How to use ExecutableFinder class of org.openqa.selenium.os package

Best Selenium code snippet using org.openqa.selenium.os.ExecutableFinder

Source:BuckBuild.java Github

copy

Full Screen

...24import com.google.common.collect.ImmutableList;25import com.google.common.hash.HashCode;26import com.google.common.hash.Hashing;27import org.openqa.selenium.os.CommandLine;28import org.openqa.selenium.os.ExecutableFinder;29import org.openqa.selenium.testing.InProject;30import java.io.IOException;31import java.net.HttpURLConnection;32import java.net.URL;33import java.nio.file.Files;34import java.nio.file.Path;35import java.util.List;36import java.util.logging.Logger;37public class BuckBuild {38 private static Logger log = Logger.getLogger(BuckBuild.class.getName());39 private String target;40 public BuckBuild of(String target) {41 this.target = target;42 return this;43 }44 public Path go() throws IOException {45 Path projectRoot = InProject.locate("Rakefile").getParent();46 if (!isInDevMode()) {47 // we should only need to do this when we're in dev mode48 // when running in a test suite, our dependencies should already49 // be listed.50 log.info("Not in dev mode. Ignoring attempt to build: " + target);51 return findOutput(projectRoot);52 }53 if (target == null || "".equals(target)) {54 throw new IllegalStateException("No targets specified");55 }56 System.out.println("\nBuilding " + target + " ...");57 ImmutableList.Builder<String> builder = ImmutableList.builder();58 findBuck(projectRoot, builder);59 builder.add("build", "--config", "color.ui=never", target);60 ImmutableList<String> command = builder.build();61 CommandLine commandLine = new CommandLine(command.toArray(new String[command.size()]));62 commandLine.copyOutputTo(System.err);63 commandLine.execute();64 if (!commandLine.isSuccessful()) {65 throw new WebDriverException("Build failed! " + target);66 }67 return findOutput(projectRoot);68 }69 private Path findOutput(Path projectRoot) throws IOException {70 ImmutableList.Builder<String> builder = ImmutableList.builder();71 findBuck(projectRoot, builder);72 builder.add("targets", "--show-full-output", "--config", "color.ui=never", target);73 ImmutableList<String> command = builder.build();74 CommandLine commandLine = new CommandLine(command.toArray(new String[command.size()]));75 commandLine.copyOutputTo(System.err);76 commandLine.execute();77 if (!commandLine.isSuccessful()) {78 throw new WebDriverException("Unable to find output! " + target);79 }80 String stdOut = commandLine.getStdOut();81 String[] allLines = stdOut.split(LINE_SEPARATOR.value());82 String lastLine = null;83 for (String line : allLines) {84 if (line.startsWith(target)) {85 lastLine = line;86 break;87 }88 }89 Preconditions.checkNotNull(lastLine, "Value read: %s", stdOut);90 List<String> outputs = Splitter.on(' ').limit(2).splitToList(lastLine);91 if (outputs.size() != 2) {92 throw new WebDriverException(93 String.format("Unable to find output! %s, %s", target, lastLine));94 }95 Path output = projectRoot.resolve(outputs.get(1));96 if (!Files.exists(output)) {97 throw new WebDriverException(98 String.format("Found output, but it does not exist: %s, %s", target, output));99 }100 return output;101 }102 private void findBuck(Path projectRoot, ImmutableList.Builder<String> builder) throws IOException {103 Path noBuckCheck = projectRoot.resolve(".nobuckcheck");104 // If there's a .nobuckcheck in the root of the file, and we can execute "buck", then assume105 // that the developer knows what they're doing. Ha! Ahaha! Ahahahaha!106 if (Files.exists(noBuckCheck)) {107 String buckCommand = new ExecutableFinder().find("buck");108 if (buckCommand != null) {109 builder.add(buckCommand);110 return;111 }112 }113 downloadBuckPexIfNecessary(builder);114 }115 private void downloadBuckPexIfNecessary(ImmutableList.Builder<String> builder)116 throws IOException {117 Path projectRoot = InProject.locate("Rakefile").getParent();118 String buckVersion = new String(Files.readAllBytes(projectRoot.resolve(".buckversion"))).trim();119 Path pex = projectRoot.resolve("buck-out/crazy-fun/" + buckVersion + "/buck.pex");120 String expectedHash = new String(Files.readAllBytes(projectRoot.resolve(".buckhash"))).trim();121 HashCode md5 = Files.exists(pex) ?122 Hashing.md5().hashBytes(Files.readAllBytes(pex)) :123 HashCode.fromString("aa"); // So we have a non-null value124 if (!Files.exists(pex) || !expectedHash.equals(md5.toString())) {125 log.warning("Downloading PEX");126 if (!Files.exists(pex.getParent())) {127 Files.createDirectories(pex.getParent());128 }129 URL url = new URL(String.format(130 "https://github.com/SeleniumHQ/buck/releases/download/buck-release-%s/buck.pex",131 buckVersion));132 HttpURLConnection connection = (HttpURLConnection) url.openConnection();133 connection.setInstanceFollowRedirects(true);134 Files.copy(connection.getInputStream(), pex, REPLACE_EXISTING);135 // Do our best to make this executable136 pex.toFile().setExecutable(true);137 }138 md5 = Hashing.md5().hashBytes(Files.readAllBytes(pex));139 if (!expectedHash.equals(md5.toString())) {140 throw new WebDriverException("Unable to confirm that download is valid");141 }142 if (Platform.getCurrent().is(WINDOWS)) {143 String python = new ExecutableFinder().find("python2");144 if (python == null) {145 python = new ExecutableFinder().find("python");146 }147 Preconditions.checkNotNull(python, "Unable to find python executable");148 builder.add(python);149 }150 builder.add(pex.toAbsolutePath().toString());151 }152 public static void main(String[] args) throws IOException {153 new BuckBuild().of("se3-server").go();154 }155}...

Full Screen

Full Screen

Source:FirefoxExecutable.java Github

copy

Full Screen

...7import org.apache.commons.lang.math.NumberUtils;8import org.openqa.selenium.Platform;9import org.openqa.selenium.WebDriverException;10import org.openqa.selenium.firefox.FirefoxDriver;11import org.openqa.selenium.os.ExecutableFinder;12import org.openqa.selenium.os.WindowsUtils;13import org.openqa.selenium.remote.DesiredCapabilities;14import com.google.common.collect.ImmutableList;15// This class duplicated codes from org.openqa.selenium.firefox.internal.Executable as it is internal.16// Should not be re-factored.17public class FirefoxExecutable {18 private static final String VERSION_SEPARATOR_REGEX = "\\.";19 private static final String MOZILLA_FIREFOX_VERSION_STRING_PREFIX = "Mozilla Firefox";20 private static final File SYSTEM_BINARY = locateFirefoxBinaryFromSystemProperty();21 private static final File PLATFORM_BINARY = locateFirefoxBinaryFromPlatform();22 private FirefoxExecutable() {23 }24 public static int getFirefoxVersion(DesiredCapabilities desiredCapabilities) {25 File defaultFirefoxBinary = FirefoxExecutable.getFirefoxBinaryFile(getFirefoxBinary(desiredCapabilities));26 try {27 String firefoxVersionString = ConsoleCommandExecutor.runConsoleCommandAndCollectFirstResult(28 new String[] { defaultFirefoxBinary.getAbsolutePath(), "-v", "|", "more" });29 if (firefoxVersionString == null30 || !firefoxVersionString.startsWith(MOZILLA_FIREFOX_VERSION_STRING_PREFIX)) {31 return 0;32 }33 firefoxVersionString = firefoxVersionString.substring(MOZILLA_FIREFOX_VERSION_STRING_PREFIX.length())34 .trim();35 String firefoxVersionMajor = firefoxVersionString.split(VERSION_SEPARATOR_REGEX)[0];36 Number firefoxVersion = NumberUtils.createNumber(firefoxVersionMajor);37 return firefoxVersion.intValue();38 } catch (IOException | InterruptedException | NumberFormatException e) {39 // Exception happened, ignore40 }41 return 0;42 }43 private static String getFirefoxBinary(DesiredCapabilities desiredCapabilities) {44 if (desiredCapabilities == null || desiredCapabilities.getCapability(FirefoxDriver.BINARY) == null) {45 return null;46 }47 Object raw = desiredCapabilities.getCapability(FirefoxDriver.BINARY);48 if (raw instanceof String) {49 return (String) raw;50 }51 return null;52 }53 public static File getFirefoxBinaryFile(String userSpecifiedBinaryPath) throws WebDriverException {54 if (userSpecifiedBinaryPath != null) {55 File userSpecifiedBinaryFile = new File(userSpecifiedBinaryPath);56 // It should exist and be a file.57 if (userSpecifiedBinaryFile.exists() && userSpecifiedBinaryFile.isFile()) {58 return userSpecifiedBinaryFile;59 }60 throw new WebDriverException("Specified firefox binary location does not exist or is not a real file: "61 + userSpecifiedBinaryPath);62 }63 if (SYSTEM_BINARY != null && SYSTEM_BINARY.exists()) {64 return SYSTEM_BINARY;65 }66 if (PLATFORM_BINARY != null && PLATFORM_BINARY.exists()) {67 return PLATFORM_BINARY;68 }69 throw new WebDriverException("Cannot find firefox binary in PATH. "70 + "Make sure firefox is installed. OS appears to be: " + Platform.getCurrent());71 }72 private static File locateFirefoxBinaryFromSystemProperty() {73 String binaryName = System.getProperty(FirefoxDriver.SystemProperty.BROWSER_BINARY);74 if (binaryName == null)75 return null;76 File binary = new File(binaryName);77 if (binary.exists())78 return binary;79 Platform current = Platform.getCurrent();80 if (current.is(WINDOWS)) {81 if (!binaryName.endsWith(".exe"))82 binaryName += ".exe";83 } else if (current.is(MAC)) {84 if (!binaryName.endsWith(".app"))85 binaryName += ".app";86 binaryName += "/Contents/MacOS/firefox-bin";87 }88 binary = new File(binaryName);89 if (binary.exists())90 return binary;91 throw new WebDriverException(String.format("'%s' property set, but unable to locate the requested binary: %s",92 FirefoxDriver.SystemProperty.BROWSER_BINARY, binaryName));93 }94 /**95 * Locates the firefox binary by platform.96 */97 @SuppressWarnings("deprecation")98 private static File locateFirefoxBinaryFromPlatform() {99 File binary = null;100 Platform current = Platform.getCurrent();101 if (current.is(WINDOWS)) {102 binary = findExistingBinary(WindowsUtils.getPathsInProgramFiles("Mozilla Firefox\\firefox.exe"));103 } else if (current.is(MAC)) {104 binary = new File("/Applications/Firefox.app/Contents/MacOS/firefox-bin");105 // fall back to homebrew install location if default is not found106 if (!binary.exists()) {107 binary = new File(System.getProperty("user.home") + binary.getAbsolutePath());108 }109 }110 if (binary != null && binary.exists()) {111 return binary;112 }113 ExecutableFinder binaryFinder = new ExecutableFinder();114 if (current.is(UNIX)) {115 String systemFirefox = binaryFinder.find("firefox-bin");116 if (systemFirefox != null) {117 return new File(systemFirefox);118 }119 }120 String systemFirefox = binaryFinder.find("firefox");121 if (systemFirefox != null) {122 return new File(systemFirefox);123 }124 return null;125 }126 private static File findExistingBinary(final ImmutableList<String> paths) {127 for (String path : paths) {...

Full Screen

Full Screen

Source:CoreSelfTest.java Github

copy

Full Screen

...23import org.junit.After;24import org.junit.Before;25import org.junit.Test;26import org.openqa.selenium.environment.webserver.AppServer;27import org.openqa.selenium.os.ExecutableFinder;28import java.io.IOException;29import java.nio.file.Files;30import java.nio.file.Path;31import java.nio.file.Paths;32import java.util.concurrent.TimeUnit;33public class CoreSelfTest {34 private String browser;35 private AppServer server;36 @Before37 public void detectBrowser() {38 browser = System.getProperty("selenium.browser", "*googlechrome");39 switch (browser) {40 case "*firefox":41 assumeNotNull(new ExecutableFinder().find("geckodriver"));42 break;43 case "*googlechrome":44 assumeNotNull(new ExecutableFinder().find("chromedriver"));45 break;46 default:47 assumeFalse("No known driver able to be found", false);48 }49 }50 @Before51 public void startTestServer() {52 server = new SeleniumAppServer();53 server.start();54 }55 @After56 public void stopTestServer() {57 server.stop();58 }...

Full Screen

Full Screen

Source:DriverManager.java Github

copy

Full Screen

2import com.google.common.base.Preconditions;3import com.upgrade.ui.helpers.AbstractUITest;4import org.openqa.selenium.Platform;5import org.openqa.selenium.WebDriver;6import org.openqa.selenium.os.ExecutableFinder;7import java.io.File;8import java.net.URL;9public abstract class DriverManager {10 protected WebDriver driver;11 private ThreadLocal<WebDriver> driverThreads;12 protected abstract void createDriver(AbstractUITest ab);13 protected DriverManager() {14 driverThreads = new ThreadLocal<>();15 }16 public void quitDriver() {17 if (driverThreads.get() != null) {18 driverThreads.get().quit();19 driverThreads.set(null);20 }21 }22 public WebDriver getDriver(AbstractUITest ab) {23 if (driverThreads.get() == null) {24 createDriver(ab);25 }26 driverThreads.set(driver);27 return driverThreads.get();28 }29 protected File getExecutable(String executableName) {30 File file;31 Preconditions.checkNotNull(executableName);32 if (Platform.getCurrent().is(Platform.WINDOWS)) {33 file = new File(DriverManager.class.getResource("/" + executableName + ".exe").getFile());34 if (canExecute(file)) {35 return file;36 }37 } else if(Platform.getCurrent().is(Platform.MAC)) {38 URL res = getClass().getClassLoader().getResource("/macDrivers/chromeDriver.exe");39 file = new File(DriverManager.class.getResource(("/macDrivers/" + executableName)).getFile());40 return file;41 }42 ExecutableFinder executableFinder = new ExecutableFinder();43 return new File(executableFinder.find(executableName +".exe"));44 }45 private static boolean canExecute(File file) {46 return file.exists() && !file.isDirectory();47 }48}...

Full Screen

Full Screen

Source:AbstractChromeTest.java Github

copy

Full Screen

1package tk.gustavo;2import org.fluentlenium.adapter.junit.FluentTest;3import org.junit.BeforeClass;4import org.openqa.selenium.os.ExecutableFinder;5public abstract class AbstractChromeTest extends FluentTest {6 private static final String PATH_TO_CHROME_DRIVER =7 "C:\\Users\\Gustavo Maciel\\Documents\\Diversos\\Projects\\flask-selenium-test\\driver\\chromedriver.exe";8 private static final String CHROME_DRIVER_PROPERTY = "webdriver.chrome.driver";9 @BeforeClass10 public static void setup() {11 if (systemPropertyNotSet() && executableNotPresentInPath()) {12 setSystemProperty();13 }14 }15 private static boolean executableNotPresentInPath() {16 return new ExecutableFinder().find("chromedriver") == null;17 }18 private static boolean systemPropertyNotSet() {19 return System.getProperty(CHROME_DRIVER_PROPERTY) == null;20 }21 private static void setSystemProperty() {22 System.setProperty(CHROME_DRIVER_PROPERTY, PATH_TO_CHROME_DRIVER);23 }24}...

Full Screen

Full Screen

ExecutableFinder

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.os.ExecutableFinder;2{3 public static void main(String[] args) throws Exception4 {5 ExecutableFinder finder = new ExecutableFinder();6 String firefoxPath = finder.find("firefox");7 System.out.println("Firefox path is : "+firefoxPath);8 }9}

Full Screen

Full Screen

ExecutableFinder

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.os.ExecutableFinder;2public class FindExecutable {3 public static void main(String[] args) {4 String executable = new ExecutableFinder().find("chromedriver");5 System.out.println("Found executable: " + executable);6 }7}8import org.openqa.selenium.os.FileFinder;9public class FindFile {10 public static void main(String[] args) {11 String file = new FileFinder().findFileInPath("chromedriver");12 System.out.println("Found file: " + file);13 }14}15import org.openqa.selenium.os.OperatingSystem;16public class OperatingSystemTest {17 public static void main(String[] args) {18 OperatingSystem os = new OperatingSystem();19 System.out.println("OS name: " + os.getName());20 System.out.println("OS version: " + os.getVersion());21 System.out.println("OS architecture: " + os.getArch());22 System.out.println("OS is 64 bit: " + os.is64Bit());23 }24}25import org.openqa.selenium.os.ProcessUtils;26public class ProcessTest {27 public static void main(String[] args) {28 ProcessUtils processUtils = new ProcessUtils();29 processUtils.killAll("chromedriver");30 }31}32import org.openqa.selenium.os.WindowsUtils;33public class WindowsUtilsTest {34 public static void main(String[] args) {35 WindowsUtils windowsUtils = new WindowsUtils();36 windowsUtils.killByName("chromedriver.exe");37 }38}39import org.openqa.selenium.os.UnixUtils;40public class UnixUtilsTest {41 public static void main(String[] args) {42 UnixUtils unixUtils = new UnixUtils();43 unixUtils.killByName("chrom

Full Screen

Full Screen

ExecutableFinder

Using AI Code Generation

copy

Full Screen

1File file = new File("chromedriver.exe");2String path = file.getAbsolutePath();3System.setProperty("webdriver.chrome.driver", path);4WebDriver driver = new ChromeDriver();5driver.manage().window().maximize();6driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);7driver.findElement(By.name("q")).sendKeys("selenium");8driver.findElement(By.name("btnK")).click();9driver.quit();

Full Screen

Full Screen

ExecutableFinder

Using AI Code Generation

copy

Full Screen

1package com.selenium;2import java.io.File;3import org.openqa.selenium.os.ExecutableFinder;4public class ExecutablePath {5 public static void main(String[] args) {6 ExecutableFinder finder = new ExecutableFinder();7 File file = finder.find("chromedriver");8 System.out.println(file.getAbsolutePath());9 }10}

Full Screen

Full Screen

ExecutableFinder

Using AI Code Generation

copy

Full Screen

1package com.selenium4beginners.java.webdriver.basics;2import java.io.File;3import org.openqa.selenium.WebDriver;4import org.openqa.selenium.chrome.ChromeDriver;5import org.openqa.selenium.os.ExecutableFinder;6public class ChromeDriverExecutables {7 public static void main(String[] args) {8 ExecutableFinder exeFinder = new ExecutableFinder();9 String exePath = exeFinder.find("chromedriver.exe");10 System.out.println("Path of the executable file: " + exePath);11 File exeFile = new File(exePath);12 System.out.println("Path of the executable file: " + exeFile.getAbsolutePath());13 System.setProperty("webdriver.chrome.driver", exeFile.getAbsolutePath());14 WebDriver driver = new ChromeDriver();15 System.out.println("Title of the page: " + driver.getTitle());16 driver.quit();17 }18}

Full Screen

Full Screen

ExecutableFinder

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.By;2import org.openqa.selenium.WebDriver;3import org.openqa.selenium.WebElement;4import org.openqa.selenium.chrome.ChromeDriver;5import org.openqa.selenium.os.ExecutableFinder;6public class TestChromeDriver {7 public static void main(String[] args) {8 ExecutableFinder executableFinder = new ExecutableFinder();9 String chromeDriverPath = executableFinder.find("chromedriver");10 System.setProperty("webdriver.chrome.driver", chromeDriverPath);11 WebDriver driver = new ChromeDriver();12 element.click();13 driver.close();14 driver.quit();15 }16}

Full Screen

Full Screen
copy
1//div[@data-date-picker-id='book-trip']//button[starts-with(@id,'dp') and starts-with(@aria-label, 'Departing on ')]2
Full Screen

Selenium 4 Tutorial:

LambdaTest’s Selenium 4 tutorial is covering every aspects of Selenium 4 testing with examples and best practices. Here you will learn basics, such as how to upgrade from Selenium 3 to Selenium 4, to some advanced concepts, such as Relative locators and Selenium Grid 4 for Distributed testing. Also will learn new features of Selenium 4, such as capturing screenshots of specific elements, opening a new tab or window on the browser, and new protocol adoptions.

Chapters:

  1. Upgrading From Selenium 3 To Selenium 4?: In this chapter, learn in detail how to update Selenium 3 to Selenium 4 for Java binding. Also, learn how to upgrade while using different build tools such as Maven or Gradle and get comprehensive guidance for upgrading Selenium.

  2. What’s New In Selenium 4 & What’s Being Deprecated? : Get all information about new implementations in Selenium 4, such as W3S protocol adaption, Optimized Selenium Grid, and Enhanced Selenium IDE. Also, learn what is deprecated for Selenium 4, such as DesiredCapabilites and FindsBy methods, etc.

  3. Selenium 4 With Python: Selenium supports all major languages, such as Python, C#, Ruby, and JavaScript. In this chapter, learn how to install Selenium 4 for Python and the features of Python in Selenium 4, such as Relative locators, Browser manipulation, and Chrom DevTool protocol.

  4. Selenium 4 Is Now W3C Compliant: JSON Wireframe protocol is retiring from Selenium 4, and they are adopting W3C protocol to learn in detail about the advantages and impact of these changes.

  5. How To Use Selenium 4 Relative Locator? : Selenium 4 came with new features such as Relative Locators that allow constructing locators with reference and easily located constructors nearby. Get to know its different use cases with examples.

  6. Selenium Grid 4 Tutorial For Distributed Testing: Selenium Grid 4 allows you to perform tests over different browsers, OS, and device combinations. It also enables parallel execution browser testing, reads up on various features of Selenium Grid 4 and how to download it, and runs a test on Selenium Grid 4 with best practices.

  7. Selenium Video Tutorials: Binge on video tutorials on Selenium by industry experts to get step-by-step direction from automating basic to complex test scenarios with Selenium.

Selenium 101 certifications:

LambdaTest also provides certification for Selenium testing to accelerate your career in Selenium automation testing.

Run Selenium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

...Most popular Stackoverflow questions on ExecutableFinder

Most used methods in ExecutableFinder

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful