Java 类org.openqa.selenium.remote.service.DriverService 实例源码

项目:bromium    文件:DefaultModule.java   
private ProxyDriverIntegrator getProxyDriverIntegrator(RequestFilter recordRequestFilter,
                                                       WebDriverSupplier webDriverSupplier,
                                                       DriverServiceSupplier driverServiceSupplier,
                                                       @Named(PATH_TO_DRIVER) String pathToDriverExecutable,
                                                       @Named(SCREEN) String screen,
                                                       @Named(TIMEOUT) int timeout,
                                                       ResponseFilter responseFilter) throws IOException {
    BrowserMobProxy proxy = createBrowserMobProxy(timeout, recordRequestFilter, responseFilter);
    proxy.start(0);
    logger.info("Proxy running on port " + proxy.getPort());
    Proxy seleniumProxy = createSeleniumProxy(proxy);
    DesiredCapabilities desiredCapabilities = createDesiredCapabilities(seleniumProxy);
    DriverService driverService = driverServiceSupplier.getDriverService(pathToDriverExecutable, screen);
    WebDriver driver = webDriverSupplier.get(driverService, desiredCapabilities);

    return new ProxyDriverIntegrator(driver, proxy, driverService);
}
项目:de.lgohlke.selenium-webdriver    文件:RemoteWebdriverInitialConnectionRetryer.java   
public WebDriver start(DriverServiceFactory factory, DriverService driverService) {
    WebDriver driver = null;
    for (int i = 0; i < retries && driver == null; i++) {
        log.info("trying to start {}/{} (attempt/max attempts)", i, retries);
        driver = startServiceAndCreateWebdriver(driverService, factory);
        log.info("is started: {}", driver == null);
        if (driver == null) {
            try {
                timeUnit.sleep(2);
            } catch (InterruptedException e) {
                log.error(e.getMessage(), e);
            }
        }
    }
    return driver;
}
项目:minium    文件:DriverServiceProperties.java   
public final DriverService getDriverService() {
    try {
        if (driverService == null) {
            driverService = createDriverService();
            wasRunning = driverService.isRunning();
            if (wasRunning) {
                LOGGER.info("Driver service {} is already running", driverService.getUrl());
            } else {
                driverService.start();
                LOGGER.info("Driver service {} started", driverService.getUrl());
            }
        }
        return driverService;
    } catch (IOException e) {
        throw Throwables.propagate(e);
    }
}
项目:jspider    文件:WebDriverFactory.java   
public WebDriverEx createWebDriver(DriverService driverService,
                                      DesiredCapabilities desiredCapabilities,
                                      SiteConfig siteConfig,
                                      DriverConfig driverConfig) throws IOException {
    driverService.start();

    //自定义HttpClientFactory用于设置命令超时时间
    ApacheHttpClient.Factory httpClientFactory = createHttpClientFactory(siteConfig, driverConfig);
    HttpCommandExecutor httpCommandExecutor = new HttpCommandExecutor(
            ImmutableMap.<String, CommandInfo>of(), driverService.getUrl(), httpClientFactory);
    WebDriverEx webDriver = new WebDriverEx(httpCommandExecutor, desiredCapabilities);
    webDriver.setDriverService(driverService);
    webDriver.setCreatedTime(new Date());

    webDriver.manage().timeouts().implicitlyWait(driverConfig.getImplicitlyWait(), TimeUnit.MILLISECONDS);
    webDriver.manage().timeouts().pageLoadTimeout(driverConfig.getPageLoadTimeout(), TimeUnit.MILLISECONDS);
    webDriver.manage().timeouts().setScriptTimeout(driverConfig.getScriptTimeout(), TimeUnit.MILLISECONDS);

    return webDriver;
}
项目:bromium    文件:DriverServiceSupplierBase.java   
@Override
public DriverService getDriverService(String pathToDriverExecutable, String screenToUse) throws IOException {
    return getBuilder()
            .usingDriverExecutable(new File(pathToDriverExecutable))
            .usingAnyFreePort()
            .withEnvironment(ImmutableMap.of("DISPLAY", screenToUse))
            .build();
}
项目:bromium    文件:DriverServiceSupplierBaseTest.java   
@Test
public void invokesTheCorrectMethodsOfTheBuilder() throws IOException {
    DriverService.Builder builder = mock(DriverService.Builder.class, RETURNS_DEEP_STUBS);

    DriverServiceSupplierBase driverServiceSupplierBase = new DriverServiceSupplierBase() {
        @Override
        protected DriverService.Builder getBuilder() {
            return builder;
        }
    };

    DriverService driverService = driverServiceSupplierBase.getDriverService(driverExecutableFileName, screenToUse);

    verify(builder).usingDriverExecutable(eq(driverExecutableFile));
}
项目:bromium    文件:ProxyDriverIntegratorTest.java   
@Test
public void providesAccessToConnectedDriverProxyAndDriverService() {
    WebDriver driver = mock(WebDriver.class);
    BrowserMobProxy proxy = mock(BrowserMobProxy.class);
    DriverService driverService = mock(DriverService.class);

    ProxyDriverIntegrator proxyDriverIntegrator = new ProxyDriverIntegrator(driver, proxy, driverService);

    assertEquals(driver, proxyDriverIntegrator.getWebDriver());
    assertEquals(proxy, proxyDriverIntegrator.getProxy());
    assertEquals(driverService, proxyDriverIntegrator.getDriverService());
}
项目:de.lgohlke.selenium-webdriver    文件:RemoteWebdriverInitialConnectionRetryer.java   
private WebDriver startServiceAndCreateWebdriver(DriverService driverService, DriverServiceFactory factory) {
    ExecutorService service = Executors.newFixedThreadPool(1);

    @SuppressWarnings("unchecked")
    Callable<WebDriver> startJob = () -> {
        if (!driverService.isRunning()) {
            log.info("starting");
            driverService.start();
        }
        log.info("try to create webdriver");
        return factory.createWebDriver(driverService);
    };

    Future<WebDriver> startFuture = service.submit(startJob);
    try {
        log.info("waiting for webdriver");
        return startFuture.get(timeout, timeUnit);
    } catch (ExecutionException | InterruptedException | TimeoutException e) {
        log.warn(e.getMessage(), e);
        if (driverService.isRunning()) {
            driverService.stop();
        }
    } finally {
        service.shutdownNow();
    }
    return null;
}
项目:dawg    文件:BrowserServiceManager.java   
/**
 * Gets a web driver for a given browser
 * @param browser The browser to get a driver for
 * @return
 * @throws IOException
 */
public static synchronized RemoteWebDriver getDriver(Browser browser) throws IOException {
    if (global == null) {
        DriverService service = start(browser);
        global = new RemoteWebDriver(service.getUrl(), getDesiredBrowserCapabilities(browser));
        drivers.put(global, service);
    }
    return global;
}
项目:dawg    文件:BrowserServiceManager.java   
/**
 * Starts a selenium service for a given browser
 * @param browser The browser to start the service for
 * @return
 * @throws IOException
 */
public static DriverService start(Browser browser) throws IOException {
    BrowserDriverProvider provider = getProvider(browser);
    DriverService service = new ChromeDriverService.Builder().usingDriverExecutable(provider.getDriverFile()).usingAnyFreePort().build();
    service.start();
    return service;
}
项目:minium    文件:ChromeDriverServiceProperties.java   
@Override
protected DriverService createDriverService() {
    Builder builder = new ChromeDriverService.Builder();
    if (port != null) builder.usingPort(port);
    if (driverExecutable != null) builder.usingDriverExecutable(driverExecutable);
    if (environment != null) builder.withEnvironment(environment);
    if (logFile != null) builder.withLogFile(logFile);
    if (verbose != null) builder.withVerbose(verbose);
    if (silent != null) builder.withSilent(silent);
    return builder.build();
}
项目:minium    文件:FirefoxDriverServiceProperties.java   
@Override
protected DriverService createDriverService() {
    Builder builder = new GeckoDriverService.Builder();
    if (port != null) builder.usingPort(port);
    if (driverExecutable != null) builder.usingDriverExecutable(driverExecutable);
    if (environment != null) builder.withEnvironment(environment);
    if (logFile != null) builder.withLogFile(logFile);
    return builder.build();
}
项目:minium    文件:PhantomJsDriverServiceProperties.java   
@Override
public DriverService createDriverService() {
    Builder builder = new PhantomJSDriverService.Builder();

    if (driverExecutable != null) builder.usingPhantomJSExecutable(driverExecutable);
    if (ghostDriver != null) builder.usingGhostDriver(ghostDriver);
    if (port != null) builder.usingPort(port);
    if (environment != null) builder.withEnvironment(environment);
    if (logFile != null) builder.withLogFile(logFile);
    if (proxy != null) builder.withProxy(new Proxy(proxy));
    if (commandLineArguments != null) builder.usingCommandLineArguments(commandLineArguments);
    if (ghostDriverCommandLineArguments != null) builder.usingGhostDriverCommandLineArguments(ghostDriverCommandLineArguments);

    return builder.build();
}
项目:minium    文件:InternetExplorerDriverServiceProperties.java   
@Override
public DriverService createDriverService() {
    Builder builder = new InternetExplorerDriverService.Builder();
    if (port != null) builder.usingPort(port);
    if (driverExecutable != null) builder.usingDriverExecutable(driverExecutable);
    if (environment != null) builder.withEnvironment(environment);
    if (logFile != null) builder.withLogFile(logFile);
    if (logLevel != null) builder.withLogLevel(InternetExplorerDriverLogLevel.valueOf(logLevel.toUpperCase()));
    if (engineImplementation != null) builder.withEngineImplementation(InternetExplorerDriverEngine.valueOf(engineImplementation.toUpperCase()));
    if (host != null) builder.withHost(host);
    if (extractPath != null) builder.withExtractPath(extractPath);
    if (silent != null) builder.withSilent(silent);
    return builder.build();
}
项目:minium    文件:WebDriverFactory.java   
@Override
public WebDriver create(WebDriverFactory webDriverFactory, DesiredCapabilities desiredCapabilities) {
    ChromeDriverServiceProperties serviceProperties = webDriverFactory.driverServices == null ? null : webDriverFactory.driverServices.getChrome();
    DriverService driverService = serviceProperties == null ? null : serviceProperties.getDriverService();
    return driverService == null ?
            new ChromeDriver(new ChromeOptions().merge(desiredCapabilities))
            : new RemoteWebDriver(driverService.getUrl(), desiredCapabilities);
}
项目:minium    文件:WebDriverFactory.java   
@Override
public WebDriver create(WebDriverFactory webDriverFactory, DesiredCapabilities desiredCapabilities) {
    FirefoxDriverServiceProperties serviceProperties = webDriverFactory.driverServices == null ? null : webDriverFactory.driverServices.getFirefox();
    DriverService driverService = serviceProperties == null ? null : serviceProperties.getDriverService();
    FirefoxOptions firefoxOptions = new FirefoxOptions().merge(desiredCapabilities);
    return driverService == null ? new FirefoxDriver(firefoxOptions) : new RemoteWebDriver(driverService.getUrl(), firefoxOptions);
}
项目:minium    文件:WebDriverFactory.java   
@Override
public WebDriver create(WebDriverFactory webDriverFactory, DesiredCapabilities desiredCapabilities) {
    InternetExplorerDriverServiceProperties serviceProperties = webDriverFactory.driverServices == null ? null : webDriverFactory.driverServices.getInternetExplorer();
    DriverService driverService = serviceProperties == null ? null : serviceProperties.getDriverService();
    InternetExplorerOptions internetExplorerOptions = new InternetExplorerOptions().merge(desiredCapabilities);
    return driverService == null ? new InternetExplorerDriver(internetExplorerOptions) : new RemoteWebDriver(driverService.getUrl(), internetExplorerOptions);
}
项目:jspider    文件:WebDriverEx.java   
public DriverService getDriverService() {
    return driverService;
}
项目:jspider    文件:WebDriverEx.java   
public void setDriverService(DriverService driverService) {
    this.driverService = driverService;
}
项目:bromium    文件:ProxyDriverIntegrator.java   
public DriverService getDriverService() {
    return driverService;
}
项目:bromium    文件:ChromeDriverServiceSupplier.java   
@Override
protected DriverService.Builder getBuilder() {
    return new ChromeDriverService.Builder();
}
项目:menggeqa    文件:AppiumCommandExecutor.java   
public AppiumCommandExecutor(Map<String, CommandInfo> additionalCommands, DriverService service,
    HttpClient.Factory httpClientFactory) {
    super(additionalCommands, service.getUrl(), httpClientFactory);
    this.service = service;
}
项目:menggeqa    文件:AppiumCommandExecutor.java   
public AppiumCommandExecutor(Map<String, CommandInfo> additionalCommands,
    DriverService service) {
    this(additionalCommands, service, new ApacheHttpClient.Factory());
}
项目:domui    文件:MyChromeDriverCommandExecutor.java   
public MyChromeDriverCommandExecutor(DriverService service) {
    super(service, CHROME_COMMAND_NAME_TO_URL);
}
项目:de.lgohlke.selenium-webdriver    文件:ChromeDriverServiceFactoryTest.java   
@SuppressWarnings("unchecked")
private Map<String, String> getEnvFromDriverService(ChromeDriverService service) throws NoSuchFieldException, IllegalAccessException {
    Field field = DriverService.class.getDeclaredField("environment");
    field.setAccessible(true);
    return (Map<String, String>) field.get(service);
}
项目:minium    文件:WebDriverFactory.java   
@Override
public WebDriver create(WebDriverFactory webDriverFactory, DesiredCapabilities desiredCapabilities) {
    PhantomJsDriverServiceProperties serviceProperties = webDriverFactory.driverServices == null ? null : webDriverFactory.driverServices.getPhantomJs();
    DriverService driverService = serviceProperties == null ? null : serviceProperties.getDriverService();
    return driverService == null ? new PhantomJSDriver(desiredCapabilities) : new RemoteWebDriver(driverService.getUrl(), desiredCapabilities);
}
项目:bromium    文件:ProxyDriverIntegrator.java   
/**
 * Creates a new object that holds  a driver, a proxy and a driver service that are connected together
 * @param driver the driver
 * @param proxy the proxy that the driver uses
 * @param driverService the driver service that is used for connecting to the virtual screen
 */
public ProxyDriverIntegrator(WebDriver driver, BrowserMobProxy proxy, DriverService driverService) {
    this.driver = driver;
    this.proxy = proxy;
    this.driverService = driverService;
}
项目:bromium    文件:DriverServiceSupplier.java   
DriverService getDriverService(String pathToDriverExecutable, String screenToUse) throws IOException;
项目:bromium    文件:DriverServiceSupplierBase.java   
protected abstract DriverService.Builder getBuilder();
项目:minium    文件:DriverServiceProperties.java   
protected abstract DriverService createDriverService();