Search in sources :

Example 1 with ChromeDriverService

use of org.openqa.selenium.chrome.ChromeDriverService in project activityinfo by bedatadriven.

the class ChromeWebDriverProvider method initPool.

private static WebDriverPool initPool() {
    WebDriverPool pool = new WebDriverPool();
    // pool.setMaxTotalSize(3);
    pool.setCreator(new Function<BrowserProfile, WebDriver>() {

        @Override
        public WebDriver apply(BrowserProfile input) {
            // Start a local http proxy that we can use to control the
            // the connection's properties
            // ProxyController proxyController = new ProxyController();
            // proxyController.start();
            Map<String, String> environment = Maps.newHashMap();
            if (!Strings.isNullOrEmpty(System.getProperty("browserTimezone"))) {
                environment.put("TZ", System.getProperty("browserTimezone"));
            }
            ChromeDriverService service = new ChromeDriverService.Builder().usingAnyFreePort().usingDriverExecutable(findDriverBin()).withEnvironment(environment).build();
            ChromeOptions options = new ChromeOptions();
            options.addArguments("--verbose");
            // 
            DesiredCapabilities capabilities = new DesiredCapabilities();
            // capabilities.setCapability(CapabilityType.PROXY, proxyController.getWebDriverProxy());
            capabilities.setCapability(ChromeOptions.CAPABILITY, options);
            // return new ProxiedWebDriver(new ChromeDriver(capabilities), proxyController);
            return new ChromeDriver(service, capabilities);
        }
    });
    return pool;
}
Also used : WebDriver(org.openqa.selenium.WebDriver) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) ChromeDriverService(org.openqa.selenium.chrome.ChromeDriverService) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) Map(java.util.Map)

Example 2 with ChromeDriverService

use of org.openqa.selenium.chrome.ChromeDriverService in project NoraUi by NoraUi.

the class DriverFactory method generateGoogleChromeDriver.

/**
 * Generates a chrome webdriver.
 *
 * @return
 *         A chrome webdriver
 * @throws TechnicalException
 *             if an error occured when Webdriver setExecutable to true.
 */
private WebDriver generateGoogleChromeDriver() throws TechnicalException {
    final String pathWebdriver = DriverFactory.getPath(Driver.CHROME);
    if (!new File(pathWebdriver).setExecutable(true)) {
        throw new TechnicalException(Messages.getMessage(TechnicalException.TECHNICAL_ERROR_MESSAGE_WEBDRIVER_SET_EXECUTABLE));
    }
    logger.info("Generating Chrome driver ({}) ...", pathWebdriver);
    System.setProperty(Driver.CHROME.getDriverName(), pathWebdriver);
    final ChromeOptions chromeOptions = new ChromeOptions();
    final DesiredCapabilities capabilities = DesiredCapabilities.chrome();
    capabilities.setCapability(CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true);
    capabilities.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.ACCEPT);
    setLoggingLevel(capabilities);
    if (Context.isHeadless()) {
        chromeOptions.addArguments("--headless");
    }
    // Proxy configuration
    if (Context.getProxy().getProxyType() != ProxyType.UNSPECIFIED && Context.getProxy().getProxyType() != ProxyType.AUTODETECT) {
        capabilities.setCapability(CapabilityType.PROXY, Context.getProxy());
    }
    setChromeOptions(capabilities, chromeOptions);
    final String withWhitelistedIps = Context.getWebdriversProperties("withWhitelistedIps");
    if (withWhitelistedIps != null && !"".equals(withWhitelistedIps)) {
        final ChromeDriverService service = new ChromeDriverService.Builder().withWhitelistedIps(withWhitelistedIps).withVerbose(false).build();
        return new ChromeDriver(service, capabilities);
    } else {
        return new ChromeDriver(capabilities);
    }
}
Also used : TechnicalException(com.github.noraui.exception.TechnicalException) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) ChromeDriverService(org.openqa.selenium.chrome.ChromeDriverService) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) File(java.io.File)

Example 3 with ChromeDriverService

use of org.openqa.selenium.chrome.ChromeDriverService in project jmeter-plugins by undera.

the class ChromeDriverConfigTest method shouldNotStopServiceIfNotRunningWhenQuitBrowserIsInvoked.

@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();
}
Also used : ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) ChromeDriverService(org.openqa.selenium.chrome.ChromeDriverService) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with ChromeDriverService

use of org.openqa.selenium.chrome.ChromeDriverService in project jmeter-plugins by undera.

the class ChromeDriverConfigTest method shouldBeAbleToCallQuitBrowserMultipleTimes.

@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();
}
Also used : ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) ChromeDriverService(org.openqa.selenium.chrome.ChromeDriverService) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 5 with ChromeDriverService

use of org.openqa.selenium.chrome.ChromeDriverService in project jmeter-plugins by undera.

the class ChromeDriverConfig method quitBrowser.

@Override
public void quitBrowser(final ChromeDriver browser) {
    super.quitBrowser(browser);
    final ChromeDriverService service = services.remove(currentThreadName());
    if (service != null && service.isRunning()) {
        service.stop();
    }
}
Also used : ChromeDriverService(org.openqa.selenium.chrome.ChromeDriverService)

Aggregations

ChromeDriverService (org.openqa.selenium.chrome.ChromeDriverService)12 ChromeDriver (org.openqa.selenium.chrome.ChromeDriver)9 Test (org.junit.Test)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 File (java.io.File)4 ChromeOptions (org.openqa.selenium.chrome.ChromeOptions)4 DesiredCapabilities (org.openqa.selenium.remote.DesiredCapabilities)3 TechnicalException (com.github.noraui.exception.TechnicalException)1 SourceFile (com.google.javascript.jscomp.SourceFile)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Capabilities (org.openqa.selenium.Capabilities)1 WebDriver (org.openqa.selenium.WebDriver)1 LogEntry (org.openqa.selenium.logging.LogEntry)1 LoggingPreferences (org.openqa.selenium.logging.LoggingPreferences)1 RemoteWebDriver (org.openqa.selenium.remote.RemoteWebDriver)1