List of usage examples for org.openqa.selenium.chrome ChromeDriverService start
public void start() throws IOException
From source file:com.github.stefaneicher.democd.HelloControllerUAT.java
License:Apache License
@SuppressWarnings("unused") private WebDriver localChromeDriver() throws IOException { File chromeDriver = new File("src/test/resources/chromedriver_mac32"); ChromeDriverService service = new ChromeDriverService.Builder().usingDriverExecutable(chromeDriver) .usingAnyFreePort().build(); service.start(); System.setProperty("webdriver.chrome.driver", String.valueOf(chromeDriver)); return new RemoteWebDriver(service.getUrl(), DesiredCapabilities.chrome()); }
From source file:com.sios.stc.coseng.util.Run.java
License:Open Source License
public synchronized void startService(final Spot spot, final WebDriver driver) throws IOException { if ((spot != null) && spot.equals(Spot.LOCAL) && (driver != null)) { // WebDriver is built into FIREFOX on Linux and Windows if (driver instanceof ChromeDriver) { // If service class isn't already running start the service if (!isServiceRunning(ChromeDriverService.class)) { final ChromeDriverService service = new ChromeDriverService.Builder() .usingDriverExecutable(param.localParam.getChromeDriver()).usingAnyFreePort().build(); service.start(); // Collect started service for cleanup after tests exhausted collectService(service); }//from w ww.j a v a2 s . c o m } else if (driver instanceof InternetExplorerDriver) { if (!isServiceRunning(InternetExplorerDriverService.class)) { final InternetExplorerDriverService service = new InternetExplorerDriverService.Builder() .usingDriverExecutable(param.localParam.getIeDriver()).usingAnyFreePort().build(); service.start(); // Collect started service for cleanup after tests exhausted collectService(service); } } } }
From source file:daveayan.gherkinsalad.browser.factory.ChromeBrowser.java
License:Open Source License
public WebDriver getDriver() { try {/*from w w w . java 2 s.c om*/ 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(); }
From source file:douban.spider.DoubanLogin.java
/** * ?chrome??//from ww w. j a v a2s . com * * @return WebDriver */ public static WebDriver getWebDriver() { File file = new File("exe\\chromedriver.exe"); //chromediriver ChromeDriverService service = new ChromeDriverService.Builder().usingDriverExecutable(file) .usingAnyFreePort().build(); try { service.start(); } catch (IOException ex) { Logger.getLogger(DoubanMovieSpider.class.getName()).log(Level.SEVERE, null, ex); } WebDriver dr = new RemoteWebDriver(service.getUrl(), DesiredCapabilities.chrome()); dr.get("https://accounts.douban.com/login?source=movie"); try { Thread.sleep(30000); } catch (InterruptedException ex) { Logger.getLogger(DoubanLogin.class.getName()).log(Level.SEVERE, null, ex); } return dr; }
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(); WebDriver drv = new RemoteWebDriver(service.getUrl(), caps); OpenPathDriver opDrv = new OpenPathDriver(drv, m -> { System.out.println(">> " + m); });/*w w w . j av a2s. c o 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.emonocot.portal.driver.WebDriverFacade.java
License:Open Source License
/** * * @return the webdriver//from ww w. ja v a2 s .c o m * @throws IOException if there is a problem loading the * properties file */ private WebDriver createWebDriver() throws IOException { Resource propertiesFile = new ClassPathResource("META-INF/spring/application.properties"); Properties properties = new Properties(); properties.load(propertiesFile.getInputStream()); String webdriverMode = properties.getProperty("selenium.webdriver.mode", "local"); String driverName = properties.getProperty("selenium.webdriver.impl", "org.openqa.selenium.firefox.FirefoxDriver"); WebDriverBrowserType browser = WebDriverBrowserType.fromString(driverName); String display = properties.getProperty("selenium.display.port", ":0"); if (webdriverMode.equals("local")) { switch (browser) { case CHROME: String chromeLocation = properties.getProperty("selenium.webdriver.chromedriver.location"); Map<String, String> environment = new HashMap<String, String>(); environment.put("DISPLAY", display); ChromeDriverService chromeService = new ChromeDriverService.Builder() .usingDriverExecutable(new File(chromeLocation)).usingAnyFreePort() .withEnvironment(environment).build(); chromeService.start(); return new RemoteWebDriver(chromeService.getUrl(), DesiredCapabilities.chrome()); case SAFARI: return new SafariDriver(); case INTERNET_EXPLORER: String internetExplorerLocation = properties.getProperty("selenium.webdriver.ie.location"); InternetExplorerDriverService ieService = InternetExplorerDriverService.createDefaultService(); ieService.start(); return new RemoteWebDriver(ieService.getUrl(), DesiredCapabilities.internetExplorer()); case FIREFOX: default: FirefoxBinary firefoxBinary = new FirefoxBinary(); firefoxBinary.setEnvironmentProperty("DISPLAY", display); ProfilesIni allProfiles = new ProfilesIni(); FirefoxProfile profile = allProfiles.getProfile("default"); return new FirefoxDriver(firefoxBinary, profile); } } else { DesiredCapabilities capabilities = new DesiredCapabilities(); switch (browser) { case CHROME: capabilities = DesiredCapabilities.chrome(); break; case INTERNET_EXPLORER: capabilities = DesiredCapabilities.internetExplorer(); break; case SAFARI: capabilities = DesiredCapabilities.safari(); break; case FIREFOX: default: capabilities = DesiredCapabilities.firefox(); } String platformName = properties.getProperty("selenium.webdriver.platformName", "LINUX"); WebDriverPlatformType platform = WebDriverPlatformType.valueOf(platformName); switch (platform) { case MAC: capabilities.setPlatform(Platform.MAC); break; case WINDOWS: capabilities.setPlatform(Platform.WINDOWS); break; case LINUX: default: capabilities.setPlatform(Platform.LINUX); } return new RemoteWebDriver(new URL("http://build.e-monocot.org:4444/wd/hub"), capabilities); } }
From source file:org.glassfish.tyrus.tests.qa.SeleniumToolkit.java
License:Open Source License
public void setUpChrome() { ChromeDriverService service; try {/*from w w w . j a v a 2 s.com*/ System.setProperty("webdriver.chrome.driver", getEnv("CHROME_DRIVER")); service = new ChromeDriverService.Builder().usingAnyFreePort() .usingDriverExecutable(new File(getEnv("CHROME_DRIVER"))).build(); service.start(); logger.log(Level.INFO, "ChromeDriverService.URL: {0}", service.getUrl()); driver = new ChromeDriver(service); commonBrowserSetup(); logger.log(Level.INFO, "Chrome Setup PASSED"); } catch (Exception ex) { logger.log(Level.SEVERE, "Chrome Setup FAILED: {0}", ex.getLocalizedMessage()); ex.printStackTrace(); } finally { assert driver != null : "Driver is null"; } }
From source file:org.powertools.web.WebDriverBrowser.java
License:Open Source License
private boolean startChrome(String logDirectory) { try {//from w ww.j a va2 s .c o m System.setProperty("webdriver.chrome.driver", "chromedriver.exe"); ChromeDriverService service = new ChromeDriverService.Builder() .usingDriverExecutable(new File("chromedriver.exe")).usingAnyFreePort() .withLogFile(new File(logDirectory + CHROMEDRIVER_LOG_FILENAME)).build(); service.start(); mDriver = new ChromeDriver(service); mRunTime.reportLink(CHROMEDRIVER_LOG_FILENAME); return true; } catch (IOException ioe) { return false; } }
From source file:org.roda.core.common.SeleniumUtils.java
License:Open Source License
/** * /* w w w . j a v a 2s .co m*/ * @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 ava 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); } }