Java Code Examples for org.openqa.selenium.remote.http.HttpClient#Factory
The following examples show how to use
org.openqa.selenium.remote.http.HttpClient#Factory .
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: 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 2
Source File: RouterTest.java From selenium with Apache License 2.0 | 6 votes |
@Before public void setUp() { tracer = DefaultTestTracer.createTracer(); bus = new GuavaEventBus(); handler = new CombinedHandler(); HttpClient.Factory clientFactory = new PassthroughHttpClient.Factory(handler); sessions = new LocalSessionMap(tracer, bus); handler.addHandler(sessions); distributor = new LocalDistributor(tracer, bus, clientFactory, sessions, null); handler.addHandler(distributor); router = new Router(tracer, clientFactory, sessions, distributor); }
Example 3
Source File: CustomHttpCommandExecutor.java From hifive-pitalium with Apache License 2.0 | 5 votes |
public CustomHttpCommandExecutor(Map<String, CommandInfo> additionalCommands, URL addressOfRemoteServer, HttpClient.Factory httpClientFactory) { try { remoteServer = addressOfRemoteServer == null ? new URL(System.getProperty("webdriver.remote.server", "http://localhost:4444/wd/hub")) : addressOfRemoteServer; } catch (MalformedURLException e) { throw new WebDriverException(e); } this.additionalCommands = additionalCommands; this.client = httpClientFactory.createClient(remoteServer); }
Example 4
Source File: AppiumCommandExecutor.java From java-client with Apache License 2.0 | 5 votes |
private AppiumCommandExecutor(Map<String, CommandInfo> additionalCommands, DriverService service, URL addressOfRemoteServer, HttpClient.Factory httpClientFactory) { super(additionalCommands, ofNullable(service) .map(DriverService::getUrl) .orElse(addressOfRemoteServer), httpClientFactory); serviceOptional = ofNullable(service); }
Example 5
Source File: ChromiumDevToolsLocator.java From selenium with Apache License 2.0 | 5 votes |
public static Optional<URI> getCdpEndPoint( HttpClient.Factory clientFactory, URI reportedUri) { Require.nonNull("HTTP client factory", clientFactory); Require.nonNull("DevTools URI", reportedUri); ClientConfig config = ClientConfig.defaultConfig().baseUri(reportedUri); HttpClient client = clientFactory.createClient(config); HttpResponse res = client.execute(new HttpRequest(GET, "/json/version")); if (res.getStatus() != HTTP_OK) { return Optional.empty(); } Map<String, Object> versionData = JSON.toType(string(res), MAP_TYPE); Object raw = versionData.get("webSocketDebuggerUrl"); if (!(raw instanceof String)) { return Optional.empty(); } String debuggerUrl = (String) raw; try { return Optional.of(new URI(debuggerUrl)); } catch (URISyntaxException e) { LOG.warning("Invalid URI for endpoint " + raw); return Optional.empty(); } }
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: SeleniumCdpConnection.java From selenium with Apache License 2.0 | 5 votes |
public static Optional<Connection> create(HttpClient.Factory clientFactory, Capabilities capabilities) { Require.nonNull("HTTP client factory", clientFactory); Require.nonNull("Capabilities", capabilities); return getCdpUri(capabilities).map(uri -> new SeleniumCdpConnection( clientFactory.createClient(ClientConfig.defaultConfig().baseUri(uri)), uri.toString())); }
Example 8
Source File: NodeTest.java From selenium with Apache License 2.0 | 5 votes |
@Test public void shouldRefuseToCreateASessionIfNoFactoriesAttached() { Node local = LocalNode.builder(tracer, bus, uri, uri, null).build(); HttpClient.Factory clientFactory = new PassthroughHttpClient.Factory(local); Node node = new RemoteNode(tracer, clientFactory, UUID.randomUUID(), uri, ImmutableSet.of()); Optional<Session> session = node.newSession(createSessionRequest(caps)) .map(CreateSessionResponse::getSession); assertThat(session).isNotPresent(); }
Example 9
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 10
Source File: RemoteProxy.java From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 | 5 votes |
public static HttpCommandExecutor getProxyExecutor(URL url, Properties prop) { prop = decrypt(prop); String proxyHost = prop.getProperty("proxyHost"); int proxyPort = Integer.valueOf(prop.getProperty("proxyPort")); String proxyUserDomain = prop.getProperty("proxyUserDomain"); String proxyUser = prop.getProperty("proxyUser"); String proxyPassword = prop.getProperty("proxyPassword"); HttpClientBuilder builder = HttpClientBuilder.create(); HttpHost proxy = new HttpHost(proxyHost, proxyPort); CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope(proxyHost, proxyPort), new NTCredentials(proxyUser, proxyPassword, getWorkstation(), proxyUserDomain)); if (url.getUserInfo() != null && !url.getUserInfo().isEmpty()) { credsProvider.setCredentials(new AuthScope(url.getHost(), (url.getPort() > 0 ? url.getPort() : url.getDefaultPort())), new UsernamePasswordCredentials(proxyUser, proxyPassword)); } builder.setProxy(proxy); builder.setDefaultCredentialsProvider(credsProvider); //HttpClient.Factory factory = new SimpleHttpClientFactory(builder); HttpClient.Factory factory = new SimpleHttpClientFactory(new okhttp3.OkHttpClient.Builder()); return new HttpCommandExecutor(new HashMap<>(), url, factory); }
Example 11
Source File: Hub.java From selenium with Apache License 2.0 | 4 votes |
@Override protected void execute(Config config) { LoggingOptions loggingOptions = new LoggingOptions(config); Tracer tracer = loggingOptions.getTracer(); EventBusOptions events = new EventBusOptions(config); EventBus bus = events.getEventBus(); CombinedHandler handler = new CombinedHandler(); SessionMap sessions = new LocalSessionMap(tracer, bus); handler.addHandler(sessions); BaseServerOptions serverOptions = new BaseServerOptions(config); URL externalUrl; try { externalUrl = serverOptions.getExternalUri().toURL(); } catch (MalformedURLException e) { throw new IllegalArgumentException(e); } NetworkOptions networkOptions = new NetworkOptions(config); HttpClient.Factory clientFactory = new RoutableHttpClientFactory( externalUrl, handler, networkOptions.getHttpClientFactory(tracer)); Distributor distributor = new LocalDistributor( tracer, bus, clientFactory, sessions, null); handler.addHandler(distributor); Router router = new Router(tracer, clientFactory, sessions, distributor); GraphqlHandler graphqlHandler = new GraphqlHandler(distributor, serverOptions.getExternalUri()); HttpHandler readinessCheck = req -> { boolean ready = router.isReady() && bus.isReady(); return new HttpResponse() .setStatus(ready ? HTTP_OK : HTTP_INTERNAL_ERROR) .setContent(Contents.utf8String("Router is " + ready)); }; HttpHandler httpHandler = combine( router, Route.prefix("/wd/hub").to(combine(router)), Route.post("/graphql").to(() -> graphqlHandler), Route.get("/readyz").to(() -> readinessCheck)); Server<?> server = new NettyServer(serverOptions, httpHandler, new ProxyCdpIntoGrid(clientFactory, sessions)); server.start(); BuildInfo info = new BuildInfo(); LOG.info(String.format( "Started Selenium hub %s (revision %s): %s", info.getReleaseLabel(), info.getBuildRevision(), server.getUrl())); }
Example 12
Source File: EventFiringAppiumCommandExecutor.java From carina with Apache License 2.0 | 4 votes |
public EventFiringAppiumCommandExecutor(Map<String, CommandInfo> additionalCommands, DriverService service, HttpClient.Factory httpClientFactory) { this(additionalCommands, checkNotNull(service), null, httpClientFactory); }
Example 13
Source File: AppiumDriver.java From java-client with Apache License 2.0 | 4 votes |
public AppiumDriver(HttpClient.Factory httpClientFactory, Capabilities desiredCapabilities) { this(AppiumDriverLocalService.buildDefaultService(), httpClientFactory, desiredCapabilities); }
Example 14
Source File: EndToEndTest.java From selenium with Apache License 2.0 | 4 votes |
@Before public void setFields() { Object[] raw = values.get(); this.server = (Server<?>) raw[0]; this.clientFactory = (HttpClient.Factory) raw[1]; }
Example 15
Source File: AppiumCommandExecutor.java From java-client with Apache License 2.0 | 4 votes |
public AppiumCommandExecutor(Map<String, CommandInfo> additionalCommands, DriverService service, HttpClient.Factory httpClientFactory) { this(additionalCommands, checkNotNull(service), null, httpClientFactory); }
Example 16
Source File: EventFiringAppiumCommandExecutor.java From carina with Apache License 2.0 | 4 votes |
public EventFiringAppiumCommandExecutor(Map<String, CommandInfo> additionalCommands, URL addressOfRemoteServer, HttpClient.Factory httpClientFactory) { this(additionalCommands, null, checkNotNull(addressOfRemoteServer), httpClientFactory); }
Example 17
Source File: EndToEndTest.java From selenium with Apache License 2.0 | 4 votes |
private static Object[] createRemotes() throws URISyntaxException { Tracer tracer = DefaultTestTracer.createTracer(); EventBus bus = ZeroMqEventBus.create( new ZContext(), "tcp://localhost:" + PortProber.findFreePort(), "tcp://localhost:" + PortProber.findFreePort(), true); LocalSessionMap localSessions = new LocalSessionMap(tracer, bus); HttpClient.Factory clientFactory = HttpClient.Factory.createDefault(); Server<?> sessionServer = createServer(localSessions); sessionServer.start(); HttpClient client = HttpClient.Factory.createDefault().createClient(sessionServer.getUrl()); SessionMap sessions = new RemoteSessionMap(tracer, client); LocalDistributor localDistributor = new LocalDistributor( tracer, bus, clientFactory, sessions, null); Server<?> distributorServer = createServer(localDistributor); distributorServer.start(); Distributor distributor = new RemoteDistributor( tracer, HttpClient.Factory.createDefault(), distributorServer.getUrl()); int port = PortProber.findFreePort(); URI nodeUri = new URI("http://localhost:" + port); LocalNode localNode = LocalNode.builder(tracer, bus, nodeUri, nodeUri, null) .add(CAPS, createFactory(nodeUri)) .build(); Server<?> nodeServer = new NettyServer( new BaseServerOptions( new MapConfig(ImmutableMap.of("server", ImmutableMap.of("port", port)))), localNode); nodeServer.start(); distributor.add(localNode); Router router = new Router(tracer, clientFactory, sessions, distributor); Server<?> routerServer = createServer(router); routerServer.start(); return new Object[] { routerServer, clientFactory }; }
Example 18
Source File: AndroidDriver.java From java-client with Apache License 2.0 | 2 votes |
/** * Creates a new instance based on Appium driver local service, HTTP client factory and {@code capabilities}. * * @param service take a look at {@link AppiumDriverLocalService} * @param httpClientFactory take a look at {@link HttpClient.Factory} * @param desiredCapabilities take a look at {@link Capabilities} */ public AndroidDriver(AppiumDriverLocalService service, HttpClient.Factory httpClientFactory, Capabilities desiredCapabilities) { super(service, httpClientFactory, updateDefaultPlatformName(desiredCapabilities, ANDROID_PLATFORM)); }
Example 19
Source File: IOSDriver.java From java-client with Apache License 2.0 | 2 votes |
/** * Creates a new instance based on Appium driver local service, HTTP client factory and {@code capabilities}. * * @param service take a look at {@link AppiumDriverLocalService} * @param httpClientFactory take a look at {@link HttpClient.Factory} * @param desiredCapabilities take a look at {@link Capabilities} */ public IOSDriver(AppiumDriverLocalService service, HttpClient.Factory httpClientFactory, Capabilities desiredCapabilities) { super(service, httpClientFactory, updateDefaultPlatformName(desiredCapabilities, IOS_DEFAULT_PLATFORM)); }
Example 20
Source File: IOSDriver.java From java-client with Apache License 2.0 | 2 votes |
/** * Creates a new instance based on HTTP client factory and {@code capabilities}. * * @param httpClientFactory take a look at {@link HttpClient.Factory} * @param desiredCapabilities take a look at {@link Capabilities} */ public IOSDriver(HttpClient.Factory httpClientFactory, Capabilities desiredCapabilities) { super(httpClientFactory, updateDefaultPlatformName(desiredCapabilities, IOS_DEFAULT_PLATFORM)); }