List of usage examples for org.openqa.selenium.chrome ChromeDriverService stop
public void stop()
From source file:openpath.Main.java
public void other(String[] args) throws IOException { String webdriverPath = "/usr/local/bin/chromedriver"; String chromePath = "/usr/bin/google-chrome"; String downloadDir = "/opt/tmp/openpath"; ChromeDriverService service = new ChromeDriverService.Builder() .usingDriverExecutable(new File(webdriverPath)).usingAnyFreePort().build(); Map<String, Object> prefs = new HashMap<>(); prefs.put("download.default_directory", downloadDir); ChromeOptions opts = new ChromeOptions(); opts.setBinary(new File(chromePath)); opts.setExperimentalOption("prefs", prefs); DesiredCapabilities caps = DesiredCapabilities.chrome(); caps.setCapability(ChromeOptions.CAPABILITY, opts); service.start();/*from w w w . j a va 2 s . c o m*/ WebDriver drv = new RemoteWebDriver(service.getUrl(), caps); OpenPathDriver opDrv = new OpenPathDriver(drv, m -> { System.out.println(">> " + m); }); String opUsername = "caiyuhao0125@hotmail.com"; String opPassword = "19910125"; opDrv.download(opUsername, opPassword, Paths.get(downloadDir)); service.stop(); System.exit(0); }
From source file:org.roda.core.common.SeleniumUtils.java
License:Open Source License
/** * /*from ww w . ja v a 2 s. c om*/ * @param args: * the first argument is the RODA base url and the second argument is * the driver path * @throws InterruptedException * @throws IOException */ public static void main(String[] args) throws InterruptedException, IOException { if (args.length != 2) { System.err.println("Number of arguments not correct since it is only needed two arguments. " + "The first argument is the RODA base url and the second argument is the driver path"); commandHelp(); System.exit(0); } url = args[0]; driverPath = args[1]; ChromeDriverService service = new ChromeDriverService.Builder().usingDriverExecutable(new File(driverPath)) .usingAnyFreePort().build(); service.start(); driver = new RemoteWebDriver(service.getUrl(), DesiredCapabilities.chrome()); driver.get(url); // welcome page saveHTML(); savePublicPages(); saveLoginPages(); saveHelpPages(); savePlanningPages(); saveAdminPages(); saveIngestPages(); saveSearchPages(); saveBrowsePages(); driver.quit(); service.stop(); for (Entry<String, String> entry : locations.entrySet()) { String location = entry.getKey(); String html = getHTMLSource(location); Pattern expression = Pattern.compile("<div id=\"webaxscore\".*?<span>(.*?)</span>"); Matcher matcher = expression.matcher(html); if (matcher.find()) { System.out.println(location + " | " + locations.get(location) + " | " + matcher.group(1)); } } }
From source file:org.zaproxy.zap.extension.jxbrowserlinux64.selenium.JxBrowserProvider.java
License:Apache License
private RemoteWebDriver getRemoteWebDriverImpl(final int requesterId, String proxyAddress, int proxyPort) { try {// w ww .j a v a 2 s. c o m ZapBrowserFrame zbf = this.getZapBrowserFrame(requesterId); File dataDir = Files.createTempDirectory("zap-jxbrowser").toFile(); dataDir.deleteOnExit(); BrowserContextParams contextParams = new BrowserContextParams(dataDir.getAbsolutePath()); if (proxyAddress != null && !proxyAddress.isEmpty()) { String hostPort = proxyAddress + ":" + proxyPort; String proxyRules = "http=" + hostPort + ";https=" + hostPort; contextParams.setProxyConfig(new CustomProxyConfig(proxyRules)); } BrowserPreferences.setChromiumSwitches("--remote-debugging-port=" + chromePort); Browser browser = new Browser(new BrowserContext(contextParams)); final BrowserPanel browserPanel = zbf.addNewBrowserPanel(isNotAutomated(requesterId), browser); if (!ensureExecutable(webdriver)) { throw new IllegalStateException("Failed to ensure WebDriver is executable."); } final ChromeDriverService service = new ChromeDriverService.Builder() .usingDriverExecutable(webdriver.toFile()).usingAnyFreePort().build(); service.start(); DesiredCapabilities capabilities = new DesiredCapabilities(); ChromeOptions options = new ChromeOptions(); options.setExperimentalOption("debuggerAddress", "localhost:" + chromePort); capabilities.setCapability(ChromeOptions.CAPABILITY, options); return new RemoteWebDriver(service.getUrl(), capabilities) { @Override public void close() { super.close(); cleanUpBrowser(requesterId, browserPanel); // XXX should stop here too? // service.stop(); } @Override public void quit() { super.quit(); cleanUpBrowser(requesterId, browserPanel); boolean interrupted = Thread.interrupted(); service.stop(); if (interrupted) { Thread.currentThread().interrupt(); } } }; } catch (Exception e) { throw new WebDriverException(e); } }