org.openqa.selenium.chrome.ChromeDriverService#start ( )源码实例Demo

下面列出了org.openqa.selenium.chrome.ChromeDriverService#start ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: selenium   文件: TestChromeDriver.java
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);
  }
}
 
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;
}