org.openqa.selenium.chrome.ChromeDriverService Java Examples
The following examples show how to use
org.openqa.selenium.chrome.ChromeDriverService.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ChromeDriverConfigTest.java From jmeter-plugins-webdriver with Apache License 2.0 | 8 votes |
@Test public void shouldCreateChromeAndStartService() throws Exception { ChromeDriver mockChromeDriver = mock(ChromeDriver.class); whenNew(ChromeDriver.class).withParameterTypes(ChromeDriverService.class, Capabilities.class).withArguments(isA(ChromeDriverService.class), isA(Capabilities.class)).thenReturn(mockChromeDriver); ChromeDriverService.Builder mockServiceBuilder = mock(ChromeDriverService.Builder.class); whenNew(ChromeDriverService.Builder.class).withNoArguments().thenReturn(mockServiceBuilder); when(mockServiceBuilder.usingDriverExecutable(isA(File.class))).thenReturn(mockServiceBuilder); ChromeDriverService mockService = mock(ChromeDriverService.class); when(mockServiceBuilder.build()).thenReturn(mockService); final ChromeDriver browser = config.createBrowser(); assertThat(browser, is(mockChromeDriver)); verifyNew(ChromeDriver.class, times(1)).withArguments(isA(ChromeDriverService.class), isA(Capabilities.class)); verify(mockServiceBuilder, times(1)).build(); assertThat(config.getServices().size(), is(1)); assertThat(config.getServices().values(), hasItem(mockService)); }
Example #2
Source File: ChromeDriverHelper.java From qaf with MIT License | 7 votes |
private synchronized void createAndStartService() { if ((service != null) && service.isRunning()) { return; } File driverFile = new File(ApplicationProperties.CHROME_DRIVER_PATH.getStringVal("./chromedriver.exe")); if (!driverFile.exists()) { logger.error("Please set webdriver.chrome.driver property properly."); throw new AutomationError("Driver file not exist."); } try { System.setProperty("webdriver.chrome.driver", driverFile.getCanonicalPath()); service = ChromeDriverService.createDefaultService(); service.start(); } catch (IOException e) { logger.error("Unable to start Chrome driver", e); throw new AutomationError("Unable to start Chrome Driver Service ", e); } }
Example #3
Source File: DebateFetcher.java From argument-reasoning-comprehension-task with Apache License 2.0 | 6 votes |
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); }
Example #4
Source File: AbstractWebappUiIntegrationTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@BeforeClass public static void createDriver() { String chromeDriverExecutable = "chromedriver"; if (System.getProperty( "os.name" ).toLowerCase(Locale.US).indexOf("windows") > -1) { chromeDriverExecutable += ".exe"; } File chromeDriver = new File("target/chromedriver/" + chromeDriverExecutable); if (!chromeDriver.exists()) { throw new RuntimeException("chromedriver could not be located!"); } ChromeDriverService chromeDriverService = new ChromeDriverService.Builder() .withVerbose(true) .usingAnyFreePort() .usingDriverExecutable(chromeDriver) .build(); driver = new ChromeDriver(chromeDriverService); }
Example #5
Source File: AbstractWebappUiIT.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@BeforeClass public static void createDriver() { String chromeDriverExecutable = "chromedriver"; if (System.getProperty( "os.name" ).toLowerCase(Locale.US).indexOf("windows") > -1) { chromeDriverExecutable += ".exe"; } File chromeDriver = new File("target/chromedriver/" + chromeDriverExecutable); if (!chromeDriver.exists()) { throw new RuntimeException("chromedriver could not be located!"); } ChromeDriverService chromeDriverService = new ChromeDriverService.Builder() .withVerbose(true) .usingAnyFreePort() .usingDriverExecutable(chromeDriver) .build(); driver = new ChromeDriver(chromeDriverService); }
Example #6
Source File: TestChromeDriver.java From selenium with Apache License 2.0 | 6 votes |
private static ChromeDriverService getService() { try { Path logFile = Files.createTempFile("chromedriver", ".log"); ChromeDriverService service = new ChromeDriverService.Builder() .withLogLevel(ChromeDriverLogLevel.ALL) .withLogFile(logFile.toFile()) .build(); LOG.info("chromedriver will log to " + logFile); LOG.info("chromedriver will use log level " + ChromeDriverLogLevel.ALL.toString().toUpperCase()); service.start(); // Fugly. Runtime.getRuntime().addShutdownHook(new Thread(service::stop)); return service; } catch (IOException e) { throw new RuntimeException(e); } }
Example #7
Source File: WebDriverUtils.java From rice with Educational Community License v2.0 | 6 votes |
/** * <p> * <a href="http://code.google.com/p/chromedriver/downloads/list">ChromeDriver downloads</a>, {@see #REMOTE_PUBLIC_CHROME}, * {@see #WEBDRIVER_CHROME_DRIVER}, and {@see #HUB_DRIVER_PROPERTY} * </p> * * @return chromeDriverService */ public static ChromeDriverService chromeDriverCreateCheck() { String driverParam = System.getProperty(HUB_DRIVER_PROPERTY); // TODO can the saucelabs driver stuff be leveraged here? if (driverParam != null && "chrome".equals(driverParam.toLowerCase())) { if (System.getProperty(WEBDRIVER_CHROME_DRIVER) == null) { if (System.getProperty(REMOTE_PUBLIC_CHROME) != null) { System.setProperty(WEBDRIVER_CHROME_DRIVER, System.getProperty(REMOTE_PUBLIC_CHROME)); } } try { ChromeDriverService chromeDriverService = new ChromeDriverService.Builder() .usingDriverExecutable(new File(System.getProperty(WEBDRIVER_CHROME_DRIVER))) .usingAnyFreePort() .build(); return chromeDriverService; } catch (Throwable t) { throw new RuntimeException("Exception starting chrome driver service, is chromedriver ( http://code.google.com/p/chromedriver/downloads/list ) installed? You can include the path to it using -Dremote.public.chrome", t) ; } } return null; }
Example #8
Source File: ApplicationDriver.java From oxTrust with MIT License | 6 votes |
public static void startService() { if (service == null) { File file = new File("/usr/bin/chromedriver"); service = new ChromeDriverService.Builder().usingDriverExecutable(file).usingAnyFreePort().build(); } try { service.start(); } catch (IOException e) { e.printStackTrace(); } }
Example #9
Source File: ChromeDriverServiceSupplierTest.java From bromium with MIT License | 6 votes |
@Test public void canStartDriverService() throws Exception { String pathToDriver = "chromedriver"; String screenToUse = ":1"; ChromeDriverService.Builder builder = mock(ChromeDriverService.Builder.class, RETURNS_MOCKS); ChromeDriverServiceSupplier chromeDriverServiceSupplier = new ChromeDriverServiceSupplier(); whenNew(ChromeDriverService.Builder.class).withNoArguments().thenReturn(builder); chromeDriverServiceSupplier.getDriverService(pathToDriver, screenToUse); verify(builder).usingDriverExecutable(eq(new File(pathToDriver))); }
Example #10
Source File: ChromeWebDriverProxy.java From marathonv5 with Apache License 2.0 | 6 votes |
@Override public DriverService createService(int port) { BrowserConfig config = BrowserConfig.instance(); String wdPath = config.getValue(BROWSER, "webdriver-exe-path"); ChromeDriverService.Builder builder = new ChromeDriverService.Builder(); if (wdPath != null) builder.usingDriverExecutable(new File(wdPath)); String environ = config.getValue(BROWSER, "browser-environment"); if (environ != null) { Map<String, String> envMap = new HashMap<>(); BufferedReader reader = new BufferedReader(new StringReader(environ)); String line = null; try { while ((line = reader.readLine()) != null) { String[] parts = line.split("="); if (parts != null && parts.length == 2) { envMap.put(parts[0], parts[1]); } } } catch (IOException e) { } builder.withEnvironment(envMap); } String logFile = config.getValue(BROWSER, "webdriver-log-file-path"); if (logFile != null) { builder.withLogFile(new File(logFile)); } builder.withVerbose(config.getValue(BROWSER, "webdriver-verbose", false)); builder.withSilent(config.getValue(BROWSER, "webdriver-silent", true)); return builder.usingPort(port).build(); }
Example #11
Source File: ChromeDriverConfig.java From jmeter-plugins-webdriver with Apache License 2.0 | 5 votes |
@Override public void quitBrowser(final ChromeDriver browser) { super.quitBrowser(browser); final ChromeDriverService service = services.remove(currentThreadName()); if (service != null && service.isRunning()) { service.stop(); } }
Example #12
Source File: ChromeDriverConfigTest.java From jmeter-plugins-webdriver with Apache License 2.0 | 5 votes |
@Test public void shouldBeAbleToCallQuitBrowserMultipleTimes() throws Exception { ChromeDriver mockChromeDriver = mock(ChromeDriver.class); ChromeDriverService mockService = mock(ChromeDriverService.class); when(mockService.isRunning()).thenReturn(true); config.getServices().put(config.currentThreadName(), mockService); config.quitBrowser(mockChromeDriver); config.quitBrowser(mockChromeDriver); assertThat(config.getServices(), is(Collections.<String, ChromeDriverService>emptyMap())); verify(mockService, times(1)).stop(); }
Example #13
Source File: ChromeDriverConfigTest.java From jmeter-plugins-webdriver with Apache License 2.0 | 5 votes |
@Test public void shouldNotCreateChromeWhenStartingServiceThrowsAnException() throws Exception { ChromeDriverService.Builder mockServiceBuilder = mock(ChromeDriverService.Builder.class); whenNew(ChromeDriverService.Builder.class).withNoArguments().thenReturn(mockServiceBuilder); when(mockServiceBuilder.usingDriverExecutable(isA(File.class))).thenReturn(mockServiceBuilder); ChromeDriverService mockService = mock(ChromeDriverService.class); when(mockServiceBuilder.build()).thenReturn(mockService); doThrow(new IOException("Stubbed exception")).when(mockService).start(); final ChromeDriver browser = config.createBrowser(); assertThat(browser, is(nullValue())); assertThat(config.getServices(), is(Collections.<String, ChromeDriverService>emptyMap())); verify(mockServiceBuilder, times(1)).build(); }
Example #14
Source File: DriverServiceManager.java From burp-javascript-security-extension with GNU General Public License v3.0 | 5 votes |
public ChromeDriverService getService(){ return service; }
Example #15
Source File: ChromeDriverConfig.java From jmeter-plugins-webdriver with Apache License 2.0 | 5 votes |
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; }
Example #16
Source File: ChromeDriverConfigTest.java From jmeter-plugins-webdriver with Apache License 2.0 | 5 votes |
@Test public void shouldQuitWebDriverAndStopServiceWhenQuitBrowserIsInvoked() throws Exception { ChromeDriver mockChromeDriver = mock(ChromeDriver.class); ChromeDriverService mockService = mock(ChromeDriverService.class); when(mockService.isRunning()).thenReturn(true); config.getServices().put(config.currentThreadName(), mockService); config.quitBrowser(mockChromeDriver); verify(mockChromeDriver).quit(); assertThat(config.getServices(), is(Collections.<String, ChromeDriverService>emptyMap())); verify(mockService, times(1)).stop(); }
Example #17
Source File: ChromeDriverConfig.java From jmeter-plugins-webdriver with Apache License 2.0 | 5 votes |
@Override protected ChromeDriver createBrowser() { final ChromeDriverService service = getThreadService(); return service != null ? new ChromeDriver(service, createCapabilities()) : null; }
Example #18
Source File: ChromeDriverConfigTest.java From jmeter-plugins-webdriver with Apache License 2.0 | 5 votes |
@Test public void shouldNotStopServiceIfNotRunningWhenQuitBrowserIsInvoked() throws Exception { ChromeDriver mockChromeDriver = mock(ChromeDriver.class); ChromeDriverService mockService = mock(ChromeDriverService.class); when(mockService.isRunning()).thenReturn(false); config.getServices().put(config.currentThreadName(), mockService); config.quitBrowser(mockChromeDriver); verify(mockChromeDriver).quit(); assertThat(config.getServices(), is(Collections.<String, ChromeDriverService>emptyMap())); verify(mockService, times(0)).stop(); }
Example #19
Source File: WebDriverAutoConfiguration.java From Learning-Spring-Boot-2.0-Second-Edition with MIT License | 5 votes |
@Bean(destroyMethod = "stop") @Lazy public ChromeDriverService chromeDriverService() { System.setProperty("webdriver.chrome.driver", "ext/chromedriver"); return createDefaultService(); }
Example #20
Source File: StandaloneDriverFactory.java From teasy with MIT License | 5 votes |
private WebDriver chrome(DesiredCapabilities customCaps, Platform platform) { DriverHolder.setDriverName(CHROME); WebDriverManager.chromedriver().setup(); ChromeDriverService service = ChromeDriverService.createDefaultService(); ChromeDriver chromeDriver = new ChromeDriver( service, new ChromeCaps(customCaps, this.alertBehaviour, this.isHeadless, platform).get() ); TestParamsHolder.setChromePort(service.getUrl().getPort()); return chromeDriver; }
Example #21
Source File: ChromeDriverConfig.java From jmeter-plugins-webdriver with Apache License 2.0 | 5 votes |
Map<String, ChromeDriverService> getServices() { return services; }
Example #22
Source File: Browser.java From coteafs-selenium with Apache License 2.0 | 5 votes |
private static WebDriver setupChromeDriver() throws MalformedURLException { LOG.i("Setting up Chrome driver..."); System.setProperty("webdriver.chrome.silentOutput", "true"); setupDriver(chromedriver()); final ChromeOptions chromeOptions = new ChromeOptions(); chromeOptions.addArguments("--dns-prefetch-disable"); if (appSetting().isHeadlessMode()) { chromeOptions.addArguments("--headless"); } chromeOptions.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true); final ChromeDriverService chromeService = ChromeDriverService.createDefaultService(); return new ChromeDriver(chromeService, chromeOptions); }
Example #23
Source File: ChromeBrowserFactory.java From darcy-webdriver with GNU General Public License v3.0 | 4 votes |
public ChromeBrowserFactory usingService(ChromeDriverService cds) { service = cds; return this; }
Example #24
Source File: UserJourneyTestIT.java From getting-started-java with Apache License 2.0 | 4 votes |
@BeforeClass public static void setupClass() throws Exception { service = ChromeDriverService.createDefaultService(); service.start(); }
Example #25
Source File: BrowserService.java From collect-earth with MIT License | 4 votes |
private RemoteWebDriver startChromeBrowser() throws BrowserNotFoundException { final Properties props = System.getProperties(); String chromedriverExe = null; if (StringUtils.isBlank(props.getProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY))) { if (SystemUtils.IS_OS_MAC || SystemUtils.IS_OS_MAC_OSX) { chromedriverExe = "resources/chromedriver_mac"; } else if (SystemUtils.IS_OS_UNIX) { chromedriverExe = "resources/chromedriver64"; } else if (SystemUtils.IS_OS_WINDOWS) { chromedriverExe = "resources/chromedriver.exe"; } else { throw new BrowserNotFoundException("Chromedriver is not supported in the current OS"); } props.setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY, chromedriverExe); } String chromeBinaryPath = localPropertiesService.getValue(EarthProperty.CHROME_BINARY_PATH); // Handle the special case when the user picks the Chrome or Firefox app files // for Mac if ((SystemUtils.IS_OS_MAC || SystemUtils.IS_OS_MAC_OSX) && (chromeBinaryPath.toLowerCase().endsWith("google chrome.app") || chromeBinaryPath.toLowerCase().endsWith("chrome.app"))) { chromeBinaryPath = chromeBinaryPath + "/Contents/MacOS/Google Chrome"; } ChromeOptions chromeOptions = new ChromeOptions(); chromeOptions.addArguments("disable-infobars"); chromeOptions.addArguments("disable-save-password-bubble"); if (!StringUtils.isBlank(chromeBinaryPath)) { try { chromeOptions.setBinary(chromeBinaryPath); } catch (final WebDriverException e) { logger.error( "The chrome executable chrome.exe cannot be found, please edit earth.properties and correct the chrome.exe location at " + EarthProperty.CHROME_BINARY_PATH + " pointing to the full path to chrome.exe", e); } } return new ChromeDriver(chromeOptions); }
Example #26
Source File: ChromeService.java From AndroidRobot with Apache License 2.0 | 4 votes |
public static ChromeDriverService getService() { return service; }
Example #27
Source File: ChromeService.java From AndroidRobot with Apache License 2.0 | 4 votes |
public static void startService() throws IOException { service = new ChromeDriverService.Builder() .usingAnyFreePort() .build(); service.start(); }
Example #28
Source File: UserJourneyTestIT.java From java-docs-samples with Apache License 2.0 | 4 votes |
@BeforeClass public static void setupClass() throws Exception { service = ChromeDriverService.createDefaultService(); service.start(); }
Example #29
Source File: ChromeDriverEx.java From QVisual with Apache License 2.0 | 4 votes |
public ChromeDriverEx(Capabilities capabilities) { this(ChromeDriverService.createDefaultService(), capabilities); }
Example #30
Source File: CucumberFeatureTest.java From site-infrastructure-tests with Apache License 2.0 | 4 votes |
public static ChromeDriverService getService() { if (logger.isDebugEnabled()) { logger.debug("Getting ChromeDriverService."); } return _chromeDriverService; }