Java Code Examples for org.openqa.selenium.remote.service.DriverService#Builder
The following examples show how to use
org.openqa.selenium.remote.service.DriverService#Builder .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BrowserServer.java From agent with MIT License | 6 votes |
@Override public synchronized void start() { if (isRunning) { return; } try { DriverService.Builder builder = builderClass.newInstance(); builder.usingDriverExecutable(driverFile); int port = PortProvider.getPcDriverServiceAvailablePort(); builder.usingPort(port); driverService = builder.build(); log.info("start driver service, port: {}, driverFile: {}", port, driverFile.getAbsolutePath()); driverService.start(); url = driverService.getUrl(); isRunning = driverService.isRunning(); } catch (Exception e) { throw new RuntimeException("启动driver service失败", e); } }
Example 2
Source File: LocalNodeFactory.java From selenium with Apache License 2.0 | 6 votes |
private static Collection<SessionFactory> createSessionFactory( Tracer tracer, HttpClient.Factory clientFactory, List<DriverService.Builder<?, ?>> builders, WebDriverInfo info) { ImmutableList.Builder<SessionFactory> toReturn = ImmutableList.builder(); Capabilities caps = info.getCanonicalCapabilities(); builders.stream() .filter(builder -> builder.score(caps) > 0) .forEach(builder -> { DriverService.Builder<?, ?> freePortBuilder = builder.usingAnyFreePort(); toReturn.add(new DriverServiceSessionFactory( tracer, clientFactory, c -> freePortBuilder.score(c) > 0, freePortBuilder)); }); return toReturn.build(); }
Example 3
Source File: DriverServiceSupplierBaseTest.java From bromium with MIT License | 5 votes |
@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)); }
Example 4
Source File: RemoteWebDriverBuilder.java From selenium with Apache License 2.0 | 5 votes |
DriverService getDriverService() { if (service != null) { return service; } ServiceLoader<DriverService.Builder> allLoaders = ServiceLoader.load(DriverService.Builder.class); // We need to extract each of the capabilities from the payload. return options .stream() .map(HashMap::new) // Make a copy so we don't alter the original values .peek(map -> map.putAll(additionalCapabilities)) .map(ImmutableCapabilities::new) .map( caps -> StreamSupport.stream(allLoaders.spliterator(), true) .filter(builder -> builder.score(caps) > 0) .findFirst() .orElse(null)) .filter(Objects::nonNull) .map( bs -> { try { return bs.build(); } catch (Throwable e) { return null; } }) .filter(Objects::nonNull) .findFirst() .orElseThrow(() -> new IllegalStateException("Unable to find a driver service")); }
Example 5
Source File: LocalNodeFactory.java From selenium with Apache License 2.0 | 5 votes |
public static Node create(Config config) { LoggingOptions loggingOptions = new LoggingOptions(config); EventBusOptions eventOptions = new EventBusOptions(config); BaseServerOptions serverOptions = new BaseServerOptions(config); NodeOptions nodeOptions = new NodeOptions(config); NetworkOptions networkOptions = new NetworkOptions(config); Tracer tracer = loggingOptions.getTracer(); HttpClient.Factory clientFactory = networkOptions.getHttpClientFactory(tracer); LocalNode.Builder builder = LocalNode.builder( tracer, eventOptions.getEventBus(), serverOptions.getExternalUri(), nodeOptions.getPublicGridUri().orElseGet(serverOptions::getExternalUri), serverOptions.getRegistrationSecret()); List<DriverService.Builder<?, ?>> builders = new ArrayList<>(); ServiceLoader.load(DriverService.Builder.class).forEach(builders::add); nodeOptions.getSessionFactories(info -> createSessionFactory(tracer, clientFactory, builders, info)) .forEach((caps, factories) -> factories.forEach(factory -> builder.add(caps, factory))); new DockerOptions(config).getDockerSessionFactories(tracer, clientFactory) .forEach((caps, factories) -> factories.forEach(factory -> builder.add(caps, factory))); return builder.build(); }
Example 6
Source File: DriverServiceSessionFactory.java From selenium with Apache License 2.0 | 5 votes |
public DriverServiceSessionFactory( Tracer tracer, HttpClient.Factory clientFactory, Predicate<Capabilities> predicate, DriverService.Builder builder) { this.tracer = Require.nonNull("Tracer", tracer); this.clientFactory = Require.nonNull("HTTP client factory", clientFactory); this.predicate = Require.nonNull("Accepted capabilities predicate", predicate); this.builder = Require.nonNull("Driver service bulder", builder); }
Example 7
Source File: NodeOptions.java From selenium with Apache License 2.0 | 5 votes |
private Map<WebDriverInfo, Collection<SessionFactory>> discoverDrivers( int maxSessions, Function<WebDriverInfo, Collection<SessionFactory>> factoryFactory) { if (!config.getBool("node", "detect-drivers").orElse(false)) { return ImmutableMap.of(); } // We don't expect duplicates, but they're fine List<WebDriverInfo> infos = StreamSupport.stream(ServiceLoader.load(WebDriverInfo.class).spliterator(), false) .filter(WebDriverInfo::isAvailable) .sorted(Comparator.comparing(info -> info.getDisplayName().toLowerCase())) .collect(Collectors.toList()); // Same List<DriverService.Builder<?, ?>> builders = new ArrayList<>(); ServiceLoader.load(DriverService.Builder.class).forEach(builders::add); Multimap<WebDriverInfo, SessionFactory> toReturn = HashMultimap.create(); infos.forEach(info -> { Capabilities caps = info.getCanonicalCapabilities(); builders.stream() .filter(builder -> builder.score(caps) > 0) .forEach(builder -> { for (int i = 0; i < Math.min(info.getMaximumSimultaneousSessions(), maxSessions); i++) { toReturn.putAll(info, factoryFactory.apply(info)); } }); }); return toReturn.asMap(); }
Example 8
Source File: ChromeDriverServiceSupplier.java From bromium with MIT License | 4 votes |
@Override protected DriverService.Builder getBuilder() { return new ChromeDriverService .Builder(); }
Example 9
Source File: DriverServiceSessionFactoryTest.java From selenium with Apache License 2.0 | 4 votes |
private DriverServiceSessionFactory factoryFor(String browser, DriverService.Builder builder) { Predicate<Capabilities> predicate = c -> c.getBrowserName().equals(browser); return new DriverServiceSessionFactory(tracer, clientFactory, predicate, builder); }
Example 10
Source File: DriverServiceSupplierBase.java From bromium with MIT License | votes |
protected abstract DriverService.Builder getBuilder();