How to use listener method of org.openqa.selenium.grid.data.NewSessionRequestEvent class

Best Selenium code snippet using org.openqa.selenium.grid.data.NewSessionRequestEvent.listener

Source:GraphqlHandlerTest.java Github

copy

Full Screen

...147 }148 private void continueOnceAddedToQueue(SessionRequest request) {149 // Add to the queue in the background150 CountDownLatch latch = new CountDownLatch(1);151 events.addListener(NewSessionRequestEvent.listener(id -> latch.countDown()));152 new Thread(() -> {153 queue.addToQueue(request);154 }).start();155 try {156 assertThat(latch.await(5, SECONDS)).isTrue();157 } catch (InterruptedException e) {158 Thread.currentThread().interrupt();159 throw new RuntimeException(e);160 }161 }162 @Test163 public void shouldBeAbleToGetSessionQueueSize() throws URISyntaxException {164 SessionRequest request = new SessionRequest(165 new RequestId(UUID.randomUUID()),...

Full Screen

Full Screen

Source:LocalNewSessionQueueTest.java Github

copy

Full Screen

...157 }158 @Test159 public void shouldBeAbleToAddToQueueAndGetValidResponse() {160 AtomicBoolean isPresent = new AtomicBoolean(false);161 bus.addListener(NewSessionRequestEvent.listener(reqId -> {162 isPresent.set(true);163 Capabilities capabilities = new ImmutableCapabilities("browserName", "chrome");164 SessionId sessionId = new SessionId("123");165 Session session =166 new Session(167 sessionId,168 URI.create("http://example.com"),169 CAPS,170 capabilities,171 Instant.now());172 CreateSessionResponse sessionResponse = new CreateSessionResponse(173 session,174 JSON.toJson(175 ImmutableMap.of(176 "value", ImmutableMap.of(177 "sessionId", sessionId,178 "capabilities", capabilities)))179 .getBytes(UTF_8));180 queue.complete(reqId, Either.right(sessionResponse));181 }));182 HttpResponse httpResponse = queue.addToQueue(sessionRequest);183 assertThat(isPresent.get()).isTrue();184 assertEquals(httpResponse.getStatus(), HTTP_OK);185 }186 @Test187 public void shouldBeAbleToAddToQueueAndGetErrorResponse() {188 bus.addListener(NewSessionRequestEvent.listener(reqId ->189 queue.complete(reqId, Either.left(new SessionNotCreatedException("Error")))));190 HttpResponse httpResponse = queue.addToQueue(sessionRequest);191 assertEquals(httpResponse.getStatus(), HTTP_INTERNAL_ERROR);192 }193 @Test194 public void shouldBeAbleToRemoveFromQueue() {195 Optional<SessionRequest> httpRequest = queue.remove(new RequestId(UUID.randomUUID()));196 assertFalse(httpRequest.isPresent());197 }198 @Test199 public void shouldBeClearQueue() {200 RequestId requestId = new RequestId(UUID.randomUUID());201 localQueue.injectIntoQueue(sessionRequest);202 int count = queue.clearQueue();203 assertEquals(count, 1);204 assertFalse(queue.remove(requestId).isPresent());205 }206 @Test207 public void shouldBeAbleToGetQueueContents() {208 localQueue.injectIntoQueue(sessionRequest);209 List<Set<Capabilities>> response = queue.getQueueContents()210 .stream()211 .map(SessionRequestCapability::getDesiredCapabilities)212 .collect(Collectors.toList());213 assertThat(response).hasSize(1);214 assertEquals(Set.of(CAPS), response.get(0));215 }216 @Test217 public void shouldBeClearQueueAndFireRejectedEvent() throws InterruptedException {218 AtomicBoolean result = new AtomicBoolean(false);219 RequestId requestId = sessionRequest.getRequestId();220 CountDownLatch latch = new CountDownLatch(1);221 bus.addListener(222 NewSessionRejectedEvent.listener(223 response -> {224 result.set(response.getRequestId().equals(requestId));225 latch.countDown();226 }));227 localQueue.injectIntoQueue(sessionRequest);228 queue.remove(requestId);229 queue.retryAddToQueue(sessionRequest);230 int count = queue.clearQueue();231 assertThat(latch.await(2, SECONDS)).isTrue();232 assertThat(result.get()).isTrue();233 assertEquals(count, 1);234 assertFalse(queue.remove(requestId).isPresent());235 }236 @Test237 public void removingARequestIdThatDoesNotExistInTheQueueShouldNotBeAnError() {238 localQueue.injectIntoQueue(sessionRequest);239 Optional<SessionRequest> httpRequest = queue.remove(new RequestId(UUID.randomUUID()));240 assertFalse(httpRequest.isPresent());241 }242 @Test243 public void shouldBeAbleToAddAgainToQueue() {244 localQueue.injectIntoQueue(sessionRequest);245 Optional<SessionRequest> removed = queue.remove(sessionRequest.getRequestId());246 assertThat(removed).isPresent();247 boolean added = queue.retryAddToQueue(sessionRequest);248 assertTrue(added);249 }250 @Test251 public void shouldBeAbleToRetryRequest() {252 AtomicBoolean isPresent = new AtomicBoolean(false);253 AtomicBoolean retrySuccess = new AtomicBoolean(false);254 AtomicInteger count = new AtomicInteger(0);255 bus.addListener(256 NewSessionRequestEvent.listener(257 reqId -> {258 // Keep a count of event fired259 count.incrementAndGet();260 Optional<SessionRequest> sessionRequest = this.queue.remove(reqId);261 isPresent.set(sessionRequest.isPresent());262 if (count.get() == 1) {263 retrySuccess.set(queue.retryAddToQueue(sessionRequest.get()));264 }265 // Only if it was retried after an interval, the count is 2266 if (count.get() == 2) {267 ImmutableCapabilities capabilities =268 new ImmutableCapabilities("browserName", "edam");269 try {270 SessionId sessionId = new SessionId("123");271 Session session =272 new Session(273 sessionId,274 new URI("http://example.com"),275 CAPS,276 capabilities,277 Instant.now());278 CreateSessionResponse sessionResponse =279 new CreateSessionResponse(280 session,281 JSON.toJson(282 ImmutableMap.of(283 "value",284 ImmutableMap.of(285 "sessionId", sessionId,286 "capabilities", capabilities)))287 .getBytes(UTF_8));288 queue.complete(reqId, Either.right(sessionResponse));289 } catch (URISyntaxException e) {290 throw new RuntimeException(e);291 }292 }293 }));294 HttpResponse httpResponse = queue.addToQueue(sessionRequest);295 assertThat(isPresent.get()).isTrue();296 assertThat(retrySuccess.get()).isTrue();297 assertEquals(httpResponse.getStatus(), HTTP_OK);298 }299 @Test(timeout = 5000)300 public void shouldBeAbleToHandleMultipleSessionRequestsAtTheSameTime() {301 bus.addListener(NewSessionRequestEvent.listener(reqId -> {302 queue.remove(reqId);303 ImmutableCapabilities capabilities = new ImmutableCapabilities("browserName", "chrome");304 try {305 SessionId sessionId = new SessionId(UUID.randomUUID());306 Session session =307 new Session(308 sessionId,309 new URI("http://example.com"),310 CAPS,311 capabilities,312 Instant.now());313 CreateSessionResponse sessionResponse = new CreateSessionResponse(314 session,315 JSON.toJson(316 ImmutableMap.of(317 "value", ImmutableMap.of(318 "sessionId", sessionId,319 "capabilities", capabilities)))320 .getBytes(UTF_8));321 queue.complete(reqId, Either.right(sessionResponse));322 } catch (URISyntaxException e) {323 queue.complete(reqId, Either.left(new SessionNotCreatedException(e.getMessage())));324 }325 }));326 ExecutorService executor = Executors.newFixedThreadPool(2);327 Callable<HttpResponse> callable = () -> {328 SessionRequest sessionRequest = new SessionRequest(329 new RequestId(UUID.randomUUID()),330 Instant.now(),331 Set.of(W3C),332 Set.of(CAPS),333 Map.of(),334 Map.of());335 return queue.addToQueue(sessionRequest);336 };337 Future<HttpResponse> firstRequest = executor.submit(callable);338 Future<HttpResponse> secondRequest = executor.submit(callable);339 try {340 HttpResponse firstResponse = firstRequest.get(30, SECONDS);341 HttpResponse secondResponse = secondRequest.get(30, SECONDS);342 String firstResponseContents = Contents.string(firstResponse);343 String secondResponseContents = Contents.string(secondResponse);344 assertEquals(firstResponse.getStatus(), HTTP_OK);345 assertEquals(secondResponse.getStatus(), HTTP_OK);346 assertNotEquals(firstResponseContents, secondResponseContents);347 } catch (InterruptedException | ExecutionException | TimeoutException e) {348 fail("Could not create session");349 }350 executor.shutdown();351 }352 @Test(timeout = 5000)353 public void shouldBeAbleToTimeoutARequestOnRetry() {354 final SessionRequest request = new SessionRequest(355 new RequestId(UUID.randomUUID()),356 LONG_AGO,357 Set.of(W3C),358 Set.of(CAPS),359 Map.of(),360 Map.of());361 AtomicInteger count = new AtomicInteger();362 bus.addListener(NewSessionRejectedEvent.listener(reqId -> {363 count.incrementAndGet();364 }));365 HttpResponse httpResponse = queue.addToQueue(request);366 assertEquals(1, count.get());367 assertEquals(HTTP_INTERNAL_ERROR, httpResponse.getStatus());368 }369 @Test(timeout = 10000)370 public void shouldBeAbleToTimeoutARequestOnRemove() throws InterruptedException {371 AtomicReference<RequestId> isPresent = new AtomicReference<>();372 CountDownLatch latch = new CountDownLatch(1);373 bus.addListener(374 NewSessionRejectedEvent.listener(375 response -> {376 isPresent.set(response.getRequestId());377 latch.countDown();378 }));379 SessionRequest sessionRequest = new SessionRequest(380 new RequestId(UUID.randomUUID()),381 LONG_AGO,382 Set.of(W3C),383 Set.of(CAPS),384 Map.of(),385 Map.of());386 localQueue.injectIntoQueue(sessionRequest);387 queue.remove(sessionRequest.getRequestId());388 assertThat(latch.await(4, SECONDS)).isTrue();...

Full Screen

Full Screen

Source:NewSessionQueuerTest.java Github

copy

Full Screen

...101 }102 @Test103 public void shouldBeAbleToAddToQueueAndGetValidResponse() {104 AtomicBoolean isPresent = new AtomicBoolean(false);105 bus.addListener(NewSessionRequestEvent.listener(reqId -> {106 Optional<HttpRequest> sessionRequest = this.local.remove();107 isPresent.set(sessionRequest.isPresent());108 Capabilities capabilities = new ImmutableCapabilities("browserName", "chrome");109 try {110 SessionId sessionId = new SessionId("123");111 Session session =112 new Session(113 sessionId,114 new URI("http://example.com"),115 caps,116 capabilities,117 Instant.now());118 CreateSessionResponse sessionResponse = new CreateSessionResponse(119 session,120 JSON.toJson(121 ImmutableMap.of(122 "value", ImmutableMap.of(123 "sessionId", sessionId,124 "capabilities", capabilities)))125 .getBytes(UTF_8));126 NewSessionResponse newSessionResponse =127 new NewSessionResponse(reqId, sessionResponse.getSession(),128 sessionResponse.getDownstreamEncodedResponse());129 bus.fire(new NewSessionResponseEvent(newSessionResponse));130 } catch (URISyntaxException e) {131 bus.fire(132 new NewSessionRejectedEvent(133 new NewSessionErrorResponse(new RequestId(UUID.randomUUID()), "Error")));134 }135 }));136 HttpResponse httpResponse = local.addToQueue(request);137 assertThat(isPresent.get()).isTrue();138 assertEquals(httpResponse.getStatus(), HTTP_OK);139 }140 @Test141 public void shouldBeAbleToAddToQueueAndGetErrorResponse() {142 AtomicBoolean isPresent = new AtomicBoolean(false);143 bus.addListener(NewSessionRequestEvent.listener(reqId -> {144 Optional<HttpRequest> sessionRequest = this.local.remove();145 isPresent.set(sessionRequest.isPresent());146 bus.fire(147 new NewSessionRejectedEvent(148 new NewSessionErrorResponse(reqId, "Error")));149 }));150 HttpResponse httpResponse = local.addToQueue(request);151 assertThat(isPresent.get()).isTrue();152 assertEquals(httpResponse.getStatus(), HTTP_INTERNAL_ERROR);153 }154 @Test155 public void shouldBeAbleToAddToQueueRemotelyAndGetErrorResponse() {156 AtomicBoolean isPresent = new AtomicBoolean(false);157 bus.addListener(NewSessionRequestEvent.listener(reqId -> {158 Optional<HttpRequest> sessionRequest = this.remote.remove();159 isPresent.set(sessionRequest.isPresent());160 bus.fire(161 new NewSessionRejectedEvent(162 new NewSessionErrorResponse(reqId, "Could not poll the queue")));163 }));164 HttpResponse httpResponse = remote.addToQueue(request);165 assertThat(isPresent.get()).isTrue();166 assertEquals(httpResponse.getStatus(), HTTP_INTERNAL_ERROR);167 }168 @Test169 public void shouldBeAbleToRemoveFromQueue() {170 Optional<HttpRequest> httpRequest = local.remove();171 assertFalse(httpRequest.isPresent());172 }173 @Test174 public void shouldBeClearQueue() {175 RequestId requestId = new RequestId(UUID.randomUUID());176 sessionQueue.offerLast(request, requestId);177 int count = local.clearQueue();178 assertEquals(count, 1);179 assertFalse(local.remove().isPresent());180 }181 @Test182 public void shouldBeClearQueueRemotely() {183 RequestId requestId = new RequestId(UUID.randomUUID());184 sessionQueue.offerLast(request, requestId);185 int count = remote.clearQueue();186 assertEquals(count, 1);187 assertFalse(remote.remove().isPresent());188 }189 @Test190 public void shouldBeClearQueueAndFireRejectedEvent() {191 AtomicBoolean result = new AtomicBoolean(false);192 RequestId requestId = new RequestId(UUID.randomUUID());193 bus.addListener(NewSessionRejectedEvent.listener(response ->194 result.set(response.getRequestId()195 .equals(requestId))));196 sessionQueue.offerLast(request, requestId);197 int count = remote.clearQueue();198 assertThat(result.get()).isTrue();199 assertEquals(count, 1);200 assertFalse(remote.remove().isPresent());201 }202 @Test203 public void shouldBeAbleToRemoveFromQueueRemotely() {204 Optional<HttpRequest> httpRequest = remote.remove();205 assertFalse(httpRequest.isPresent());206 }207 @Test208 public void shouldBeAbleToAddAgainToQueue() {209 boolean added = local.retryAddToQueue(request, new RequestId(UUID.randomUUID()));210 assertTrue(added);211 }212 @Test213 public void shouldBeAbleToAddAgainToQueueRemotely() {214 HttpRequest request = createRequest(payload, POST, "/se/grid/newsessionqueuer/session");215 boolean added = remote.retryAddToQueue(request, new RequestId(UUID.randomUUID()));216 assertTrue(added);217 }218 @Test219 public void shouldBeAbleToRetryRequest() {220 AtomicBoolean isPresent = new AtomicBoolean(false);221 AtomicBoolean retrySuccess = new AtomicBoolean(false);222 bus.addListener(NewSessionRequestEvent.listener(reqId -> {223 // Keep a count of event fired224 count++;225 Optional<HttpRequest> sessionRequest = this.remote.remove();226 isPresent.set(sessionRequest.isPresent());227 if (count == 1) {228 retrySuccess.set(remote.retryAddToQueue(sessionRequest.get(), reqId));229 }230 // Only if it was retried after an interval, the count is 2231 if (count == 2) {232 ImmutableCapabilities capabilities = new ImmutableCapabilities("browserName", "chrome");233 try {234 SessionId sessionId = new SessionId("123");235 Session session =236 new Session(237 sessionId,238 new URI("http://example.com"),239 caps,240 capabilities,241 Instant.now());242 CreateSessionResponse sessionResponse = new CreateSessionResponse(243 session,244 JSON.toJson(245 ImmutableMap.of(246 "value", ImmutableMap.of(247 "sessionId", sessionId,248 "capabilities", capabilities)))249 .getBytes(UTF_8));250 NewSessionResponse newSessionResponse =251 new NewSessionResponse(reqId, sessionResponse.getSession(),252 sessionResponse.getDownstreamEncodedResponse());253 bus.fire(new NewSessionResponseEvent(newSessionResponse));254 } catch (URISyntaxException e) {255 bus.fire(256 new NewSessionRejectedEvent(257 new NewSessionErrorResponse(new RequestId(UUID.randomUUID()), "Error")));258 }259 }260 }));261 HttpResponse httpResponse = remote.addToQueue(request);262 assertThat(isPresent.get()).isTrue();263 assertThat(retrySuccess.get()).isTrue();264 assertEquals(httpResponse.getStatus(), HTTP_OK);265 }266 @Test267 public void shouldBeAbleToHandleMultipleSessionRequestsAtTheSameTime() {268 bus.addListener(NewSessionRequestEvent.listener(reqId -> {269 Optional<HttpRequest> sessionRequest = this.local.remove();270 ImmutableCapabilities capabilities = new ImmutableCapabilities("browserName", "chrome");271 try {272 SessionId sessionId = new SessionId(UUID.randomUUID());273 Session session =274 new Session(275 sessionId,276 new URI("http://example.com"),277 caps,278 capabilities,279 Instant.now());280 CreateSessionResponse sessionResponse = new CreateSessionResponse(281 session,282 JSON.toJson(283 ImmutableMap.of(284 "value", ImmutableMap.of(285 "sessionId", sessionId,286 "capabilities", capabilities)))287 .getBytes(UTF_8));288 NewSessionResponse newSessionResponse =289 new NewSessionResponse(reqId, sessionResponse.getSession(),290 sessionResponse.getDownstreamEncodedResponse());291 bus.fire(new NewSessionResponseEvent(newSessionResponse));292 } catch (URISyntaxException e) {293 bus.fire(294 new NewSessionRejectedEvent(295 new NewSessionErrorResponse(new RequestId(UUID.randomUUID()), "Error")));296 }297 }));298 ExecutorService executor = Executors.newFixedThreadPool(2);299 Callable<HttpResponse> callable = () -> remote.addToQueue(request);300 Future<HttpResponse> firstRequest = executor.submit(callable);301 Future<HttpResponse> secondRequest = executor.submit(callable);302 try {303 HttpResponse firstResponse = firstRequest.get(30, TimeUnit.SECONDS);304 HttpResponse secondResponse = secondRequest.get(30, TimeUnit.SECONDS);305 String firstResponseContents = Contents.string(firstResponse);306 String secondResponseContents = Contents.string(secondResponse);307 assertEquals(firstResponse.getStatus(), HTTP_OK);308 assertEquals(secondResponse.getStatus(), HTTP_OK);309 assertNotEquals(firstResponseContents, secondResponseContents);310 } catch (InterruptedException | ExecutionException | TimeoutException e) {311 fail("Could not create session");312 }313 executor.shutdown();314 }315 @Test316 public void shouldBeAbleToTimeoutARequestOnRetry() {317 Tracer tracer = DefaultTestTracer.createTracer();318 LocalNewSessionQueue sessionQueue = new LocalNewSessionQueue(319 tracer,320 bus,321 Duration.ofSeconds(4),322 Duration.ofSeconds(2));323 local = new LocalNewSessionQueuer(tracer, bus, sessionQueue);324 HttpClient client = new PassthroughHttpClient(local);325 remote = new RemoteNewSessionQueuer(tracer, client);326 HttpRequest request = createRequest(payload, POST, "/session");327 request.addHeader(SESSIONREQUEST_TIMESTAMP_HEADER,328 Long.toString(1539091064));329 AtomicInteger count = new AtomicInteger();330 bus.addListener(NewSessionRequestEvent.listener(reqId -> {331 // Add to front of queue, when retry is triggered it will check if request timed out332 count.incrementAndGet();333 remote.retryAddToQueue(request, reqId);334 }));335 HttpResponse httpResponse = remote.addToQueue(request);336 assertEquals(count.get(),1);337 assertEquals(httpResponse.getStatus(), HTTP_INTERNAL_ERROR);338 }339 @Test340 public void shouldBeAbleToTimeoutARequestOnPoll() {341 Tracer tracer = DefaultTestTracer.createTracer();342 LocalNewSessionQueue sessionQueue = new LocalNewSessionQueue(343 tracer,344 bus,345 Duration.ofSeconds(4),346 Duration.ofSeconds(0));347 local = new LocalNewSessionQueuer(tracer, bus, sessionQueue);348 HttpClient client = new PassthroughHttpClient(local);349 remote = new RemoteNewSessionQueuer(tracer, client);350 AtomicBoolean isPresent = new AtomicBoolean();351 bus.addListener(NewSessionRequestEvent.listener(reqId -> {352 Optional<HttpRequest> request = remote.remove();353 isPresent.set(request.isPresent());354 bus.fire(355 new NewSessionRejectedEvent(356 new NewSessionErrorResponse(reqId, "Error")));357 }));358 HttpResponse httpResponse = remote.addToQueue(request);359 assertEquals(httpResponse.getStatus(), HTTP_INTERNAL_ERROR);360 assertThat(isPresent.get()).isFalse();361 }362 @Test363 public void shouldBeAbleToClearQueueAndRejectMultipleRequests() {364 ExecutorService executor = Executors.newFixedThreadPool(2);365 Callable<HttpResponse> callable = () -> remote.addToQueue(request);...

Full Screen

Full Screen

Source:LocalDistributor.java Github

copy

Full Screen

...123 this.nodes = new ConcurrentHashMap<>();124 this.sessionRequests = Require.nonNull("New Session Request Queue", sessionRequests);125 this.registrationSecret = Require.nonNull("Registration secret", registrationSecret);126 this.healthcheckInterval = Require.nonNull("Health check interval", healthcheckInterval);127 bus.addListener(NodeStatusEvent.listener(this::register));128 bus.addListener(NodeStatusEvent.listener(model::refresh));129 bus.addListener(NodeHeartBeatEvent.listener(nodeStatus -> {130 if (nodes.containsKey(nodeStatus.getId())) {131 model.touch(nodeStatus.getId());132 } else {133 register(nodeStatus);134 }135 }));136 bus.addListener(NodeDrainComplete.listener(this::remove));137 bus.addListener(NewSessionRequestEvent.listener(requestIds::offer));138 Regularly regularly = new Regularly("Local Distributor");139 regularly.submit(model::purgeDeadNodes, Duration.ofSeconds(30), Duration.ofSeconds(30));140 Thread shutdownHook = new Thread(this::callExecutorShutdown);141 Runtime.getRuntime().addShutdownHook(shutdownHook);142 NewSessionRunnable runnable = new NewSessionRunnable();143 ThreadFactory threadFactory = r -> {144 Thread thread = new Thread(r);145 thread.setName("New Session Creation");146 thread.setDaemon(true);147 return thread;148 };149 executorService = Executors.newSingleThreadScheduledExecutor(threadFactory);150 executorService.scheduleAtFixedRate(runnable, 0, 1000, TimeUnit.MILLISECONDS);151 }...

Full Screen

Full Screen

Source:LocalNewSessionQueue.java Github

copy

Full Screen

...65 * <li>If the session request is completed, then {@link #complete(RequestId, Either)} must66 * be called. This will not only ensure that {@link #addToQueue(SessionRequest)}67 * returns, but will also fire a {@link NewSessionRejectedEvent} if the session was68 * rejected. Positive completions of events are assumed to be notified on the event bus69 * by other listeners.70 * <li>If the request cannot be handled right now, call71 * {@link #retryAddToQueue(SessionRequest)} to return the session request to the front72 * of the queue.73 * </ol>74 * <p>75 * There is a background thread that will reap {@link SessionRequest}s that have timed out.76 * This means that a request can either complete by a listener calling77 * {@link #complete(RequestId, Either)} directly, or by being reaped by the thread.78 */79@ManagedService(objectName = "org.seleniumhq.grid:type=SessionQueue,name=LocalSessionQueue",80 description = "New session queue")81public class LocalNewSessionQueue extends NewSessionQueue implements Closeable {82 private final EventBus bus;83 private final SlotMatcher slotMatcher;84 private final Duration requestTimeout;85 private final Map<RequestId, Data> requests;86 private final Map<RequestId, TraceContext> contexts;87 private final Deque<SessionRequest> queue;88 private final ReadWriteLock lock = new ReentrantReadWriteLock();89 private final ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor(r -> {90 Thread thread = new Thread(r);...

Full Screen

Full Screen

Source:NewSessionRequestEvent.java Github

copy

Full Screen

...24 private static final EventName NEW_SESSION_REQUEST = new EventName("new-session-request");25 public NewSessionRequestEvent(RequestId requestId) {26 super(NEW_SESSION_REQUEST, requestId);27 }28 public static EventListener<RequestId> listener(Consumer<RequestId> handler) {29 Require.nonNull("Handler", handler);30 return new EventListener<>(NEW_SESSION_REQUEST, RequestId.class, handler);31 }32}

Full Screen

Full Screen

listener

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.grid.data.NewSessionRequestEvent;2import org.openqa.selenium.grid.data.NewSessionQueuedEvent;3import org.openqa.selenium.grid.data.NewSessionRejectedEvent;4import org.openqa.selenium.grid.data.NewSessionRequestEvent.Listener;5import org.openqa.selenium.grid.data.NewSessionRequestEvent.NewSessionRequestListener;6import org.openqa.selenium.grid.data.NewSessionRequestEvent.SessionRequestListener;7import org.openqa.selenium.grid.data.NewSessionRequestEvent.SessionRequestRejectedListener;8import org.openqa.selenium.grid.data.NewSessionRequestEvent.SessionRequestQueuedListener;9import org.openqa.selenium.grid.data.SessionRequest;10import org.openqa.selenium.remote.tracing.Span;11import org.openqa.selenium.remote.tracing.Tracer;12import java.util.Objects;13public class NewSessionRequestEventListeners implements NewSessionRequestListener, SessionRequestListener, SessionRequestQueuedListener, SessionRequestRejectedListener {14 private final Listener listener;15 public NewSessionRequestEventListeners(Listener listener) {16 this.listener = Objects.requireNonNull(listener);17 }18 public void sessionRequested(SessionRequest request) {19 listener.onSessionRequest(request);20 }21 public void sessionRequestQueued(SessionRequest request, Span span) {22 listener.onSessionQueued(request, span);23 }24 public void sessionRequestRejected(SessionRequest request, Span span) {25 listener.onSessionRejected(request, span);26 }27 public static NewSessionRequestListener newSessionRequest(Listener listener) {28 return new NewSessionRequestEventListeners(listener);29 }30 public static SessionRequestListener sessionRequest(Listener listener) {31 return new NewSessionRequestEventListeners(listener);32 }33 public static SessionRequestQueuedListener sessionRequestQueued(Listener listener) {34 return new NewSessionRequestEventListeners(listener);35 }36 public static SessionRequestRejectedListener sessionRequestRejected(Listener listener) {37 return new NewSessionRequestEventListeners(listener);38 }39}40import org.openqa.selenium.grid.data.NewSessionQueuedEvent;41import org.openqa.selenium.grid.data.NewSessionRequestEvent;42import org.openqa.selenium.grid.data.SessionRequest;43import org.openqa.selenium.remote.tracing.Span;44public class NewSessionQueuedEventListeners implements NewSessionRequestEvent.SessionRequestQueuedListener {45 private final NewSessionQueuedEvent.Listener listener;46 public NewSessionQueuedEventListeners(NewSessionQueuedEvent.Listener listener) {

Full Screen

Full Screen

listener

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.grid.data.NewSessionRequestEvent;2import org.openqa.selenium.grid.data.NewSessionQueuedEvent;3import org.openqa.selenium.grid.data.NewSessionRejectedEvent;4import org.openqa.selenium.grid.data.NewSessionRequestEvent.Listener;5import org.openqa.selenium.grid.data.NewSessionRequestEvent.NewSessionRequestListener;6import org.openqa.selenium.grid.data.NewSessionRequestEvent.NewSessionQueuedListener;7import org.openqa.selenium.grid.data.NewSessionRequestEvent.NewSessionRejectedListener;8import org.openqa.selenium.grid.data.Session;9import org.openqa.selenium.grid.data.SessionRequest;10public class ListenerExample {11 public static void main(String[] args) {12 SessionRequest request = null;13 Session session = null;14 NewSessionRequestEvent event = new NewSessionRequestEvent(request);15 NewSessionQueuedEvent queuedEvent = new NewSessionQueuedEvent(request);16 NewSessionRejectedEvent rejectedEvent = new NewSessionRejectedEvent(request, "message");17 Listener listener = new Listener() {18 public void beforeRequest(SessionRequest request) {19 System.out.println("beforeRequest");20 }21 public void afterRequest(SessionRequest request) {22 System.out.println("afterRequest");23 }24 public void beforeQueued(SessionRequest request) {25 System.out.println("beforeQueued");26 }27 public void afterQueued(SessionRequest request) {28 System.out.println("afterQueued");29 }30 public void beforeRejected(SessionRequest request, String message) {31 System.out.println("beforeRejected");32 }33 public void afterRejected(SessionRequest request, String message) {34 System.out.println("afterRejected");35 }36 public void beforeAssigned(SessionRequest request, Session session) {37 System.out.println("beforeAssigned");38 }39 public void afterAssigned(SessionRequest request, Session session) {40 System.out.println("afterAssigned");41 }42 public void beforeCreated(SessionRequest request, Session session) {43 System.out.println("beforeCreated");44 }45 public void afterCreated(SessionRequest request, Session session) {46 System.out.println("afterCreated");47 }48 public void beforeStarted(SessionRequest request, Session session) {49 System.out.println("beforeStarted");50 }51 public void afterStarted(SessionRequest request, Session session

Full Screen

Full Screen

listener

Using AI Code Generation

copy

Full Screen

1package seleniumGrid;2import org.openqa.selenium.grid.config.Config;3import org.openqa.selenium.grid.config.ConfigException;4import org.openqa.selenium.grid.config.MemoizedConfig;5import org.openqa.selenium.grid.config.TomlConfig;6import org.openqa.selenium.grid.data.NewSessionRequestEvent;7import org.openqa.selenium.grid.node.Node;8import org.openqa.selenium.grid.node.local.LocalNode;9import org.openqa.selenium.grid.server.EventBus;10import org.openqa.selenium.grid.server.EventBusOptions;11import org.openqa.selenium.grid.server.Server;12import org.openqa.selenium.grid.server.ServerOptions;13import org.openqa.selenium.grid.web.Routable;14import org.openqa.selenium.grid.web.Routes;15import org.openqa.selenium.remote.http.HttpHandler;16import org.openqa.selenium.remote.http.HttpResponse;17import org.openqa.selenium.remote.http.Route;18import java.io.IOException;19import java.net.URI;20import java.net.URISyntaxException;21import java.util.logging.Logger;22public class GridListener {23 private static final Logger LOG = Logger.getLogger(GridListener.class.getName());24 public static void main(String[] args) throws URISyntaxException, IOException {25 Config config = new MemoizedConfig(new TomlConfig("config.toml"));26 EventBus bus = new EventBus(new EventBusOptions(config));27 Server<?> server = new Server<>(new ServerOptions(config), new HttpHandler() {28 public HttpResponse execute(Route route, org.openqa.selenium.remote.http.HttpRequest request) throws IOException {29 return new HttpResponse().setContent("Hello world!");30 }31 }, new Routable() {32 public void addRoutes(Routes routes) {33 routes.get("/", this);34 }35 });36 URI uri = server.getUrl();37 LOG.info("Server started on " + uri);38 Node node = new LocalNode(39 new LocalNodeOptions(config),40 new NodeStatusListener(bus, uri));41 server.start();42 node.start();43 }44 private static class NodeStatusListener implements NewSessionRequestEvent.Listener {45 private final EventBus bus;46 private final URI uri;47 public NodeStatusListener(EventBus bus, URI uri) {48 this.bus = bus;49 this.uri = uri;50 }51 public void onNewSessionRequest(NewSessionRequestEvent event) {52 LOG.info("New session request received: " + event);53 LOG.info("Current server url: " + uri);54 }55 }56 private static class LocalNodeOptions extends NodeOptions {57 public LocalNodeOptions(Config config) throws ConfigException {

Full Screen

Full Screen

listener

Using AI Code Generation

copy

Full Screen

1import java.io.IOException;2import java.net.URI;3import java.time.Duration;4import java.util.Map;5import java.util.Set;6import java.util.function.Consumer;7import java.util.logging.Level;8import java.util.logging.Logger;9import org.openqa.selenium.Capabilities;10import org.openqa.selenium.ImmutableCapabilities;11import org.openqa.selenium.SessionNotCreatedException;12import org.openqa.selenium.events.EventBus;13import org.openqa.selenium.events.EventBusOptions;14import org.openqa.selenium.events.EventListener;15import org.openqa.selenium.events.EventName;16import org.openqa.selenium.events.EventSink;17import org.openqa.selenium.events.EventSource;18import org.openqa.selenium.events.zeromq.ZeroMqOptions;19import org.openqa.selenium.grid.config.Config;20import org.openqa.selenium.grid.config.MemoizedConfig;21import org.openqa.selenium.grid.config.TomlConfig;22import org.openqa.selenium.grid.data.NewSessionRequestEvent;23import org.openqa.selenium.grid.data.Session;24import org.openqa.selenium.grid.distributor.Distributor;25import org.openqa.selenium.grid.distributor.local.LocalDistributor;26import org.openqa.selenium.grid.node.Node;27import org.openqa.selenium.grid.node.local.LocalNode;28import org.openqa.selenium.grid.security.Secret;29import org.openqa.selenium.grid.server.BaseServerOptions;30import org.openqa.selenium.grid.server.EventBusServer;31import org.openqa.selenium.grid.server.Server;32import org.openqa.selenium.grid.server.ServerFlags;33import org.openqa.selenium.grid.sessionmap.SessionMap;34import org.openqa.selenium.grid.sessionmap.local.LocalSessionMap;35import org.openqa.selenium.grid.web.Routable;36import org.openqa.selenium.grid.web.Routes;37import org.openqa.selenium.internal.Require;38import org.openqa.selenium.json.Json;39import org.openqa.selenium.net.PortProber;40import org.openqa.selenium.remote.http.HttpClient;41import org.openqa.selenium.remote.http.HttpRequest;42import org.openqa.selenium.remote.http.HttpResponse;43import org.openqa.selenium.remote.tracing.DefaultTestTracer;44import org.openqa.selenium.remote.tracing.Tracer;45import org.openqa.selenium.remote.tracing.zeromq.ZeroMqTracer;46import org.openqa.selenium.remote.tracing.zeromq.ZeroMqTracerOptions;47import org.openqa.selenium.support.events.EventFiringWebDriver;48import org.openqa.selenium.support.events.WebDriverEventListener;49import com.google.common.collect.ImmutableMap;50import com.google.common.collect.ImmutableSet;51import com.google.common.collect.Maps;52public class SeleniumGrid {53 private static final Logger LOG = Logger.getLogger(SeleniumGrid.class.getName());54 private static final Json JSON = new Json();55 private static final String CONFIG_FILE = "config.toml";

Full Screen

Full Screen

listener

Using AI Code Generation

copy

Full Screen

1driver.register(new NewSessionRequestListener());2driver.quit();3driver.register(new NewSessionQueuedListener());4driver.quit();5driver.register(new SessionCreatedListener());6driver.quit();7driver.register(new SessionDeletedListener());8driver.quit();9driver.register(new SessionRequestListener());10driver.quit();11driver.register(new SessionRequestCompleteListener());12driver.quit();13driver.register(new SessionRequestFailedListener());14driver.quit();15driver.register(new SessionRequestQueuedListener());16driver.get("

Full Screen

Full Screen

listener

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.grid.data.NewSessionRequestEvent;2import org.openqa.selenium.grid.data.SessionRequest;3import org.openqa.selenium.support.events.EventFiringWebDriver;4import org.openqa.selenium.support.events.WebDriverEventListener;5import org.openqa.selenium.support.events.internal.EventFiringMouse;6import org.openqa.selenium.support.events.internal.EventFiringTouch;7import java.util.Map;8public class SeleniumGridEventListener implements WebDriverEventListener {9 public void beforeNavigateTo(String url, WebDriver driver) {10 System.out.println("Before navigating to: '" + url + "'");11 }12 public void afterNavigateTo(String url, WebDriver driver) {13 System.out.println("Navigated to:'" + url + "'");14 }15 public void beforeChangeValueOf(WebElement element, WebDriver driver, CharSequence[] keysToSend) {16 System.out.println("Value of the:" + element.toString() + " before any changes made");17 }18 public void afterChangeValueOf(WebElement element, WebDriver driver, CharSequence[] keysToSend) {19 System.out.println("Element value changed to: " + element.toString());20 }21 public void beforeClickOn(WebElement element, WebDriver driver) {22 System.out.println("Trying to click on: " + element.toString());23 }24 public void afterClickOn(WebElement element, WebDriver driver) {25 System.out.println("Clicked on: " + element.toString());26 }27 public void beforeNavigateBack(WebDriver driver) {28 System.out.println("Navigating back to previous page");29 }30 public void afterNavigateBack(WebDriver driver) {31 System.out.println("Navigated back to previous page");32 }33 public void beforeNavigateForward(WebDriver driver) {34 System.out.println("Navigating forward to next page");35 }36 public void afterNavigateForward(WebDriver driver) {37 System.out.println("Navigated forward to next page");38 }39 public void onException(Throwable error, WebDriver driver) {40 System.out.println("Exception occured: " + error);41 }42 public <X> void beforeGetScreenshotAs(OutputType<X> target) {43 System.out.println("Before taking screenshot");44 }45 public <X> void afterGetScreenshotAs(OutputType<X> target, X screenshot) {46 System.out.println("After taking screenshot");47 }48 public void beforeGetText(WebElement element, WebDriver driver) {49 System.out.println("Before getting text");50 }51 public void afterGetText(WebElement element,

Full Screen

Full Screen

listener

Using AI Code Generation

copy

Full Screen

1public void onEvent(NewSessionRequestEvent event) {2 System.out.println(event.getSessionRequest());3}4public void onEvent(SessionRequestEvent event) {5 System.out.println(event.getSessionRequest());6}7public void onEvent(SessionRequestQueuedEvent event) {8 System.out.println(event.getSessionRequest());9}10public void onEvent(SessionRequestAssignedEvent event) {11 System.out.println(event.getSessionRequest());12}13public void onEvent(SessionRequestStartedEvent event) {14 System.out.println(event.getSessionRequest());15}16public void onEvent(SessionRequestCompleteEvent event) {17 System.out.println(event.getSessionRequest());18}19public void onEvent(SessionRequestFailedEvent event) {20 System.out.println(event.getSessionRequest());21}22public void onEvent(SessionRequestTimedOutEvent event) {23 System.out.println(event.getSessionRequest());24}25public void onEvent(SessionRequestCancelledEvent event) {26 System.out.println(event.getSessionRequest());27}28public void onEvent(SessionQueuedEvent event) {29 System.out.println(event.getSession());30}31public void onEvent(SessionCreatedEvent

Full Screen

Full Screen

listener

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.grid.config.Config;2import org.openqa.selenium.grid.config.ConfigException;3import org.openqa.selenium.grid.config.MemoizedConfig;4import org.openqa.selenium.grid.data.NewSessionRequestEvent;5import org.openqa.selenium.grid.data.SessionRequest;6import org.openqa.selenium.grid.node.local.LocalNode;7import org.openqa.selenium.grid.server.EventBusConfig;8import org.openqa.selenium.grid.server.EventBusOptions;9import org.openqa.selenium.grid.server.Server;10import org.openqa.selenium.grid.server.ServerOptions;11import org.openqa.selenium.grid.web.Routable;12import org.openqa.selenium.grid.web.Routes;13import org.openqa.selenium.remote.http.Contents;14import org.openqa.selenium.remote.http.HttpRequest;15import org.openqa.selenium.remote.http.HttpResponse;16import org.openqa.selenium.remote.http.Route;17import java.io.IOException;18import java.util.Map;19import java.util.Objects;20import java.util.Optional;21import java.util.concurrent.ConcurrentHashMap;22import java.util.concurrent.TimeUnit;23import static org.openqa.selenium.grid.config.StandardGridRoles.NODE_ROLE;24public class NewSessionRequestEventExample {25 public static void main(String[] args) throws IOException, ConfigException {26 Config config = new MemoizedConfig();27 Server<?> server = new Server<>(new ServerOptions(config));28 LocalNode node = LocalNode.builder(29 new EventBusOptions(config),30 new NodeOptions(config))31 .build();32 node.start();33 server.addHandler(new NewSessionRequestHandler(node));34 server.start();35 server.join();36 }37 private static class NewSessionRequestHandler implements Routable {38 private final LocalNode node;39 public NewSessionRequestHandler(LocalNode node) {40 this.node = Objects.requireNonNull(node);41 }42 public void addRoutes(Routes routes) {43 routes.add(Route.post("/session").to(req -> {44 SessionRequest request = new SessionRequest(req);45 node.getEventBus().addListener(NewSession

Full Screen

Full Screen

listener

Using AI Code Generation

copy

Full Screen

1public void onEvent(NewSessionRequestEvent event) {2 System.out.println(event.getSessionRequest());3}4public void onEvent(SessionRequestEvent event) {5 System.out.println(event.getSessionRequest());6}7public void onEvent(SessionRequestQueuedEvent event) {8 System.out.println(event.getSessionRequest());9}10public void onEvent(SessionRequestAssignedEvent event) {11 System.out.println(event.getSessionRequest());12}13public void onEvent(SessionRequestStartedEvent event) {14 System.out.println(event.getSessionRequest());15}16public void onEvent(SessionRequestCompleteEvent event) {17 System.out.println(event.getSessionRequest());18}19public void onEvent(SessionRequestFailedEvent event) {20 System.out.println(event.getSessionRequest());21}22public void onEvent(SessionRequestTimedOutEvent event) {23 System.out.println(event.getSessionRequest());24}25public void onEvent(SessionRequestCancelledEvent event) {26 System.out.println(event.getSessionRequest());27}28public void onEvent(SessionQueuedEvent event) {29 System.out.println(event.getSession());30}31public void onEvent(SessionCreatedEvent

Full Screen

Full Screen

listener

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.grid.config.Config;2import org.openqa.selenium.grid.config.ConfigException;3import org.openqa.selenium.grid.config.MemoizedConfig;4import org.openqa.selenium.grid.data.NewSessionRequestEvent;5import org.openqa.selenium.grid.data.SessionRequest;6import org.openqa.selenium.grid.node.local.LocalNode;7import org.openqa.selenium.grid.server.EventBusConfig;8import org.openqa.selenium.grid.server.EventBusOptions;9import org.openqa.selenium.grid.server.Server;10import org.openqa.selenium.grid.server.ServerOptions;11import org.openqa.selenium.grid.web.Routable;12import org.openqa.selenium.grid.web.Routes;13import org.openqa.selenium.remote.http.Contents;14import org.openqa.selenium.remote.http.HttpRequest;15import org.openqa.selenium.remote.http.HttpResponse;16import org.openqa.selenium.remote.http.Route;17import java.io.IOException;18import java.util.Map;19import java.util.Objects;20import java.util.Optional;21import java.util.concurrent.ConcurrentHashMap;22import java.util.concurrent.TimeUnit;23import static org.openqa.selenium.grid.config.StandardGridRoles.NODE_ROLE;24public class NewSessionRequestEventExample {25 public static void main(String[] args) throws IOException, ConfigException {26 Config config = new MemoizedConfig();27 Server<?> server = new Server<>(new ServerOptions(config));28 LocalNode node = LocalNode.builder(29 new EventBusOptions(config),30 new NodeOptions(config))31 .build();32 node.start();33 server.addHandler(new NewSessionRequestHandler(node));34 server.start();35 server.join();36 }37 private static class NewSessionRequestHandler implements Routable {38 private final LocalNode node;39 public NewSessionRequestHandler(LocalNode node) {40 this.node = Objects.requireNonNull(node);41 }42 public void addRoutes(Routes routes) {43 routes.add(Route.post("/session").to(req -> {44 SessionRequest request = new SessionRequest(req);45 node.getEventBus().addListener(NewSession

Full Screen

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 method in NewSessionRequestEvent

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful