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;
}
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);
}
}
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();
}
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();
}
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();
}
}
Aggregations