ChromeDriverService chromeDriverService = new ChromeDriverService.Builder() .usingDriverExecutable(new File(ChromeUtils.getChromeDriverPath())) .usingAnyFreePort() .withEnvironment(ImmutableMap.of("DISPLAY",":1024")) .build(); try { chromeDriverService.start(); webDriver = new ChromeDriver(chromeDriverService, caps); } ....
private static void initializeSeleniumDriver() throws IOException { if (null == DRIVERSERVICE) { final String theChromeDriverBinary = System.getenv("CHROMEDRIVER_BINARY"); if (null == theChromeDriverBinary || theChromeDriverBinary.isEmpty()) { throw new RuntimeException("No chromedriver binary found! Please set CHROMEDRIVER_BINARY environment variable!"); } ChromeDriverService.Builder theDriverService = new ChromeDriverService.Builder(); theDriverService = theDriverService.withVerbose(false); theDriverService = theDriverService.usingDriverExecutable(new File(theChromeDriverBinary)); DRIVERSERVICE = theDriverService.build(); DRIVERSERVICE.start(); Runtime.getRuntime().addShutdownHook(new Thread(() -> DRIVERSERVICE.stop())); } }
private static void initializeSeleniumDriver() throws IOException { if (null == DRIVERSERVICE) { final String theChromeDriverBinary = System.getenv("CHROMEDRIVER_BINARY"); if (null == theChromeDriverBinary || theChromeDriverBinary.isEmpty()) { throw new RuntimeException("No chromedriver binary found! Please set CHROMEDRIVER_BINARY environment variable!"); } ChromeDriverService.Builder theDriverService = new ChromeDriverService.Builder(); theDriverService = theDriverService.withVerbose(false); theDriverService = theDriverService.usingDriverExecutable(new File(theChromeDriverBinary)); DRIVERSERVICE = theDriverService.build(); DRIVERSERVICE.start(); Runtime.getRuntime().addShutdownHook(new Thread(() -> DRIVERSERVICE.stop())); } }
ChromeDriverService cds = ChromeDriverService.createDefaultService(); try { cds.start(); } catch (IOException e) { e.printStackTrace();
public WebDriver getDriver() { try { File file = new File(Config.chrome_webdriver_location); ChromeDriverService service = new ChromeDriverService.Builder() .usingDriverExecutable(file) .usingAnyFreePort().build(); service.start(); WebDriver instance = new ChromeDriver(service, DesiredCapabilities.chrome()); log.info("Found webdriver instance : " + instance); return instance; } catch (IOException e) { e.printStackTrace(); } log.info("Returning back null web driver"); return new NullWebDriver(); }
private ChromeDriverService getThreadService() { ChromeDriverService service = services.get(currentThreadName()); if (service != null) { return service; } try { service = new ChromeDriverService.Builder().usingDriverExecutable(new File(getChromeDriverPath())).build(); service.start(); services.put(currentThreadName(), service); } catch (IOException e) { LOGGER.error("Failed to start chrome service"); service = null; } return service; }
theDriverService.start();
public DebateFetcher(String chromeDriverFile) throws IOException { service = new ChromeDriverService.Builder() .usingDriverExecutable( new File(chromeDriverFile)) .usingAnyFreePort() .withEnvironment(ImmutableMap.of("DISPLAY", ":20")).build(); service.start(); DesiredCapabilities capabilities = DesiredCapabilities.chrome(); driver = new RemoteWebDriver(service.getUrl(), capabilities); }
.build(); service.start();