下面列出了org.openqa.selenium.chrome.ChromeDriverService#createDefaultService ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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);
}
}
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);
}
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;
}
public ChromeDriverEx(Capabilities capabilities) {
this(ChromeDriverService.createDefaultService(), capabilities);
}
@BeforeClass
public static void setupClass() throws Exception {
service = ChromeDriverService.createDefaultService();
service.start();
}
@BeforeClass
public static void setupClass() throws Exception {
service = ChromeDriverService.createDefaultService();
service.start();
}
@BeforeClass
public static void setupClass() throws Exception {
service = ChromeDriverService.createDefaultService();
service.start();
}
/**
* Creates a new ChromeDriver using the {@link ChromeDriverService#createDefaultService default}
* server configuration.
*
* @see #ChromeDriver(ChromeDriverService, ChromeOptions)
*/
public ChromeDriver() {
this(ChromeDriverService.createDefaultService(), new ChromeOptions());
}
/**
* Creates a new ChromeDriver instance. The {@code capabilities} will be passed to the
* ChromeDriver service.
*
* @param capabilities The capabilities required from the ChromeDriver.
* @see #ChromeDriver(ChromeDriverService, Capabilities)
* @deprecated Use {@link ChromeDriver(ChromeOptions)} instead.
*/
@Deprecated
public ChromeDriver(Capabilities capabilities) {
this(ChromeDriverService.createDefaultService(), capabilities);
}