- Common ways to obtain ChromeDriver
private void myMethod () {ChromeDriver c =
new ChromeDriver()
ChromeOptions options;new ChromeDriver(options)
Capabilities capabilities;new ChromeDriver(capabilities)
- Smart code suggestions by Codota
}
@Override public void destroyInstance(ChromeDriver instance) { instance.quit(); }
@Override public void destroyInstance(ChromeDriver instance) { instance.quit(); }
@Override protected void doSomethingWithProxy(String host, int port) throws IOException { Path tempDir = FileUtils.getTempDirectory().toPath(); HostAndPort proxy = HostAndPort.fromParts(host, port); System.out.format("har replay proxy listening at %s%n", proxy); ChromeDriverSetupRule.doSetup(); ChromeOptions options = createChromeOptions(tempDir, proxy); ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(); ChromeDriver driver = new ChromeDriver(options); try { /* * Ideally we'd listen for an event indicating that the browser had been closed, * but no such event exists. So instead we poll for the window state. */ WindowClosedCheck checker = new WindowClosedCheck(driver); ScheduledFuture<?> future = executor.scheduleWithFixedDelay(checker, CLOSED_POLL_INITIAL_DELAY_MS, CLOSED_POLL_INTERVAL_MS, TimeUnit.MILLISECONDS); checker.setScheduledFuture(future); synchronized (windowClosedSignal) { windowClosedSignal.wait(); } } catch (InterruptedException e) { e.printStackTrace(System.err); } finally { driver.quit(); executor.shutdownNow(); } }
public void destroy() throws Exception { if(chromePrefLogDir != null && chromePrefLogDir.isDirectory()) { Set<String> available = driver.manage().logs().getAvailableLogTypes(); for (String type : available) { printLog(type); } } driver.close(); driver.quit(); }
public Multimap<URI, String> useReplayServer(ReplaySessionControl sessionControl, Iterable<URI> urisToGet) throws IOException { HostAndPort proxy = sessionControl.getSocketAddress(); ChromeOptions options = optionsProducer.produceOptions(proxy); ChromeDriverService service = new ChromeDriverService.Builder() .usingAnyFreePort() .withEnvironment(xvfb.getController().newEnvironment()) .build(); ChromeDriver driver = new ChromeDriver(service, options); ChromeDriverKillHook.getInstance().add(driver); try { Multimap<URI, String> pageSources = ArrayListMultimap.create(); for (URI uri : urisToGet) { driver.get(uri.toString()); String pageSource = driver.getPageSource(); pageSources.put(uri, pageSource); } return pageSources; } finally { driver.quit(); ChromeDriverKillHook.getInstance().remove(driver); } } }
driver.quit();
e.printStackTrace(); } finally { driver.quit();