Best Selenium code snippet using org.openqa.selenium.grid.sessionqueue.local.LocalNewSessionQueue
Source:LocalDistributorTest.java
...32import org.openqa.selenium.grid.node.Node;33import org.openqa.selenium.grid.node.local.LocalNode;34import org.openqa.selenium.grid.security.Secret;35import org.openqa.selenium.grid.sessionmap.local.LocalSessionMap;36import org.openqa.selenium.grid.sessionqueue.local.LocalNewSessionQueue;37import org.openqa.selenium.grid.sessionqueue.local.LocalNewSessionQueuer;38import org.openqa.selenium.grid.testing.TestSessionFactory;39import org.openqa.selenium.internal.Either;40import org.openqa.selenium.remote.HttpSessionId;41import org.openqa.selenium.remote.SessionId;42import org.openqa.selenium.remote.http.Contents;43import org.openqa.selenium.remote.http.HttpClient;44import org.openqa.selenium.remote.http.HttpHandler;45import org.openqa.selenium.remote.http.HttpMethod;46import org.openqa.selenium.remote.http.HttpRequest;47import org.openqa.selenium.remote.http.HttpResponse;48import org.openqa.selenium.remote.tracing.DefaultTestTracer;49import org.openqa.selenium.remote.tracing.Tracer;50import java.io.UncheckedIOException;51import java.net.URI;52import java.net.URISyntaxException;53import java.time.Duration;54import java.time.Instant;55import java.util.ArrayList;56import java.util.List;57import java.util.Optional;58import java.util.Set;59import java.util.UUID;60import java.util.concurrent.Callable;61import java.util.concurrent.Executors;62import java.util.concurrent.Future;63import java.util.concurrent.TimeUnit;64import static org.assertj.core.api.Assertions.assertThat;65import static org.assertj.core.api.Assertions.fail;66import static org.openqa.selenium.grid.data.Availability.DRAINING;67import static org.openqa.selenium.remote.http.HttpMethod.GET;68public class LocalDistributorTest {69 private final Secret registrationSecret = new Secret("bavarian smoked");70 private Tracer tracer;71 private EventBus bus;72 private HttpClient.Factory clientFactory;73 private URI uri;74 private Node localNode;75 @Before76 public void setUp() throws URISyntaxException {77 tracer = DefaultTestTracer.createTracer();78 bus = new GuavaEventBus();79 clientFactory = HttpClient.Factory.createDefault();80 Capabilities caps = new ImmutableCapabilities("browserName", "cheese");81 uri = new URI("http://localhost:1234");82 localNode = LocalNode.builder(tracer, bus, uri, uri, registrationSecret)83 .add(caps, new TestSessionFactory((id, c) -> new Handler(c)))84 .maximumConcurrentSessions(2)85 .build();86 }87 @Test88 public void testAddNodeToDistributor() {89 LocalNewSessionQueue localNewSessionQueue = new LocalNewSessionQueue(90 tracer,91 bus,92 Duration.ofSeconds(2),93 Duration.ofSeconds(2));94 LocalNewSessionQueuer queuer = new LocalNewSessionQueuer(95 tracer,96 bus,97 localNewSessionQueue,98 registrationSecret);99 Distributor distributor = new LocalDistributor(100 tracer,101 bus,102 clientFactory,103 new LocalSessionMap(tracer, bus),104 queuer,105 registrationSecret,106 Duration.ofMinutes(5));107 distributor.add(localNode);108 DistributorStatus status = distributor.getStatus();109 //Check the size110 final Set<NodeStatus> nodes = status.getNodes();111 assertThat(nodes.size()).isEqualTo(1);112 //Check a couple attributes113 NodeStatus distributorNode = nodes.iterator().next();114 assertThat(distributorNode.getId()).isEqualByComparingTo(localNode.getId());115 assertThat(distributorNode.getUri()).isEqualTo(uri);116 }117 @Test118 public void testShouldNotAddNodeWithWrongSecret() {119 Secret secret = new Secret("my_secret");120 LocalNewSessionQueue localNewSessionQueue = new LocalNewSessionQueue(121 tracer,122 bus,123 Duration.ofSeconds(2),124 Duration.ofSeconds(2));125 LocalNewSessionQueuer queuer = new LocalNewSessionQueuer(126 tracer,127 bus,128 localNewSessionQueue,129 registrationSecret);130 Distributor secretDistributor = new LocalDistributor(131 tracer,132 bus,133 clientFactory,134 new LocalSessionMap(tracer, bus),135 queuer,136 secret,137 Duration.ofMinutes(5));138 bus.fire(new NodeStatusEvent(localNode.getStatus()));139 DistributorStatus status = secretDistributor.getStatus();140 //Check the size141 final Set<NodeStatus> nodes = status.getNodes();142 assertThat(nodes.size()).isEqualTo(0);143 }144 @Test145 public void testRemoveNodeFromDistributor() {146 LocalNewSessionQueue localNewSessionQueue = new LocalNewSessionQueue(147 tracer,148 bus,149 Duration.ofSeconds(2),150 Duration.ofSeconds(2));151 LocalNewSessionQueuer queuer = new LocalNewSessionQueuer(152 tracer,153 bus,154 localNewSessionQueue,155 registrationSecret);156 Distributor distributor = new LocalDistributor(157 tracer,158 bus,159 clientFactory,160 new LocalSessionMap(tracer, bus),161 queuer,162 registrationSecret,163 Duration.ofMinutes(5));164 distributor.add(localNode);165 //Check the size166 DistributorStatus statusBefore = distributor.getStatus();167 final Set<NodeStatus> nodesBefore = statusBefore.getNodes();168 assertThat(nodesBefore.size()).isEqualTo(1);169 //Recheck the status--should be zero170 distributor.remove(localNode.getId());171 DistributorStatus statusAfter = distributor.getStatus();172 final Set<NodeStatus> nodesAfter = statusAfter.getNodes();173 assertThat(nodesAfter.size()).isEqualTo(0);174 }175 @Test176 public void testAddSameNodeTwice() {177 LocalNewSessionQueue localNewSessionQueue = new LocalNewSessionQueue(178 tracer,179 bus,180 Duration.ofSeconds(2),181 Duration.ofSeconds(2));182 LocalNewSessionQueuer queuer = new LocalNewSessionQueuer(183 tracer,184 bus,185 localNewSessionQueue,186 registrationSecret);187 Distributor distributor = new LocalDistributor(188 tracer,189 bus,190 clientFactory,191 new LocalSessionMap(tracer, bus),192 queuer,193 registrationSecret,194 Duration.ofMinutes(5));195 distributor.add(localNode);196 distributor.add(localNode);197 DistributorStatus status = distributor.getStatus();198 //Should only be one node after dupe check199 final Set<NodeStatus> nodes = status.getNodes();200 assertThat(nodes.size()).isEqualTo(1);201 }202 @Test203 public void shouldBeAbleToAddMultipleSessionsConcurrently() throws Exception {204 LocalNewSessionQueue localNewSessionQueue = new LocalNewSessionQueue(205 tracer,206 bus,207 Duration.ofSeconds(2),208 Duration.ofSeconds(2));209 LocalNewSessionQueuer queuer = new LocalNewSessionQueuer(210 tracer,211 bus,212 localNewSessionQueue,213 registrationSecret);214 LocalDistributor distributor = new LocalDistributor(215 tracer,216 bus,217 clientFactory,218 new LocalSessionMap(tracer, bus),219 queuer,220 registrationSecret,221 Duration.ofMinutes(5));222 // Add one node to ensure that everything is created in that.223 Capabilities caps = new ImmutableCapabilities("browserName", "cheese");224 class VerifyingHandler extends Session implements HttpHandler {225 private VerifyingHandler(SessionId id, Capabilities capabilities) {226 super(id, uri, new ImmutableCapabilities(), capabilities, Instant.now());227 }228 @Override229 public HttpResponse execute(HttpRequest req) {230 Optional<SessionId> id = HttpSessionId.getSessionId(req.getUri()).map(SessionId::new);231 assertThat(id).isEqualTo(Optional.of(getId()));232 return new HttpResponse();233 }234 }235 // Only use one node.236 Node node = LocalNode.builder(tracer, bus, uri, uri, registrationSecret)237 .add(caps, new TestSessionFactory(VerifyingHandler::new))238 .add(caps, new TestSessionFactory(VerifyingHandler::new))239 .add(caps, new TestSessionFactory(VerifyingHandler::new))240 .maximumConcurrentSessions(3)241 .build();242 distributor.add(node);243 HttpRequest req = new HttpRequest(HttpMethod.POST, "/session")244 .setContent(Contents.asJson(ImmutableMap.of(245 "capabilities", ImmutableMap.of(246 "alwaysMatch", ImmutableMap.of(247 "browserName", "cheese")))));248 List<Callable<SessionId>> callables = new ArrayList<>();249 for (int i = 0; i < 3; i++) {250 callables.add(() -> {251 Either<SessionNotCreatedException, CreateSessionResponse> result =252 distributor.newSession(req);253 if (result.isRight()) {254 CreateSessionResponse res = result.right();255 assertThat(res.getSession().getCapabilities().getBrowserName()).isEqualTo("cheese");256 return res.getSession().getId();257 } else {258 fail("Session creation failed", result.left());259 }260 return null;261 });262 }263 List<Future<SessionId>> futures = Executors.newFixedThreadPool(3).invokeAll(callables);264 for (Future<SessionId> future : futures) {265 SessionId id = future.get(2, TimeUnit.SECONDS);266 // Now send a random command.267 HttpResponse res = node.execute(new HttpRequest(GET, String.format("/session/%s/url", id)));268 assertThat(res.isSuccessful()).isTrue();269 }270 }271 @Test272 public void testDrainNodeFromDistributor() {273 LocalNewSessionQueue localNewSessionQueue = new LocalNewSessionQueue(274 tracer,275 bus,276 Duration.ofSeconds(2),277 Duration.ofSeconds(2));278 LocalNewSessionQueuer queuer = new LocalNewSessionQueuer(279 tracer,280 bus,281 localNewSessionQueue,282 registrationSecret);283 Distributor distributor = new LocalDistributor(284 tracer,285 bus,286 clientFactory,287 new LocalSessionMap(tracer, bus),288 queuer,289 registrationSecret,290 Duration.ofMinutes(5));291 distributor.add(localNode);292 assertThat(localNode.isDraining()).isFalse();293 //Check the size - there should be one node294 DistributorStatus statusBefore = distributor.getStatus();295 Set<NodeStatus> nodesBefore = statusBefore.getNodes();296 assertThat(nodesBefore.size()).isEqualTo(1);297 NodeStatus nodeBefore = nodesBefore.iterator().next();298 assertThat(nodeBefore.getAvailability()).isNotEqualTo(DRAINING);299 distributor.drain(localNode.getId());300 assertThat(localNode.isDraining()).isTrue();301 //Recheck the status - there should still be no node, it is removed302 DistributorStatus statusAfter = distributor.getStatus();303 Set<NodeStatus> nodesAfter = statusAfter.getNodes();304 assertThat(nodesAfter.size()).isEqualTo(0);305 }306 @Test307 public void testDrainNodeFromNode() {308 assertThat(localNode.isDraining()).isFalse();309 LocalNewSessionQueue localNewSessionQueue = new LocalNewSessionQueue(310 tracer,311 bus,312 Duration.ofSeconds(2),313 Duration.ofSeconds(2));314 LocalNewSessionQueuer queuer = new LocalNewSessionQueuer(315 tracer,316 bus,317 localNewSessionQueue,318 registrationSecret);319 Distributor distributor = new LocalDistributor(320 tracer,321 bus,322 clientFactory,323 new LocalSessionMap(tracer, bus),324 queuer,325 registrationSecret,326 Duration.ofMinutes(5));327 distributor.add(localNode);328 localNode.drain();...
Source:SessionQueueGridTest.java
...58import org.openqa.selenium.grid.sessionmap.SessionMap;59import org.openqa.selenium.grid.sessionmap.local.LocalSessionMap;60import org.openqa.selenium.grid.sessionqueue.NewSessionQueue;61import org.openqa.selenium.grid.sessionqueue.NewSessionQueuer;62import org.openqa.selenium.grid.sessionqueue.local.LocalNewSessionQueue;63import org.openqa.selenium.grid.sessionqueue.local.LocalNewSessionQueuer;64import org.openqa.selenium.grid.testing.TestSessionFactory;65import org.openqa.selenium.grid.web.CombinedHandler;66import org.openqa.selenium.grid.web.RoutableHttpClientFactory;67import org.openqa.selenium.net.PortProber;68import org.openqa.selenium.netty.server.NettyServer;69import org.openqa.selenium.remote.http.HttpClient;70import org.openqa.selenium.remote.http.HttpHandler;71import org.openqa.selenium.remote.http.HttpRequest;72import org.openqa.selenium.remote.http.HttpResponse;73import org.openqa.selenium.remote.tracing.DefaultTestTracer;74import org.openqa.selenium.remote.tracing.Tracer;75public class SessionQueueGridTest {76 private static final Capabilities CAPS = new ImmutableCapabilities("browserName", "cheese");77 private HttpClient.Factory clientFactory;78 private Secret registrationSecret;79 private Server<?> server;80 @Before81 public void setup() throws URISyntaxException, MalformedURLException {82 Tracer tracer = DefaultTestTracer.createTracer();83 EventBus bus = new GuavaEventBus();84 URI nodeUri = new URI("http://localhost:4444");85 CombinedHandler handler = new CombinedHandler();86 clientFactory = new RoutableHttpClientFactory(87 nodeUri.toURL(), handler,88 HttpClient.Factory.createDefault());89 registrationSecret = new Secret("cheese");90 SessionMap sessions = new LocalSessionMap(tracer, bus);91 handler.addHandler(sessions);92 NewSessionQueue localNewSessionQueue = new LocalNewSessionQueue(93 tracer,94 bus,95 Duration.ofSeconds(5),96 Duration.ofSeconds(10));97 NewSessionQueuer queuer = new LocalNewSessionQueuer(98 tracer,99 bus,100 localNewSessionQueue,101 registrationSecret);102 handler.addHandler(queuer);103 Distributor distributor = new LocalDistributor(104 tracer,105 bus,106 clientFactory,107 sessions,108 queuer,109 registrationSecret,110 Duration.ofMinutes(5));111 handler.addHandler(distributor);...
Source:NewSessionCreationTest.java
...38import org.openqa.selenium.grid.sessionmap.SessionMap;39import org.openqa.selenium.grid.sessionmap.local.LocalSessionMap;40import org.openqa.selenium.grid.sessionqueue.NewSessionQueue;41import org.openqa.selenium.grid.sessionqueue.NewSessionQueuer;42import org.openqa.selenium.grid.sessionqueue.local.LocalNewSessionQueue;43import org.openqa.selenium.grid.sessionqueue.local.LocalNewSessionQueuer;44import org.openqa.selenium.grid.testing.TestSessionFactory;45import org.openqa.selenium.grid.web.CombinedHandler;46import org.openqa.selenium.grid.web.EnsureSpecCompliantHeaders;47import org.openqa.selenium.netty.server.NettyServer;48import org.openqa.selenium.remote.http.Contents;49import org.openqa.selenium.remote.http.HttpClient;50import org.openqa.selenium.remote.http.HttpRequest;51import org.openqa.selenium.remote.http.HttpResponse;52import org.openqa.selenium.remote.http.Routable;53import org.openqa.selenium.remote.tracing.DefaultTestTracer;54import org.openqa.selenium.remote.tracing.Tracer;55import org.openqa.selenium.testing.drivers.Browser;56import java.net.URI;57import java.net.URISyntaxException;58import java.time.Duration;59import java.time.Instant;60import java.util.concurrent.atomic.AtomicInteger;61import static java.net.HttpURLConnection.HTTP_INTERNAL_ERROR;62import static org.assertj.core.api.Assertions.assertThat;63import static org.openqa.selenium.json.Json.JSON_UTF_8;64import static org.openqa.selenium.remote.http.Contents.asJson;65import static org.openqa.selenium.remote.http.HttpMethod.POST;66public class NewSessionCreationTest {67 private Tracer tracer;68 private EventBus events;69 private HttpClient.Factory clientFactory;70 private Secret registrationSecret;71 private Server<?> server;72 @Before73 public void setup() {74 tracer = DefaultTestTracer.createTracer();75 events = new GuavaEventBus();76 clientFactory = HttpClient.Factory.createDefault();77 registrationSecret = new Secret("hereford hop");78 }79 @After80 public void stopServer() {81 server.stop();82 }83 @Test84 public void ensureJsCannotCreateANewSession() throws URISyntaxException {85 SessionMap sessions = new LocalSessionMap(tracer, events);86 LocalNewSessionQueue localNewSessionQueue = new LocalNewSessionQueue(87 tracer,88 events,89 Duration.ofSeconds(2),90 Duration.ofSeconds(2));91 NewSessionQueuer queuer = new LocalNewSessionQueuer(92 tracer,93 events,94 localNewSessionQueue,95 registrationSecret);96 Distributor distributor = new LocalDistributor(97 tracer,98 events,99 clientFactory,100 sessions,101 queuer,102 registrationSecret,103 Duration.ofMinutes(5));104 Routable router = new Router(tracer, clientFactory, sessions, queuer, distributor)105 .with(new EnsureSpecCompliantHeaders(ImmutableList.of(), ImmutableSet.of()));106 server = new NettyServer(107 new BaseServerOptions(new MapConfig(ImmutableMap.of())),108 router,109 new ProxyCdpIntoGrid(clientFactory, sessions))110 .start();111 URI uri = server.getUrl().toURI();112 Node node = LocalNode.builder(113 tracer,114 events,115 uri,116 uri,117 registrationSecret)118 .add(119 Browser.detect().getCapabilities(),120 new TestSessionFactory(121 (id, caps) ->122 new Session(id, uri, Browser.detect().getCapabilities(), caps, Instant.now())))123 .build();124 distributor.add(node);125 try (HttpClient client = HttpClient.Factory.createDefault().createClient(server.getUrl())) {126 // Attempt to create a session with an origin header but content type set127 HttpResponse res = client.execute(128 new HttpRequest(POST, "/session")129 .addHeader("Content-Type", JSON_UTF_8)130 .addHeader("Origin", "localhost")131 .setContent(Contents.asJson(ImmutableMap.of(132 "capabilities", ImmutableMap.of(133 "alwaysMatch", Browser.detect().getCapabilities())))));134 assertThat(res.getStatus()).isEqualTo(HTTP_INTERNAL_ERROR);135 // And now make sure the session is just fine136 res = client.execute(137 new HttpRequest(POST, "/session")138 .addHeader("Content-Type", JSON_UTF_8)139 .setContent(Contents.asJson(ImmutableMap.of(140 "capabilities", ImmutableMap.of(141 "alwaysMatch", Browser.detect().getCapabilities())))));142 assertThat(res.isSuccessful()).isTrue();143 }144 }145 @Test146 public void shouldNotRetryNewSessionRequestOnUnexpectedError() throws URISyntaxException {147 Capabilities capabilities = new ImmutableCapabilities("browserName", "cheese");148 URI nodeUri = new URI("http://localhost:4444");149 CombinedHandler handler = new CombinedHandler();150 SessionMap sessions = new LocalSessionMap(tracer, events);151 handler.addHandler(sessions);152 NewSessionQueue localNewSessionQueue = new LocalNewSessionQueue(153 tracer,154 events,155 Duration.ofSeconds(2),156 Duration.ofSeconds(10));157 NewSessionQueuer queuer = new LocalNewSessionQueuer(158 tracer,159 events,160 localNewSessionQueue,161 registrationSecret);162 handler.addHandler(queuer);163 Distributor distributor = new LocalDistributor(164 tracer,165 events,166 clientFactory,167 sessions,168 queuer,169 registrationSecret,170 Duration.ofMinutes(5));171 handler.addHandler(distributor);...
Source:Standalone.java
...42import org.openqa.selenium.grid.sessionmap.local.LocalSessionMap;43import org.openqa.selenium.grid.sessionqueue.NewSessionQueue;44import org.openqa.selenium.grid.sessionqueue.NewSessionQueuer;45import org.openqa.selenium.grid.sessionqueue.config.NewSessionQueueOptions;46import org.openqa.selenium.grid.sessionqueue.local.LocalNewSessionQueue;47import org.openqa.selenium.grid.sessionqueue.local.LocalNewSessionQueuer;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 NewSessionQueueOptions newSessionQueueOptions = new NewSessionQueueOptions(config);125 NewSessionQueue sessionRequests = new LocalNewSessionQueue(126 tracer,127 bus,128 newSessionQueueOptions.getSessionRequestRetryInterval(),129 newSessionQueueOptions.getSessionRequestTimeout());130 NewSessionQueuer queuer = new LocalNewSessionQueuer(131 tracer,132 bus,133 sessionRequests,134 registrationSecret);135 combinedHandler.addHandler(queuer);136 DistributorOptions distributorOptions = new DistributorOptions(config);137 Distributor distributor = new LocalDistributor(138 tracer,139 bus,140 clientFactory,141 sessions,142 queuer,143 registrationSecret,144 distributorOptions.getHealthCheckInterval());...
Source:Hub.java
...40import org.openqa.selenium.grid.sessionmap.local.LocalSessionMap;41import org.openqa.selenium.grid.sessionqueue.NewSessionQueue;42import org.openqa.selenium.grid.sessionqueue.NewSessionQueuer;43import org.openqa.selenium.grid.sessionqueue.config.NewSessionQueueOptions;44import org.openqa.selenium.grid.sessionqueue.local.LocalNewSessionQueue;45import org.openqa.selenium.grid.sessionqueue.local.LocalNewSessionQueuer;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_QUEUER_ROLE;69import static org.openqa.selenium.grid.config.StandardGridRoles.SESSION_QUEUE_ROLE;70import static org.openqa.selenium.remote.http.Route.combine;71@AutoService(CliCommand.class)72public class Hub extends TemplateGridServerCommand {73 private static final Logger LOG = Logger.getLogger(Hub.class.getName());74 @Override75 public String getName() {76 return "hub";77 }78 @Override79 public String getDescription() {80 return "A grid hub, composed of sessions, distributor, and router.";81 }82 @Override83 public Set<Role> getConfigurableRoles() {84 return ImmutableSet.of(85 DISTRIBUTOR_ROLE,86 EVENT_BUS_ROLE,87 HTTPD_ROLE,88 SESSION_QUEUE_ROLE,89 SESSION_QUEUER_ROLE,90 ROUTER_ROLE);91 }92 @Override93 public Set<Object> getFlagObjects() {94 return Collections.emptySet();95 }96 @Override97 protected String getSystemPropertiesConfigPrefix() {98 return "selenium";99 }100 @Override101 protected Config getDefaultConfig() {102 return new DefaultHubConfig();103 }104 @Override105 protected Handlers createHandlers(Config config) {106 LoggingOptions loggingOptions = new LoggingOptions(config);107 Tracer tracer = loggingOptions.getTracer();108 EventBusOptions events = new EventBusOptions(config);109 EventBus bus = events.getEventBus();110 CombinedHandler handler = new CombinedHandler();111 SessionMap sessions = new LocalSessionMap(tracer, bus);112 handler.addHandler(sessions);113 BaseServerOptions serverOptions = new BaseServerOptions(config);114 SecretOptions secretOptions = new SecretOptions(config);115 Secret secret = secretOptions.getRegistrationSecret();116 URL externalUrl;117 try {118 externalUrl = serverOptions.getExternalUri().toURL();119 } catch (MalformedURLException e) {120 throw new IllegalArgumentException(e);121 }122 NetworkOptions networkOptions = new NetworkOptions(config);123 HttpClient.Factory clientFactory = new RoutableHttpClientFactory(124 externalUrl,125 handler,126 networkOptions.getHttpClientFactory(tracer));127 NewSessionQueueOptions newSessionQueueOptions = new NewSessionQueueOptions(config);128 NewSessionQueue sessionRequests = new LocalNewSessionQueue(129 tracer,130 bus,131 newSessionQueueOptions.getSessionRequestRetryInterval(),132 newSessionQueueOptions.getSessionRequestTimeout());133 NewSessionQueuer queuer = new LocalNewSessionQueuer(tracer, bus, sessionRequests, secret);134 handler.addHandler(queuer);135 DistributorOptions distributorOptions = new DistributorOptions(config);136 Distributor distributor = new LocalDistributor(137 tracer,138 bus,139 clientFactory,140 sessions,141 queuer,142 secret,143 distributorOptions.getHealthCheckInterval());144 handler.addHandler(distributor);145 Router router = new Router(tracer, clientFactory, sessions, queuer, distributor);146 GraphqlHandler graphqlHandler = new GraphqlHandler(147 tracer,...
Source:RouterTest.java
...31import org.openqa.selenium.grid.security.Secret;32import org.openqa.selenium.grid.sessionmap.SessionMap;33import org.openqa.selenium.grid.sessionmap.local.LocalSessionMap;34import org.openqa.selenium.grid.sessionqueue.NewSessionQueuer;35import org.openqa.selenium.grid.sessionqueue.local.LocalNewSessionQueue;36import org.openqa.selenium.grid.sessionqueue.local.LocalNewSessionQueuer;37import org.openqa.selenium.grid.testing.PassthroughHttpClient;38import org.openqa.selenium.grid.testing.TestSessionFactory;39import org.openqa.selenium.grid.web.CombinedHandler;40import org.openqa.selenium.grid.web.Values;41import org.openqa.selenium.remote.http.HttpClient;42import org.openqa.selenium.remote.http.HttpRequest;43import org.openqa.selenium.remote.http.HttpResponse;44import org.openqa.selenium.remote.tracing.DefaultTestTracer;45import org.openqa.selenium.remote.tracing.Tracer;46import org.openqa.selenium.support.ui.FluentWait;47import java.net.URI;48import java.net.URISyntaxException;49import java.time.Duration;50import java.time.Instant;51import java.util.Map;52import java.util.concurrent.atomic.AtomicReference;53import static org.junit.Assert.assertFalse;54import static org.junit.Assert.assertNotNull;55import static org.openqa.selenium.grid.data.Availability.DOWN;56import static org.openqa.selenium.grid.data.Availability.UP;57import static org.openqa.selenium.json.Json.MAP_TYPE;58import static org.openqa.selenium.remote.http.HttpMethod.GET;59public class RouterTest {60 private Tracer tracer;61 private EventBus bus;62 private CombinedHandler handler;63 private SessionMap sessions;64 private NewSessionQueuer queuer;65 private Distributor distributor;66 private Router router;67 private Secret registrationSecret;68 @Before69 public void setUp() {70 tracer = DefaultTestTracer.createTracer();71 bus = new GuavaEventBus();72 handler = new CombinedHandler();73 HttpClient.Factory clientFactory = new PassthroughHttpClient.Factory(handler);74 sessions = new LocalSessionMap(tracer, bus);75 handler.addHandler(sessions);76 registrationSecret = new Secret("stinking bishop");77 LocalNewSessionQueue localNewSessionQueue = new LocalNewSessionQueue(78 tracer,79 bus,80 Duration.ofSeconds(2),81 Duration.ofSeconds(2));82 queuer = new LocalNewSessionQueuer(tracer, bus, localNewSessionQueue, registrationSecret);83 handler.addHandler(queuer);84 distributor = new LocalDistributor(85 tracer,86 bus,87 clientFactory,88 sessions,89 queuer,90 registrationSecret,91 Duration.ofMinutes(5));92 handler.addHandler(distributor);93 router = new Router(tracer, clientFactory, sessions, queuer, distributor);94 }95 @Test96 public void shouldListAnEmptyDistributorAsMeaningTheGridIsNotReady() {...
Source:LocalNewSessionQueuer.java
...30import org.openqa.selenium.remote.tracing.Tracer;31import java.time.Duration;32import java.util.Optional;33import java.util.logging.Logger;34public class LocalNewSessionQueuer extends NewSessionQueuer {35 private static final Logger LOG = Logger.getLogger(LocalNewSessionQueuer.class.getName());36 private final EventBus bus;37 public final NewSessionQueue sessionRequests;38 public LocalNewSessionQueuer(Tracer tracer, EventBus bus,39 NewSessionQueue sessionRequests) {40 super(tracer);41 this.bus = Require.nonNull("Event bus", bus);42 this.sessionRequests = Require.nonNull("New Session Request Queue", sessionRequests);43 }44 public static NewSessionQueuer create(Config config) {45 Tracer tracer = new LoggingOptions(config).getTracer();46 EventBus bus = new EventBusOptions(config).getEventBus();47 Duration retryInterval = new NewSessionQueueOptions(config).getSessionRequestRetryInterval();48 NewSessionQueue sessionRequests = new LocalNewSessionQueue(tracer, bus, retryInterval);49 return new LocalNewSessionQueuer(tracer, bus, sessionRequests);50 }51 @Override52 public HttpResponse addToQueue(HttpRequest request) {53 validateSessionRequest(request);54 GetNewSessionResponse55 getNewSessionResponse = new GetNewSessionResponse(tracer, bus, sessionRequests);56 return getNewSessionResponse.add(request);57 }58 @Override59 public boolean retryAddToQueue(HttpRequest request, RequestId reqId) {60 return sessionRequests.offerFirst(request, reqId);61 }62 @Override63 public Optional<HttpRequest> remove() {...
Source:GridModelTest.java
...21import org.openqa.selenium.grid.distributor.Distributor;22import org.openqa.selenium.grid.security.Secret;23import org.openqa.selenium.grid.sessionmap.SessionMap;24import org.openqa.selenium.grid.sessionmap.local.LocalSessionMap;25import org.openqa.selenium.grid.sessionqueue.local.LocalNewSessionQueue;26import org.openqa.selenium.grid.sessionqueue.local.LocalNewSessionQueuer;27import org.openqa.selenium.remote.http.HttpClient;28import org.openqa.selenium.remote.tracing.DefaultTestTracer;29import org.openqa.selenium.remote.tracing.Tracer;30import java.time.Duration;31public class GridModelTest {32 private final Tracer tracer = DefaultTestTracer.createTracer();33 private final EventBus events = new GuavaEventBus();34 private final HttpClient.Factory clientFactory = HttpClient.Factory.createDefault();35 private final SessionMap sessions = new LocalSessionMap(tracer, events);36 private final Secret secret = new Secret("cheese");37 LocalNewSessionQueue localNewSessionQueue = new LocalNewSessionQueue(38 tracer,39 events,40 Duration.ofSeconds(2),41 Duration.ofSeconds(2));42 LocalNewSessionQueuer queuer = new LocalNewSessionQueuer(43 tracer,44 events,45 localNewSessionQueue,46 secret);47 private final Distributor distributor = new LocalDistributor(48 tracer,49 events,50 clientFactory,51 sessions,52 queuer,53 secret,54 Duration.ofMinutes(5));55 @Test56 public void shouldNotChangeTheStateOfANodeMarkedAsDownWhenNodeStatusEventFires() {...
LocalNewSessionQueue
Using AI Code Generation
1LocalNewSessionQueue newSessionQueue = new LocalNewSessionQueue();2LocalSessionFactory sessionFactory = new LocalSessionFactory();3LocalSessionQueue sessionQueue = new LocalSessionQueue(newSessionQueue, sessionFactory);4LocalNewSessionQueue newSessionQueue = new LocalNewSessionQueue();5LocalSessionFactory sessionFactory = new LocalSessionFactory();6LocalSessionQueue sessionQueue = new LocalSessionQueue(newSessionQueue, sessionFactory);7LocalNewSessionQueue newSessionQueue = new LocalNewSessionQueue();8LocalSessionFactory sessionFactory = new LocalSessionFactory();9LocalSessionQueue sessionQueue = new LocalSessionQueue(newSessionQueue, sessionFactory);10LocalNewSessionQueue newSessionQueue = new LocalNewSessionQueue();11LocalSessionFactory sessionFactory = new LocalSessionFactory();12LocalSessionQueue sessionQueue = new LocalSessionQueue(newSessionQueue, sessionFactory);13LocalNewSessionQueue newSessionQueue = new LocalNewSessionQueue();14LocalSessionFactory sessionFactory = new LocalSessionFactory();15LocalSessionQueue sessionQueue = new LocalSessionQueue(newSessionQueue, sessionFactory);16LocalNewSessionQueue newSessionQueue = new LocalNewSessionQueue();17LocalSessionFactory sessionFactory = new LocalSessionFactory();18LocalSessionQueue sessionQueue = new LocalSessionQueue(newSessionQueue, sessionFactory);19LocalNewSessionQueue newSessionQueue = new LocalNewSessionQueue();20LocalSessionFactory sessionFactory = new LocalSessionFactory();21LocalSessionQueue sessionQueue = new LocalSessionQueue(newSessionQueue, sessionFactory);22LocalNewSessionQueue newSessionQueue = new LocalNewSessionQueue();23LocalSessionFactory sessionFactory = new LocalSessionFactory();24LocalSessionQueue sessionQueue = new LocalSessionQueue(newSessionQueue, sessionFactory);25LocalNewSessionQueue newSessionQueue = new LocalNewSessionQueue();26LocalSessionFactory sessionFactory = new LocalSessionFactory();27LocalSessionQueue sessionQueue = new LocalSessionQueue(newSessionQueue, sessionFactory);28LocalNewSessionQueue newSessionQueue = new LocalNewSessionQueue();
LocalNewSessionQueue
Using AI Code Generation
1LocalNewSessionQueue queue = new LocalNewSessionQueue();2queue.addSessionRequest(request);3queue.addSessionRequest(request);4queue.addSessionRequest(request);5queue.addSessionRequest(request);6queue.addSessionRequest(request);7queue.addSessionRequest(request);8LocalNewSessionQueue queue = new LocalNewSessionQueue();9queue.addSessionRequest(request);10queue.addSessionRequest(request);11queue.addSessionRequest(request);12queue.addSessionRequest(request);13queue.addSessionRequest(request);14queue.addSessionRequest(request);15LocalNewSessionQueue queue = new LocalNewSessionQueue();16queue.addSessionRequest(request);17queue.addSessionRequest(request);18queue.addSessionRequest(request);19queue.addSessionRequest(request);20queue.addSessionRequest(request);21queue.addSessionRequest(request);22LocalNewSessionQueue queue = new LocalNewSessionQueue();23queue.addSessionRequest(request);24queue.addSessionRequest(request);25queue.addSessionRequest(request);26queue.addSessionRequest(request);27queue.addSessionRequest(request);28queue.addSessionRequest(request);29LocalNewSessionQueue queue = new LocalNewSessionQueue();30queue.addSessionRequest(request);31queue.addSessionRequest(request);32queue.addSessionRequest(request);33queue.addSessionRequest(request);34queue.addSessionRequest(request);35queue.addSessionRequest(request);36LocalNewSessionQueue queue = new LocalNewSessionQueue();37queue.addSessionRequest(request);38queue.addSessionRequest(request);39queue.addSessionRequest(request);40queue.addSessionRequest(request);41queue.addSessionRequest(request);42queue.addSessionRequest(request);43LocalNewSessionQueue queue = new LocalNewSessionQueue();44queue.addSessionRequest(request);45queue.addSessionRequest(request);46queue.addSessionRequest(request);47queue.addSessionRequest(request);48queue.addSessionRequest(request);49queue.addSessionRequest(request);50LocalNewSessionQueue queue = new LocalNewSessionQueue();51queue.addSessionRequest(request);52queue.addSessionRequest(request);53queue.addSessionRequest(request
LocalNewSessionQueue
Using AI Code Generation
1NewSessionQueue queue = new LocalNewSessionQueue();2NewSessionQueue queue = new LocalNewSessionQueue();3NewSessionQueue queue = new LocalNewSessionQueue();4NewSessionQueue queue = new LocalNewSessionQueue();5NewSessionQueue queue = new LocalNewSessionQueue();6NewSessionQueue queue = new LocalNewSessionQueue();7NewSessionQueue queue = new LocalNewSessionQueue();
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.
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.
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.
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.
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.
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.
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.
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.
LambdaTest also provides certification for Selenium testing to accelerate your career in Selenium automation testing.
Get 100 minutes of automation test minutes FREE!!