How to use Secret class of org.openqa.selenium.grid.security package

Best Selenium code snippet using org.openqa.selenium.grid.security.Secret

Source:Standalone.java Github

copy

Full Screen

...33import org.openqa.selenium.grid.node.ProxyNodeCdp;34import org.openqa.selenium.grid.node.config.NodeOptions;35import org.openqa.selenium.grid.router.Router;36import org.openqa.selenium.grid.security.BasicAuthenticationFilter;37import org.openqa.selenium.grid.security.Secret;38import org.openqa.selenium.grid.security.SecretOptions;39import org.openqa.selenium.grid.server.BaseServerOptions;40import org.openqa.selenium.grid.server.EventBusOptions;41import org.openqa.selenium.grid.server.NetworkOptions;42import org.openqa.selenium.grid.server.Server;43import org.openqa.selenium.grid.sessionmap.SessionMap;44import org.openqa.selenium.grid.sessionmap.local.LocalSessionMap;45import org.openqa.selenium.grid.sessionqueue.NewSessionQueue;46import org.openqa.selenium.grid.sessionqueue.config.SessionRequestOptions;47import org.openqa.selenium.grid.sessionqueue.local.LocalNewSessionQueue;48import org.openqa.selenium.grid.web.CombinedHandler;49import org.openqa.selenium.grid.web.GridUiRoute;50import org.openqa.selenium.grid.web.RoutableHttpClientFactory;51import org.openqa.selenium.internal.Require;52import org.openqa.selenium.remote.http.Contents;53import org.openqa.selenium.remote.http.HttpClient;54import org.openqa.selenium.remote.http.HttpHandler;55import org.openqa.selenium.remote.http.HttpResponse;56import org.openqa.selenium.remote.http.Routable;57import org.openqa.selenium.remote.http.Route;58import org.openqa.selenium.remote.tracing.Tracer;59import java.net.MalformedURLException;60import java.net.URI;61import java.net.URL;62import java.util.Collections;63import java.util.Set;64import java.util.logging.Logger;65import static java.net.HttpURLConnection.HTTP_INTERNAL_ERROR;66import static java.net.HttpURLConnection.HTTP_OK;67import static org.openqa.selenium.grid.config.StandardGridRoles.DISTRIBUTOR_ROLE;68import static org.openqa.selenium.grid.config.StandardGridRoles.HTTPD_ROLE;69import static org.openqa.selenium.grid.config.StandardGridRoles.NODE_ROLE;70import static org.openqa.selenium.grid.config.StandardGridRoles.ROUTER_ROLE;71import static org.openqa.selenium.grid.config.StandardGridRoles.SESSION_QUEUE_ROLE;72import static org.openqa.selenium.remote.http.Route.combine;73@AutoService(CliCommand.class)74public class Standalone extends TemplateGridServerCommand {75 private static final Logger LOG = Logger.getLogger("selenium");76 @Override77 public String getName() {78 return "standalone";79 }80 @Override81 public String getDescription() {82 return "The selenium server, running everything in-process.";83 }84 @Override85 public Set<Role> getConfigurableRoles() {86 return ImmutableSet.of(DISTRIBUTOR_ROLE, HTTPD_ROLE, NODE_ROLE, ROUTER_ROLE, SESSION_QUEUE_ROLE);87 }88 @Override89 public Set<Object> getFlagObjects() {90 return Collections.singleton(new StandaloneFlags());91 }92 @Override93 protected String getSystemPropertiesConfigPrefix() {94 return "selenium";95 }96 @Override97 protected Config getDefaultConfig() {98 return new DefaultStandaloneConfig();99 }100 @Override101 protected Handlers createHandlers(Config config) {102 LoggingOptions loggingOptions = new LoggingOptions(config);103 Tracer tracer = loggingOptions.getTracer();104 EventBusOptions events = new EventBusOptions(config);105 EventBus bus = events.getEventBus();106 BaseServerOptions serverOptions = new BaseServerOptions(config);107 SecretOptions secretOptions = new SecretOptions(config);108 Secret registrationSecret = secretOptions.getRegistrationSecret();109 URI localhost = serverOptions.getExternalUri();110 URL localhostUrl;111 try {112 localhostUrl = localhost.toURL();113 } catch (MalformedURLException e) {114 throw new IllegalArgumentException(e);115 }116 NetworkOptions networkOptions = new NetworkOptions(config);117 CombinedHandler combinedHandler = new CombinedHandler();118 HttpClient.Factory clientFactory = new RoutableHttpClientFactory(119 localhostUrl,120 combinedHandler,121 networkOptions.getHttpClientFactory(tracer));122 SessionMap sessions = new LocalSessionMap(tracer, bus);123 combinedHandler.addHandler(sessions);124 DistributorOptions distributorOptions = new DistributorOptions(config);125 SessionRequestOptions sessionRequestOptions = new SessionRequestOptions(config);126 NewSessionQueue queue = new LocalNewSessionQueue(127 tracer,128 bus,129 distributorOptions.getSlotMatcher(),130 sessionRequestOptions.getSessionRequestRetryInterval(),131 sessionRequestOptions.getSessionRequestTimeout(),132 registrationSecret);133 combinedHandler.addHandler(queue);134 Distributor distributor = new LocalDistributor(135 tracer,136 bus,137 clientFactory,138 sessions,139 queue,140 distributorOptions.getSlotSelector(),141 registrationSecret,142 distributorOptions.getHealthCheckInterval(),143 distributorOptions.shouldRejectUnsupportedCaps());144 combinedHandler.addHandler(distributor);145 Routable router = new Router(tracer, clientFactory, sessions, queue, distributor)146 .with(networkOptions.getSpecComplianceChecks());147 HttpHandler readinessCheck = req -> {148 boolean ready = sessions.isReady() && distributor.isReady() && bus.isReady();149 return new HttpResponse()150 .setStatus(ready ? HTTP_OK : HTTP_INTERNAL_ERROR)151 .setContent(Contents.utf8String("Standalone is " + ready));152 };153 GraphqlHandler graphqlHandler = new GraphqlHandler(154 tracer,155 distributor,...

Full Screen

Full Screen

Source:Hub.java Github

copy

Full Screen

...31import org.openqa.selenium.grid.log.LoggingOptions;32import org.openqa.selenium.grid.router.ProxyCdpIntoGrid;33import org.openqa.selenium.grid.router.Router;34import org.openqa.selenium.grid.security.BasicAuthenticationFilter;35import org.openqa.selenium.grid.security.Secret;36import org.openqa.selenium.grid.security.SecretOptions;37import org.openqa.selenium.grid.server.BaseServerOptions;38import org.openqa.selenium.grid.server.EventBusOptions;39import org.openqa.selenium.grid.server.NetworkOptions;40import org.openqa.selenium.grid.server.Server;41import org.openqa.selenium.grid.sessionmap.SessionMap;42import org.openqa.selenium.grid.sessionmap.local.LocalSessionMap;43import org.openqa.selenium.grid.sessionqueue.NewSessionQueue;44import org.openqa.selenium.grid.sessionqueue.config.SessionRequestOptions;45import org.openqa.selenium.grid.sessionqueue.local.LocalNewSessionQueue;46import org.openqa.selenium.grid.web.CombinedHandler;47import org.openqa.selenium.grid.web.GridUiRoute;48import org.openqa.selenium.grid.web.RoutableHttpClientFactory;49import org.openqa.selenium.internal.Require;50import org.openqa.selenium.remote.http.Contents;51import org.openqa.selenium.remote.http.HttpClient;52import org.openqa.selenium.remote.http.HttpHandler;53import org.openqa.selenium.remote.http.HttpResponse;54import org.openqa.selenium.remote.http.Routable;55import org.openqa.selenium.remote.http.Route;56import org.openqa.selenium.remote.tracing.Tracer;57import java.net.MalformedURLException;58import java.net.URL;59import java.util.Collections;60import java.util.Set;61import java.util.logging.Logger;62import static java.net.HttpURLConnection.HTTP_INTERNAL_ERROR;63import static java.net.HttpURLConnection.HTTP_OK;64import static org.openqa.selenium.grid.config.StandardGridRoles.DISTRIBUTOR_ROLE;65import static org.openqa.selenium.grid.config.StandardGridRoles.EVENT_BUS_ROLE;66import static org.openqa.selenium.grid.config.StandardGridRoles.HTTPD_ROLE;67import static org.openqa.selenium.grid.config.StandardGridRoles.ROUTER_ROLE;68import static org.openqa.selenium.grid.config.StandardGridRoles.SESSION_QUEUE_ROLE;69import static org.openqa.selenium.remote.http.Route.combine;70@AutoService(CliCommand.class)71public class Hub extends TemplateGridServerCommand {72 private static final Logger LOG = Logger.getLogger(Hub.class.getName());73 @Override74 public String getName() {75 return "hub";76 }77 @Override78 public String getDescription() {79 return "A grid hub, composed of sessions, distributor, and router.";80 }81 @Override82 public Set<Role> getConfigurableRoles() {83 return ImmutableSet.of(84 DISTRIBUTOR_ROLE,85 EVENT_BUS_ROLE,86 HTTPD_ROLE,87 SESSION_QUEUE_ROLE,88 ROUTER_ROLE);89 }90 @Override91 public Set<Object> getFlagObjects() {92 return Collections.emptySet();93 }94 @Override95 protected String getSystemPropertiesConfigPrefix() {96 return "selenium";97 }98 @Override99 protected Config getDefaultConfig() {100 return new DefaultHubConfig();101 }102 @Override103 protected Handlers createHandlers(Config config) {104 LoggingOptions loggingOptions = new LoggingOptions(config);105 Tracer tracer = loggingOptions.getTracer();106 EventBusOptions events = new EventBusOptions(config);107 EventBus bus = events.getEventBus();108 CombinedHandler handler = new CombinedHandler();109 SessionMap sessions = new LocalSessionMap(tracer, bus);110 handler.addHandler(sessions);111 BaseServerOptions serverOptions = new BaseServerOptions(config);112 SecretOptions secretOptions = new SecretOptions(config);113 Secret secret = secretOptions.getRegistrationSecret();114 URL externalUrl;115 try {116 externalUrl = serverOptions.getExternalUri().toURL();117 } catch (MalformedURLException e) {118 throw new IllegalArgumentException(e);119 }120 NetworkOptions networkOptions = new NetworkOptions(config);121 HttpClient.Factory clientFactory = new RoutableHttpClientFactory(122 externalUrl,123 handler,124 networkOptions.getHttpClientFactory(tracer));125 DistributorOptions distributorOptions = new DistributorOptions(config);126 SessionRequestOptions sessionRequestOptions = new SessionRequestOptions(config);127 NewSessionQueue queue = new LocalNewSessionQueue(...

Full Screen

Full Screen

Source:RemoteNewSessionQueue.java Github

copy

Full Screen

...21import org.openqa.selenium.grid.data.CreateSessionResponse;22import org.openqa.selenium.grid.data.RequestId;23import org.openqa.selenium.grid.data.SessionRequestCapability;24import org.openqa.selenium.grid.log.LoggingOptions;25import org.openqa.selenium.grid.security.AddSecretFilter;26import org.openqa.selenium.grid.security.Secret;27import org.openqa.selenium.grid.security.SecretOptions;28import org.openqa.selenium.grid.server.NetworkOptions;29import org.openqa.selenium.grid.sessionqueue.NewSessionQueue;30import org.openqa.selenium.grid.data.SessionRequest;31import org.openqa.selenium.grid.sessionqueue.config.NewSessionQueueOptions;32import org.openqa.selenium.grid.web.Values;33import org.openqa.selenium.internal.Either;34import org.openqa.selenium.internal.Require;35import org.openqa.selenium.json.Json;36import org.openqa.selenium.json.TypeToken;37import org.openqa.selenium.remote.http.Contents;38import org.openqa.selenium.remote.http.Filter;39import org.openqa.selenium.remote.http.HttpClient;40import org.openqa.selenium.remote.http.HttpRequest;41import org.openqa.selenium.remote.http.HttpResponse;42import org.openqa.selenium.remote.tracing.HttpTracing;43import org.openqa.selenium.remote.tracing.Tracer;44import java.io.UncheckedIOException;45import java.lang.reflect.Type;46import java.net.MalformedURLException;47import java.net.URI;48import java.util.List;49import java.util.Optional;50import java.util.Set;51import static org.openqa.selenium.remote.http.HttpMethod.DELETE;52import static org.openqa.selenium.remote.http.HttpMethod.GET;53import static org.openqa.selenium.remote.http.HttpMethod.POST;54public class RemoteNewSessionQueue extends NewSessionQueue {55 private static final Type QUEUE_CONTENTS_TYPE = new TypeToken<List<SessionRequestCapability>>() {}.getType();56 private static final Json JSON = new Json();57 private final HttpClient client;58 private final Filter addSecret;59 public RemoteNewSessionQueue(Tracer tracer, HttpClient client, Secret registrationSecret) {60 super(tracer, registrationSecret);61 this.client = Require.nonNull("HTTP client", client);62 Require.nonNull("Registration secret", registrationSecret);63 this.addSecret = new AddSecretFilter(registrationSecret);64 }65 public static NewSessionQueue create(Config config) {66 Tracer tracer = new LoggingOptions(config).getTracer();67 URI uri = new NewSessionQueueOptions(config).getSessionQueueUri();68 HttpClient.Factory clientFactory = new NetworkOptions(config).getHttpClientFactory(tracer);69 SecretOptions secretOptions = new SecretOptions(config);70 Secret registrationSecret = secretOptions.getRegistrationSecret();71 try {72 return new RemoteNewSessionQueue(73 tracer,74 clientFactory.createClient(uri.toURL()),75 registrationSecret);76 } catch (MalformedURLException e) {77 throw new UncheckedIOException(e);78 }79 }80 @Override81 public HttpResponse addToQueue(SessionRequest request) {82 HttpRequest upstream = new HttpRequest(POST, "/se/grid/newsessionqueue/session");83 HttpTracing.inject(tracer, tracer.getCurrentContext(), upstream);84 upstream.setContent(Contents.asJson(request));85 return client.with(addSecret).execute(upstream);86 }87 @Override88 public boolean retryAddToQueue(SessionRequest request) {89 Require.nonNull("Session request", request);90 HttpRequest upstream =91 new HttpRequest(POST, String.format("/se/grid/newsessionqueue/session/%s/retry", request.getRequestId()));92 HttpTracing.inject(tracer, tracer.getCurrentContext(), upstream);93 upstream.setContent(Contents.asJson(request));94 HttpResponse response = client.with(addSecret).execute(upstream);95 return Values.get(response, Boolean.class);96 }97 @Override98 public Optional<SessionRequest> remove(RequestId reqId) {99 HttpRequest upstream = new HttpRequest(POST, "/se/grid/newsessionqueue/session/" + reqId);100 HttpTracing.inject(tracer, tracer.getCurrentContext(), upstream);101 HttpResponse response = client.with(addSecret).execute(upstream);102 if (response.isSuccessful()) {103 // TODO: This should work cleanly with just a TypeToken of <Optional<SessionRequest>>104 String rawValue = Contents.string(response);105 if (rawValue == null || rawValue.trim().isEmpty()) {106 return Optional.empty();107 }108 return Optional.of(JSON.toType(rawValue, SessionRequest.class));109 }110 return Optional.empty();111 }112 @Override113 public Optional<SessionRequest> getNextAvailable(Set<Capabilities> stereotypes) {114 Require.nonNull("Stereotypes", stereotypes);115 HttpRequest upstream = new HttpRequest(POST, "/se/grid/newsessionqueue/session/next")116 .setContent(Contents.asJson(stereotypes));117 HttpTracing.inject(tracer, tracer.getCurrentContext(), upstream);118 HttpResponse response = client.with(addSecret).execute(upstream);119 SessionRequest value = Values.get(response, SessionRequest.class);120 return Optional.ofNullable(value);121 }122 @Override123 public void complete(RequestId reqId, Either<SessionNotCreatedException, CreateSessionResponse> result) {124 Require.nonNull("Request ID", reqId);125 Require.nonNull("Result", result);126 HttpRequest upstream;127 if (result.isRight()) {128 upstream = new HttpRequest(POST, String.format("/se/grid/newsessionqueue/session/%s/success", reqId))129 .setContent(Contents.asJson(result.right()));130 } else {131 upstream = new HttpRequest(POST, String.format("/se/grid/newsessionqueue/session/%s/failure", reqId))132 .setContent(Contents.asJson(result.left().getRawMessage()));133 }134 HttpTracing.inject(tracer, tracer.getCurrentContext(), upstream);135 client.with(addSecret).execute(upstream);136 }137 @Override138 public int clearQueue() {139 HttpRequest upstream = new HttpRequest(DELETE, "/se/grid/newsessionqueue/queue");140 HttpTracing.inject(tracer, tracer.getCurrentContext(), upstream);141 HttpResponse response = client.with(addSecret).execute(upstream);142 return Values.get(response, Integer.class);143 }144 @Override145 public List<SessionRequestCapability> getQueueContents() {146 HttpRequest upstream = new HttpRequest(GET, "/se/grid/newsessionqueue/queue");147 HttpTracing.inject(tracer, tracer.getCurrentContext(), upstream);148 HttpResponse response = client.execute(upstream);149 return Values.get(response, QUEUE_CONTENTS_TYPE);150 }151 @Override152 public boolean isReady() {153 try {154 return client.execute(new HttpRequest(GET, "/readyz")).isSuccessful();155 } catch (RuntimeException e) {...

Full Screen

Full Screen

Source:RouterServer.java Github

copy

Full Screen

...32import org.openqa.selenium.grid.log.LoggingOptions;33import org.openqa.selenium.grid.router.ProxyCdpIntoGrid;34import org.openqa.selenium.grid.router.Router;35import org.openqa.selenium.grid.security.BasicAuthenticationFilter;36import org.openqa.selenium.grid.security.Secret;37import org.openqa.selenium.grid.security.SecretOptions;38import org.openqa.selenium.grid.server.BaseServerOptions;39import org.openqa.selenium.grid.server.NetworkOptions;40import org.openqa.selenium.grid.server.Server;41import org.openqa.selenium.grid.sessionmap.SessionMap;42import org.openqa.selenium.grid.sessionmap.config.SessionMapOptions;43import org.openqa.selenium.grid.sessionqueue.NewSessionQueue;44import org.openqa.selenium.grid.sessionqueue.config.NewSessionQueueOptions;45import org.openqa.selenium.grid.sessionqueue.remote.RemoteNewSessionQueue;46import org.openqa.selenium.grid.web.GridUiRoute;47import org.openqa.selenium.internal.Require;48import org.openqa.selenium.remote.http.HttpClient;49import org.openqa.selenium.remote.http.HttpHandler;50import org.openqa.selenium.remote.http.HttpResponse;51import org.openqa.selenium.remote.http.Routable;52import org.openqa.selenium.remote.http.Route;53import org.openqa.selenium.remote.tracing.Tracer;54import java.net.URL;55import java.util.Collections;56import java.util.Set;57import java.util.logging.Logger;58import static java.net.HttpURLConnection.HTTP_NO_CONTENT;59import static org.openqa.selenium.grid.config.StandardGridRoles.DISTRIBUTOR_ROLE;60import static org.openqa.selenium.grid.config.StandardGridRoles.HTTPD_ROLE;61import static org.openqa.selenium.grid.config.StandardGridRoles.ROUTER_ROLE;62import static org.openqa.selenium.grid.config.StandardGridRoles.SESSION_MAP_ROLE;63import static org.openqa.selenium.grid.config.StandardGridRoles.SESSION_QUEUE_ROLE;64import static org.openqa.selenium.net.Urls.fromUri;65import static org.openqa.selenium.remote.http.Route.combine;66import static org.openqa.selenium.remote.http.Route.get;67@AutoService(CliCommand.class)68public class RouterServer extends TemplateGridServerCommand {69 private static final Logger LOG = Logger.getLogger(RouterServer.class.getName());70 @Override71 public String getName() {72 return "router";73 }74 @Override75 public String getDescription() {76 return "Creates a router to front the selenium grid.";77 }78 @Override79 public Set<Role> getConfigurableRoles() {80 return ImmutableSet.of(81 DISTRIBUTOR_ROLE,82 HTTPD_ROLE,83 ROUTER_ROLE,84 SESSION_MAP_ROLE,85 SESSION_QUEUE_ROLE);86 }87 @Override88 public Set<Object> getFlagObjects() {89 return Collections.emptySet();90 }91 @Override92 protected String getSystemPropertiesConfigPrefix() {93 return "router";94 }95 @Override96 protected Config getDefaultConfig() {97 return new MapConfig(ImmutableMap.of("server", ImmutableMap.of("port", 4444)));98 }99 @Override100 protected Handlers createHandlers(Config config) {101 LoggingOptions loggingOptions = new LoggingOptions(config);102 Tracer tracer = loggingOptions.getTracer();103 NetworkOptions networkOptions = new NetworkOptions(config);104 HttpClient.Factory clientFactory = networkOptions.getHttpClientFactory(tracer);105 BaseServerOptions serverOptions = new BaseServerOptions(config);106 SecretOptions secretOptions = new SecretOptions(config);107 Secret secret = secretOptions.getRegistrationSecret();108 SessionMapOptions sessionsOptions = new SessionMapOptions(config);109 SessionMap sessions = sessionsOptions.getSessionMap();110 NewSessionQueueOptions sessionQueueOptions = new NewSessionQueueOptions(config);111 URL sessionQueueUrl = fromUri(sessionQueueOptions.getSessionQueueUri());112 NewSessionQueue queue = new RemoteNewSessionQueue(113 tracer,114 clientFactory.createClient(sessionQueueUrl),115 secret);116 DistributorOptions distributorOptions = new DistributorOptions(config);117 URL distributorUrl = fromUri(distributorOptions.getDistributorUri());118 Distributor distributor = new RemoteDistributor(119 tracer,120 clientFactory,121 distributorUrl,...

Full Screen

Full Screen

Source:RemoteNewSessionQueuer.java Github

copy

Full Screen

...17package org.openqa.selenium.grid.sessionqueue.remote;18import org.openqa.selenium.grid.config.Config;19import org.openqa.selenium.grid.data.RequestId;20import org.openqa.selenium.grid.log.LoggingOptions;21import org.openqa.selenium.grid.security.AddSecretFilter;22import org.openqa.selenium.grid.security.Secret;23import org.openqa.selenium.grid.security.SecretOptions;24import org.openqa.selenium.grid.server.NetworkOptions;25import org.openqa.selenium.grid.sessionqueue.NewSessionQueuer;26import org.openqa.selenium.grid.sessionqueue.config.NewSessionQueuerOptions;27import org.openqa.selenium.grid.web.Values;28import org.openqa.selenium.internal.Require;29import org.openqa.selenium.remote.http.Filter;30import org.openqa.selenium.remote.http.HttpClient;31import org.openqa.selenium.remote.http.HttpRequest;32import org.openqa.selenium.remote.http.HttpResponse;33import org.openqa.selenium.remote.tracing.HttpTracing;34import org.openqa.selenium.remote.tracing.Tracer;35import java.io.UncheckedIOException;36import java.net.MalformedURLException;37import java.net.URI;38import java.util.List;39import java.util.Optional;40import static java.net.HttpURLConnection.HTTP_OK;41import static org.openqa.selenium.grid.sessionqueue.NewSessionQueue.SESSIONREQUEST_ID_HEADER;42import static org.openqa.selenium.grid.sessionqueue.NewSessionQueue.SESSIONREQUEST_TIMESTAMP_HEADER;43import static org.openqa.selenium.remote.http.HttpMethod.DELETE;44import static org.openqa.selenium.remote.http.HttpMethod.GET;45import static org.openqa.selenium.remote.http.HttpMethod.POST;46public class RemoteNewSessionQueuer extends NewSessionQueuer {47 private static final String timestampHeader = SESSIONREQUEST_TIMESTAMP_HEADER;48 private static final String reqIdHeader = SESSIONREQUEST_ID_HEADER;49 private final HttpClient client;50 private final Filter addSecret;51 public RemoteNewSessionQueuer(Tracer tracer, HttpClient client, Secret registrationSecret) {52 super(tracer, registrationSecret);53 this.client = Require.nonNull("HTTP client", client);54 Require.nonNull("Registration secret", registrationSecret);55 this.addSecret = new AddSecretFilter(registrationSecret);56 }57 public static NewSessionQueuer create(Config config) {58 Tracer tracer = new LoggingOptions(config).getTracer();59 URI uri = new NewSessionQueuerOptions(config).getSessionQueuerUri();60 HttpClient.Factory clientFactory = new NetworkOptions(config).getHttpClientFactory(tracer);61 SecretOptions secretOptions = new SecretOptions(config);62 Secret registrationSecret = secretOptions.getRegistrationSecret();63 try {64 return new RemoteNewSessionQueuer(65 tracer,66 clientFactory.createClient(uri.toURL()),67 registrationSecret);68 } catch (MalformedURLException e) {69 throw new UncheckedIOException(e);70 }71 }72 @Override73 public HttpResponse addToQueue(HttpRequest request) {74 HttpRequest upstream = new HttpRequest(POST, "/se/grid/newsessionqueuer/session");75 HttpTracing.inject(tracer, tracer.getCurrentContext(), upstream);76 upstream.setContent(request.getContent());77 return client.execute(upstream);78 }79 @Override80 public boolean retryAddToQueue(HttpRequest request, RequestId reqId) {81 HttpRequest upstream =82 new HttpRequest(POST, "/se/grid/newsessionqueuer/session/retry/" + reqId.toString());83 HttpTracing.inject(tracer, tracer.getCurrentContext(), upstream);84 upstream.setContent(request.getContent());85 upstream.setHeader(timestampHeader, request.getHeader(timestampHeader));86 upstream.setHeader(reqIdHeader, reqId.toString());87 HttpResponse response = client.with(addSecret).execute(upstream);88 return Values.get(response, Boolean.class);89 }90 @Override91 public Optional<HttpRequest> remove(RequestId reqId) {92 HttpRequest upstream =93 new HttpRequest(GET, "/se/grid/newsessionqueuer/session/" + reqId.toString());94 HttpTracing.inject(tracer, tracer.getCurrentContext(), upstream);95 HttpResponse response = client.with(addSecret).execute(upstream);96 if(response.getStatus()==HTTP_OK) {97 HttpRequest httpRequest = new HttpRequest(POST, "/session");98 httpRequest.setContent(response.getContent());99 httpRequest.setHeader(timestampHeader, response.getHeader(timestampHeader));100 httpRequest.setHeader(reqIdHeader, response.getHeader(reqIdHeader));101 return Optional.ofNullable(httpRequest);102 }103 return Optional.empty();104 }105 @Override106 public int clearQueue() {107 HttpRequest upstream = new HttpRequest(DELETE, "/se/grid/newsessionqueuer/queue");108 HttpTracing.inject(tracer, tracer.getCurrentContext(), upstream);109 HttpResponse response = client.with(addSecret).execute(upstream);110 return Values.get(response, Integer.class);111 }112 @Override113 public List<Object> getQueueContents() {114 HttpRequest upstream = new HttpRequest(GET, "/se/grid/newsessionqueuer/queue");115 HttpTracing.inject(tracer, tracer.getCurrentContext(), upstream);116 HttpResponse response = client.execute(upstream);117 return Values.get(response, List.class);118 }119 @Override120 public boolean isReady() {121 try {122 return client.execute(new HttpRequest(GET, "/readyz")).isSuccessful();123 } catch (RuntimeException e) {...

Full Screen

Full Screen

Source:NewSessionQueue.java Github

copy

Full Screen

...20import org.openqa.selenium.grid.data.CreateSessionResponse;21import org.openqa.selenium.grid.data.RequestId;22import org.openqa.selenium.grid.data.SessionRequest;23import org.openqa.selenium.grid.data.SessionRequestCapability;24import org.openqa.selenium.grid.security.RequiresSecretFilter;25import org.openqa.selenium.grid.security.Secret;26import org.openqa.selenium.internal.Either;27import org.openqa.selenium.internal.Require;28import org.openqa.selenium.remote.http.HttpRequest;29import org.openqa.selenium.remote.http.HttpResponse;30import org.openqa.selenium.remote.http.Routable;31import org.openqa.selenium.remote.http.Route;32import org.openqa.selenium.remote.tracing.Tracer;33import org.openqa.selenium.status.HasReadyState;34import java.time.Instant;35import java.util.List;36import java.util.Map;37import java.util.Optional;38import java.util.Set;39import java.util.UUID;40import static org.openqa.selenium.remote.http.Route.combine;41import static org.openqa.selenium.remote.http.Route.delete;42import static org.openqa.selenium.remote.http.Route.get;43import static org.openqa.selenium.remote.http.Route.post;44public abstract class NewSessionQueue implements HasReadyState, Routable {45 protected final Tracer tracer;46 private final Route routes;47 protected NewSessionQueue(Tracer tracer, Secret registrationSecret) {48 this.tracer = Require.nonNull("Tracer", tracer);49 Require.nonNull("Registration secret", registrationSecret);50 RequiresSecretFilter requiresSecret = new RequiresSecretFilter(registrationSecret);51 routes = combine(52 post("/session")53 .to(() -> req -> {54 SessionRequest sessionRequest = new SessionRequest(55 new RequestId(UUID.randomUUID()),56 req,57 Instant.now()58 );59 return addToQueue(sessionRequest);60 }),61 post("/se/grid/newsessionqueue/session")62 .to(() -> new AddToSessionQueue(tracer, this))63 .with(requiresSecret),64 post("/se/grid/newsessionqueue/session/{requestId}/retry")65 .to(params -> new AddBackToSessionQueue(tracer, this, requestIdFrom(params)))66 .with(requiresSecret),67 post("/se/grid/newsessionqueue/session/{requestId}/failure")68 .to(params -> new SessionNotCreated(tracer, this, requestIdFrom(params)))69 .with(requiresSecret),70 post("/se/grid/newsessionqueue/session/{requestId}/success")71 .to(params -> new SessionCreated(tracer, this, requestIdFrom(params)))72 .with(requiresSecret),73 post("/se/grid/newsessionqueue/session/{requestId}")74 .to(params -> new RemoveFromSessionQueue(tracer, this, requestIdFrom(params)))75 .with(requiresSecret),76 post("/se/grid/newsessionqueue/session/next")77 .to(() -> new GetNextMatchingRequest(tracer, this))78 .with(requiresSecret),79 get("/se/grid/newsessionqueue/queue")80 .to(() -> new GetSessionQueue(tracer, this)),81 delete("/se/grid/newsessionqueue/queue")82 .to(() -> new ClearSessionQueue(tracer, this))83 .with(requiresSecret));84 }85 private RequestId requestIdFrom(Map<String, String> params) {86 return new RequestId(UUID.fromString(params.get("requestId")));87 }88 public abstract HttpResponse addToQueue(SessionRequest request);89 public abstract boolean retryAddToQueue(SessionRequest request);90 public abstract Optional<SessionRequest> remove(RequestId reqId);91 public abstract Optional<SessionRequest> getNextAvailable(Set<Capabilities> stereotypes);92 public abstract void complete(RequestId reqId, Either<SessionNotCreatedException, CreateSessionResponse> result);93 public abstract int clearQueue();94 public abstract List<SessionRequestCapability> getQueueContents();95 @Override96 public boolean matches(HttpRequest req) {97 return routes.matches(req);...

Full Screen

Full Screen

Source:ZeroMqEventBus.java Github

copy

Full Screen

...18import org.openqa.selenium.events.EventBus;19import org.openqa.selenium.events.EventListener;20import org.openqa.selenium.events.EventName;21import org.openqa.selenium.grid.config.Config;22import org.openqa.selenium.grid.security.Secret;23import org.openqa.selenium.grid.security.SecretOptions;24import org.openqa.selenium.internal.Require;25import org.openqa.selenium.json.JsonInput;26import org.zeromq.ZContext;27import java.util.function.Consumer;28import static org.openqa.selenium.events.zeromq.UnboundZmqEventBus.REJECTED_EVENT;29/**30 * An {@link EventBus} backed by ZeroMQ.31 */32public class ZeroMqEventBus {33 private static final String EVENTS_SECTION = "events";34 private ZeroMqEventBus() {35 // Use the create method.36 }37 public static EventBus create(ZContext context, String publish, String subscribe, boolean bind, Secret secret) {38 if (bind) {39 return new BoundZmqEventBus(context, publish, subscribe, secret);40 }41 return new UnboundZmqEventBus(context, publish, subscribe, secret);42 }43 public static EventBus create(Config config) {44 String publish = config.get(EVENTS_SECTION, "publish")45 .orElseThrow(() -> new IllegalArgumentException(46 "Unable to find address to publish events to."));47 String subscribe = config.get(EVENTS_SECTION, "subscribe")48 .orElseThrow(() -> new IllegalArgumentException(49 "Unable to find address to subscribe for events from."));50 boolean bind = config.getBool(EVENTS_SECTION, "bind").orElse(false);51 SecretOptions secretOptions = new SecretOptions(config);52 return create(new ZContext(), publish, subscribe, bind, secretOptions.getRegistrationSecret());53 }54 public static EventListener<RejectedEvent> onRejectedEvent(Consumer<RejectedEvent> handler) {55 Require.nonNull("Handler", handler);56 return new EventListener<>(REJECTED_EVENT, RejectedEvent.class, handler);57 }58 public static class RejectedEvent {59 private final EventName name;60 private final Object data;61 RejectedEvent(EventName name, Object data) {62 this.name = name;63 this.data = data;64 }65 public EventName getName() {66 return name;...

Full Screen

Full Screen

Source:RequiresSecretFilter.java Github

copy

Full Screen

...23import org.openqa.selenium.remote.http.HttpResponse;24import java.util.Objects;25import java.util.logging.Logger;26import static java.net.HttpURLConnection.HTTP_UNAUTHORIZED;27import static org.openqa.selenium.grid.security.AddSecretFilter.HEADER_NAME;28public class RequiresSecretFilter implements Filter {29 private static final Logger LOG = Logger.getLogger(RequiresSecretFilter.class.getName());30 private final Secret secret;31 public RequiresSecretFilter(Secret secret) {32 this.secret = secret;33 }34 @Override35 public HttpHandler apply(HttpHandler httpHandler) {36 Require.nonNull("HTTP handler", httpHandler);37 return req -> {38 if (!isSecretMatch(secret, req)) {39 return new HttpResponse()40 .setStatus(HTTP_UNAUTHORIZED)41 .addHeader("Content-Type", "text/plain; charset=UTF-8")42 .setContent(Contents.utf8String("Unauthorized access attempted to " + req.getUri()));43 }44 return httpHandler.execute(req);45 };46 }47 private boolean isSecretMatch(Secret secret, HttpRequest request) {48 String header = request.getHeader(HEADER_NAME);49 if (header == null) {50 if (secret != null) {51 LOG.warning("Unexpected secret sent!");52 return false;53 }54 return true;55 }56 Secret requestSecret = new Secret(header);57 if (!Objects.equals(secret, requestSecret)) {58 LOG.warning("Secrets did not match!");59 return false;60 }61 return true;62 }63}...

Full Screen

Full Screen
copy
1 if (f = fopen("goodluckfindingthisfile")) { ... } 2 else { // file not found ...3
Full Screen
copy
1public [int or IOException] writeToStream(OutputStream stream) {2 [void or IOException] a= stream.write(mybytes);3 if (a instanceof IOException)4 return a;5 return mybytes.length;6}7
Full Screen
copy
1try {2 // do stuff3} catch (AnnoyingcheckedException e) {4 throw new RuntimeException(e);5}6
Full Screen

Selenium 4 Tutorial:

LambdaTest’s Selenium 4 tutorial is covering every aspects of Selenium 4 testing with examples and best practices. Here you will learn basics, such as how to upgrade from Selenium 3 to Selenium 4, to some advanced concepts, such as Relative locators and Selenium Grid 4 for Distributed testing. Also will learn new features of Selenium 4, such as capturing screenshots of specific elements, opening a new tab or window on the browser, and new protocol adoptions.

Chapters:

  1. Upgrading From Selenium 3 To Selenium 4?: In this chapter, learn in detail how to update Selenium 3 to Selenium 4 for Java binding. Also, learn how to upgrade while using different build tools such as Maven or Gradle and get comprehensive guidance for upgrading Selenium.

  2. What’s New In Selenium 4 & What’s Being Deprecated? : Get all information about new implementations in Selenium 4, such as W3S protocol adaption, Optimized Selenium Grid, and Enhanced Selenium IDE. Also, learn what is deprecated for Selenium 4, such as DesiredCapabilites and FindsBy methods, etc.

  3. Selenium 4 With Python: Selenium supports all major languages, such as Python, C#, Ruby, and JavaScript. In this chapter, learn how to install Selenium 4 for Python and the features of Python in Selenium 4, such as Relative locators, Browser manipulation, and Chrom DevTool protocol.

  4. Selenium 4 Is Now W3C Compliant: JSON Wireframe protocol is retiring from Selenium 4, and they are adopting W3C protocol to learn in detail about the advantages and impact of these changes.

  5. How To Use Selenium 4 Relative Locator? : Selenium 4 came with new features such as Relative Locators that allow constructing locators with reference and easily located constructors nearby. Get to know its different use cases with examples.

  6. Selenium Grid 4 Tutorial For Distributed Testing: Selenium Grid 4 allows you to perform tests over different browsers, OS, and device combinations. It also enables parallel execution browser testing, reads up on various features of Selenium Grid 4 and how to download it, and runs a test on Selenium Grid 4 with best practices.

  7. Selenium Video Tutorials: Binge on video tutorials on Selenium by industry experts to get step-by-step direction from automating basic to complex test scenarios with Selenium.

Selenium 101 certifications:

LambdaTest also provides certification for Selenium testing to accelerate your career in Selenium automation testing.

Run Selenium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used methods in Secret

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful