How to use matches method of org.openqa.selenium.grid.data.DefaultSlotMatcher class

Best Selenium code snippet using org.openqa.selenium.grid.data.DefaultSlotMatcher.matches

Source:DistributorTest.java Github

copy

Full Screen

...873 Either<SessionNotCreatedException, CreateSessionResponse> chromeResult =874 distributor.newSession(createRequest(chrome));875 assertThatEither(chromeResult).isRight();876 Session chromeSession = chromeResult.right().getSession();877 //Ensure the Uri of the Session matches one of the Chrome Nodes, not the Edge Node878 assertThat(879 chromeSession.getUri()).isIn(880 chromeNodes881 .stream().map(Node::getStatus).collect(Collectors.toList()) //List of getStatus() from the Set882 .stream().map(NodeStatus::getUri).collect(Collectors.toList()) //List of getUri() from the Set883 );884 Either<SessionNotCreatedException, CreateSessionResponse> firefoxResult =885 distributor.newSession(createRequest(firefox));886 assertThatEither(firefoxResult).isRight();887 Session firefoxSession = firefoxResult.right().getSession();888 LOG.info(String.format("Firefox Session %d assigned to %s", i, chromeSession.getUri()));889 boolean inFirefoxNodes = firefoxNodes.stream().anyMatch(node -> node.getUri().equals(firefoxSession.getUri()));890 boolean inChromeNodes = chromeNodes.stream().anyMatch(node -> node.getUri().equals(chromeSession.getUri()));891 //This could be either, or, or both...

Full Screen

Full Screen

Source:LocalNewSessionQueueTest.java Github

copy

Full Screen

1// Licensed to the Software Freedom Conservancy (SFC) under one2// or more contributor license agreements. See the NOTICE file3// distributed with this work for additional information4// regarding copyright ownership. The SFC licenses this file5// to you under the Apache License, Version 2.0 (the6// "License"); you may not use this file except in compliance7// with the License. You may obtain a copy of the License at8//9// http://www.apache.org/licenses/LICENSE-2.010//11// Unless required by applicable law or agreed to in writing,12// software distributed under the License is distributed on an13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY14// KIND, either express or implied. See the License for the15// specific language governing permissions and limitations16// under the License.17package org.openqa.selenium.grid.sessionqueue.local;18import com.google.common.collect.ImmutableMap;19import org.junit.After;20import org.junit.ClassRule;21import org.junit.Test;22import org.junit.rules.Timeout;23import org.junit.runner.RunWith;24import org.junit.runners.Parameterized;25import org.openqa.selenium.Capabilities;26import org.openqa.selenium.ImmutableCapabilities;27import org.openqa.selenium.SessionNotCreatedException;28import org.openqa.selenium.events.EventBus;29import org.openqa.selenium.events.local.GuavaEventBus;30import org.openqa.selenium.grid.data.CreateSessionResponse;31import org.openqa.selenium.grid.data.DefaultSlotMatcher;32import org.openqa.selenium.grid.data.NewSessionRejectedEvent;33import org.openqa.selenium.grid.data.NewSessionRequestEvent;34import org.openqa.selenium.grid.data.RequestId;35import org.openqa.selenium.grid.data.Session;36import org.openqa.selenium.grid.data.SessionRequestCapability;37import org.openqa.selenium.grid.security.Secret;38import org.openqa.selenium.grid.sessionqueue.NewSessionQueue;39import org.openqa.selenium.grid.data.SessionRequest;40import org.openqa.selenium.grid.sessionqueue.remote.RemoteNewSessionQueue;41import org.openqa.selenium.grid.testing.PassthroughHttpClient;42import org.openqa.selenium.internal.Debug;43import org.openqa.selenium.internal.Either;44import org.openqa.selenium.json.Json;45import org.openqa.selenium.remote.SessionId;46import org.openqa.selenium.remote.http.Contents;47import org.openqa.selenium.remote.http.HttpClient;48import org.openqa.selenium.remote.http.HttpResponse;49import org.openqa.selenium.remote.tracing.DefaultTestTracer;50import org.openqa.selenium.remote.tracing.Tracer;51import java.net.URI;52import java.net.URISyntaxException;53import java.time.Duration;54import java.time.Instant;55import java.util.Collection;56import java.util.LinkedHashSet;57import java.util.List;58import java.util.Map;59import java.util.Optional;60import java.util.Set;61import java.util.UUID;62import java.util.concurrent.Callable;63import java.util.concurrent.CountDownLatch;64import java.util.concurrent.ExecutionException;65import java.util.concurrent.ExecutorService;66import java.util.concurrent.Executors;67import java.util.concurrent.Future;68import java.util.concurrent.TimeoutException;69import java.util.concurrent.atomic.AtomicBoolean;70import java.util.concurrent.atomic.AtomicInteger;71import java.util.concurrent.atomic.AtomicReference;72import java.util.function.Supplier;73import java.util.stream.Collectors;74import static java.net.HttpURLConnection.HTTP_INTERNAL_ERROR;75import static java.net.HttpURLConnection.HTTP_OK;76import static java.nio.charset.StandardCharsets.UTF_8;77import static java.util.concurrent.TimeUnit.SECONDS;78import static org.assertj.core.api.Assertions.assertThat;79import static org.assertj.core.api.Assertions.fail;80import static org.junit.Assert.assertEquals;81import static org.junit.Assert.assertFalse;82import static org.junit.Assert.assertNotEquals;83import static org.junit.Assert.assertTrue;84import static org.openqa.selenium.remote.Dialect.W3C;85import static org.openqa.selenium.testing.Safely.safelyCall;86@RunWith(Parameterized.class)87public class LocalNewSessionQueueTest {88 @ClassRule89 public static Timeout classTimeout = new Timeout(60, SECONDS);90 private static final Json JSON = new Json();91 private static final Capabilities CAPS = new ImmutableCapabilities("browserName", "cheese");92 private static final Secret REGISTRATION_SECRET = new Secret("secret");93 private static final Instant LONG_AGO = Instant.parse("2007-01-03T21:49:10.00Z"); // Go check the git log94 private final NewSessionQueue queue;95 private final LocalNewSessionQueue localQueue;96 private final EventBus bus;97 private final SessionRequest sessionRequest;98 static class TestData {99 public final EventBus bus;100 public final LocalNewSessionQueue localQueue;101 public final NewSessionQueue queue;102 public TestData(EventBus bus, LocalNewSessionQueue localQueue, NewSessionQueue queue) {103 this.bus = bus;104 this.localQueue = localQueue;105 this.queue = queue;106 }107 }108 public LocalNewSessionQueueTest(Supplier<TestData> supplier) {109 TestData testData = supplier.get();110 this.bus = testData.bus;111 this.queue = testData.queue;112 this.localQueue = testData.localQueue;113 this.sessionRequest = new SessionRequest(114 new RequestId(UUID.randomUUID()),115 Instant.now(),116 Set.of(W3C),117 Set.of(CAPS),118 Map.of(),119 Map.of());120 }121 @Parameterized.Parameters122 public static Collection<Supplier<TestData>> createQueues() {123 Tracer tracer = DefaultTestTracer.createTracer();124 Set<Supplier<TestData>> toReturn = new LinkedHashSet<>();125 // Note: this method is called only once, so if we want each test to126 // be isolated, everything that they use has to be created via the127 // supplier. In particular, a shared event bus will cause weird128 // failures to happen.129 toReturn.add(() -> {130 EventBus bus = new GuavaEventBus();131 LocalNewSessionQueue local = new LocalNewSessionQueue(132 tracer,133 bus,134 new DefaultSlotMatcher(),135 Duration.ofSeconds(1),136 Duration.ofSeconds(Debug.isDebugging() ? 9999 : 5),137 REGISTRATION_SECRET);138 return new TestData(bus, local, local);139 });140 toReturn.add(() -> {141 EventBus bus = new GuavaEventBus();142 LocalNewSessionQueue local = new LocalNewSessionQueue(143 tracer,144 bus,145 new DefaultSlotMatcher(),146 Duration.ofSeconds(1),147 Duration.ofSeconds(Debug.isDebugging() ? 9999 : 5),148 REGISTRATION_SECRET);149 HttpClient client = new PassthroughHttpClient(local);150 return new TestData(bus, local, new RemoteNewSessionQueue(tracer, client, REGISTRATION_SECRET));151 });152 return toReturn;153 }154 @After155 public void shutdownQueue() {156 safelyCall(localQueue::close);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();389 assertThat(isPresent.get()).isEqualTo(sessionRequest.getRequestId());390 }391 @Test(timeout = 5000)392 public void shouldBeAbleToClearQueueAndRejectMultipleRequests() {393 ExecutorService executor = Executors.newFixedThreadPool(2);394 Callable<HttpResponse> callable = () -> {395 SessionRequest sessionRequest = new SessionRequest(396 new RequestId(UUID.randomUUID()),397 Instant.now(),398 Set.of(W3C),399 Set.of(CAPS),400 Map.of(),401 Map.of());402 return queue.addToQueue(sessionRequest);403 };404 Future<HttpResponse> firstRequest = executor.submit(callable);405 Future<HttpResponse> secondRequest = executor.submit(callable);406 int count = 0;407 while (count < 2) {408 count += queue.clearQueue();409 }410 try {411 HttpResponse firstResponse = firstRequest.get(30, SECONDS);412 HttpResponse secondResponse = secondRequest.get(30, SECONDS);413 assertEquals(firstResponse.getStatus(), HTTP_INTERNAL_ERROR);414 assertEquals(secondResponse.getStatus(), HTTP_INTERNAL_ERROR);415 } catch (InterruptedException | ExecutionException | TimeoutException e) {416 fail("Could not create session");417 }418 executor.shutdownNow();419 }420 @Test421 public void shouldBeAbleToReturnTheNextAvailableEntryThatMatchesAStereotype() {422 SessionRequest expected = new SessionRequest(423 new RequestId(UUID.randomUUID()),424 Instant.now(),425 Set.of(W3C),426 Set.of(new ImmutableCapabilities("browserName", "cheese", "se:kind", "smoked")),427 Map.of(),428 Map.of());429 localQueue.injectIntoQueue(expected);430 localQueue.injectIntoQueue(new SessionRequest(431 new RequestId(UUID.randomUUID()),432 Instant.now(),433 Set.of(W3C),434 Set.of(new ImmutableCapabilities("browserName", "peas", "se:kind", "mushy")),435 Map.of(),436 Map.of()));437 Optional<SessionRequest> returned = queue.getNextAvailable(438 Set.of(new ImmutableCapabilities("browserName", "cheese")));439 assertThat(returned).isEqualTo(Optional.of(expected));440 }441 @Test442 public void shouldNotReturnANextAvailableEntryThatDoesNotMatchTheStereotypes() {443 // Note that this is basically the same test as getting the entry444 // from queue, but we've cleverly reversed the entries, so the one445 // that doesn't match should be first in the queue.446 localQueue.injectIntoQueue(new SessionRequest(447 new RequestId(UUID.randomUUID()),448 Instant.now(),449 Set.of(W3C),450 Set.of(new ImmutableCapabilities("browserName", "peas", "se:kind", "mushy")),451 Map.of(),452 Map.of()));453 SessionRequest expected = new SessionRequest(454 new RequestId(UUID.randomUUID()),455 Instant.now(),456 Set.of(W3C),457 Set.of(new ImmutableCapabilities("browserName", "cheese", "se:kind", "smoked")),458 Map.of(),459 Map.of());460 localQueue.injectIntoQueue(expected);461 Optional<SessionRequest> returned = queue.getNextAvailable(462 Set.of(new ImmutableCapabilities("browserName", "cheese")));463 assertThat(returned).isEqualTo(Optional.of(expected));464 }465}...

Full Screen

Full Screen

Source:DockerSessionFactory.java Github

copy

Full Screen

...117 this.slotMatcher = new DefaultSlotMatcher();118 }119 @Override120 public boolean test(Capabilities capabilities) {121 return slotMatcher.matches(stereotype, capabilities);122 }123 @Override124 public Either<WebDriverException, ActiveSession> apply(CreateSessionRequest sessionRequest) {125 LOG.info("Starting session for " + sessionRequest.getDesiredCapabilities());126 int port = runningInDocker ? 4444 : PortProber.findFreePort();127 try (Span span = tracer.getCurrentContext().createSpan("docker_session_factory.apply")) {128 Map<String, EventAttributeValue> attributeMap = new HashMap<>();129 attributeMap.put(AttributeKey.LOGGER_CLASS.getKey(),130 EventAttribute.setValue(this.getClass().getName()));131 String logMessage = runningInDocker ? "Creating container..." :132 "Creating container, mapping container port 4444 to " + port;133 LOG.info(logMessage);134 Container container = createBrowserContainer(port, sessionRequest.getDesiredCapabilities());135 container.start();...

Full Screen

Full Screen

Source:DefaultSlotMatcherTest.java Github

copy

Full Screen

...34 CapabilityType.BROWSER_NAME, "chrome",35 CapabilityType.BROWSER_VERSION, "80",36 CapabilityType.PLATFORM_NAME, Platform.WINDOWS37 );38 assertThat(slotMatcher.matches(stereotype, capabilities)).isTrue();39 }40 @Test41 public void matchesBrowserAndVersion() {42 Capabilities stereotype = new ImmutableCapabilities(43 CapabilityType.BROWSER_NAME, "chrome",44 CapabilityType.BROWSER_VERSION, "80",45 CapabilityType.PLATFORM_NAME, Platform.WINDOWS46 );47 Capabilities capabilities = new ImmutableCapabilities(48 CapabilityType.BROWSER_NAME, "chrome",49 CapabilityType.BROWSER_VERSION, "80"50 );51 assertThat(slotMatcher.matches(stereotype, capabilities)).isTrue();52 }53 @Test54 public void matchesBrowser() {55 Capabilities stereotype = new ImmutableCapabilities(56 CapabilityType.BROWSER_NAME, "chrome",57 CapabilityType.BROWSER_VERSION, "80",58 CapabilityType.PLATFORM_NAME, Platform.WINDOWS59 );60 Capabilities capabilities = new ImmutableCapabilities(61 CapabilityType.BROWSER_NAME, "chrome"62 );63 assertThat(slotMatcher.matches(stereotype, capabilities)).isTrue();64 }65 @Test66 public void platformDoesNotMatch() {67 Capabilities stereotype = new ImmutableCapabilities(68 CapabilityType.BROWSER_NAME, "chrome",69 CapabilityType.BROWSER_VERSION, "80",70 CapabilityType.PLATFORM_NAME, Platform.WINDOWS71 );72 Capabilities capabilities = new ImmutableCapabilities(73 CapabilityType.BROWSER_NAME, "chrome",74 CapabilityType.BROWSER_VERSION, "80",75 CapabilityType.PLATFORM_NAME, Platform.MAC76 );77 assertThat(slotMatcher.matches(stereotype, capabilities)).isFalse();78 }79 @Test80 public void browserDoesNotMatch() {81 Capabilities stereotype = new ImmutableCapabilities(82 CapabilityType.BROWSER_NAME, "chrome",83 CapabilityType.BROWSER_VERSION, "80",84 CapabilityType.PLATFORM_NAME, Platform.WINDOWS85 );86 Capabilities capabilities = new ImmutableCapabilities(87 CapabilityType.BROWSER_NAME, "firefox",88 CapabilityType.BROWSER_VERSION, "80",89 CapabilityType.PLATFORM_NAME, Platform.WINDOWS90 );91 assertThat(slotMatcher.matches(stereotype, capabilities)).isFalse();92 }93 @Test94 public void browserVersionDoesNotMatch() {95 Capabilities stereotype = new ImmutableCapabilities(96 CapabilityType.BROWSER_NAME, "chrome",97 CapabilityType.BROWSER_VERSION, "80",98 CapabilityType.PLATFORM_NAME, Platform.WINDOWS99 );100 Capabilities capabilities = new ImmutableCapabilities(101 CapabilityType.BROWSER_NAME, "chrome",102 CapabilityType.BROWSER_VERSION, "84",103 CapabilityType.PLATFORM_NAME, Platform.WINDOWS104 );105 assertThat(slotMatcher.matches(stereotype, capabilities)).isFalse();106 }107 @Test108 public void requestedPlatformDoesNotMatch() {109 Capabilities stereotype = new ImmutableCapabilities(110 CapabilityType.BROWSER_NAME, "chrome",111 CapabilityType.BROWSER_VERSION, "80"112 );113 Capabilities capabilities = new ImmutableCapabilities(114 CapabilityType.BROWSER_NAME, "chrome",115 CapabilityType.BROWSER_VERSION, "80",116 CapabilityType.PLATFORM_NAME, Platform.WINDOWS117 );118 assertThat(slotMatcher.matches(stereotype, capabilities)).isFalse();119 }120 @Test121 public void shouldNotMatchIfRequestedBrowserVersionIsMissingFromStereotype() {122 Capabilities stereotype = new ImmutableCapabilities(123 CapabilityType.BROWSER_NAME, "chrome",124 CapabilityType.PLATFORM_NAME, Platform.WINDOWS125 );126 Capabilities capabilities = new ImmutableCapabilities(127 CapabilityType.BROWSER_NAME, "chrome",128 CapabilityType.BROWSER_VERSION, "84",129 CapabilityType.PLATFORM_NAME, Platform.WINDOWS130 );131 assertThat(slotMatcher.matches(stereotype, capabilities)).isFalse();132 }133 @Test134 public void matchesWithJsonWireProtocolCaps() {135 Capabilities stereotype = new ImmutableCapabilities(136 CapabilityType.BROWSER_NAME, "chrome",137 CapabilityType.BROWSER_VERSION, "80",138 CapabilityType.PLATFORM_NAME, Platform.WINDOWS139 );140 Capabilities capabilities = new ImmutableCapabilities(141 CapabilityType.BROWSER_NAME, "chrome",142 CapabilityType.VERSION, "80",143 CapabilityType.PLATFORM, Platform.WINDOWS144 );145 assertThat(slotMatcher.matches(stereotype, capabilities)).isTrue();146 }147 @Test148 public void shouldNotMatchCapabilitiesThatAreDifferentButDoNotContainCommonCapabilityNames() {149 Capabilities stereotype = new ImmutableCapabilities("acceptInsecureCerts", "true");150 Capabilities capabilities = new ImmutableCapabilities("acceptInsecureCerts", "false");151 assertThat(slotMatcher.matches(stereotype, capabilities)).isFalse();152 }153 @Test154 public void shouldMatchCapabilitiesThatAreTheSameButDoNotContainCommonCapabilityNames() {155 Capabilities stereotype = new ImmutableCapabilities("strictFileInteractability", "true");156 Capabilities capabilities = new ImmutableCapabilities("strictFileInteractability", "true");157 assertThat(slotMatcher.matches(stereotype, capabilities)).isTrue();158 }159}...

Full Screen

Full Screen

Source:LocalNodeFactory.java Github

copy

Full Screen

...81 toReturn.add(new DriverServiceSessionFactory(82 tracer,83 clientFactory,84 stereotype,85 capabilities -> slotMatcher.matches(stereotype, capabilities),86 driverServiceBuilder));87 });88 return toReturn.build();89 }90}...

Full Screen

Full Screen

Source:DefaultSlotMatcher.java Github

copy

Full Screen

...38 * to each driver.39 */40public class DefaultSlotMatcher implements SlotMatcher {41 @Override42 public boolean matches(Capabilities stereotype, Capabilities capabilities) {43 Boolean initialMatch = stereotype.getCapabilityNames().stream()44 // Matching of extension capabilities is implementation independent. Skip them45 .filter(name -> !name.contains(":"))46 // Platform matching is special, we do it below47 .filter(name -> !"platform".equalsIgnoreCase(name) && !"platformName".equalsIgnoreCase(name))48 .map(name -> {49 Object value = capabilities.getCapability(name);50 boolean matches;51 if (value instanceof String) {52 matches = stereotype.getCapability(name).toString().equalsIgnoreCase(value.toString());53 } else {54 matches = value == null || Objects.equals(stereotype.getCapability(name), value);55 }56 return matches;57 })58 .reduce(Boolean::logicalAnd)59 .orElse(false);60 if (!initialMatch) {61 return false;62 }63 // Simple browser, browserVersion and platformName match64 boolean browserNameMatch =65 capabilities.getBrowserName() == null ||66 Objects.equals(stereotype.getBrowserName(), capabilities.getBrowserName());67 boolean browserVersionMatch =68 (capabilities.getBrowserVersion() == null || capabilities.getBrowserVersion().isEmpty()) ||69 Objects.equals(stereotype.getBrowserVersion(), capabilities.getBrowserVersion());70 boolean platformNameMatch =...

Full Screen

Full Screen

Source:Slot.java Github

copy

Full Screen

...47 public Optional<Session> getSession() {48 return session;49 }50 public boolean isSupporting(Capabilities caps) {51 return slotMatcher.matches(getStereotype(), caps);52 }53 @Override54 public boolean equals(Object o) {55 if (!(o instanceof Slot)) {56 return false;57 }58 Slot that = (Slot) o;59 return Objects.equals(this.id, that.id) &&60 Objects.equals(this.stereotype, that.stereotype) &&61 Objects.equals(this.session, that.session) &&62 Objects.equals(this.lastStarted.toEpochMilli(), that.lastStarted.toEpochMilli());63 }64 @Override65 public int hashCode() {...

Full Screen

Full Screen

matches

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.grid.data.DefaultSlotMatcher;2import org.openqa.selenium.grid.data.Slot;3import org.openqa.selenium.grid.data.SlotId;4import org.openqa.selenium.grid.data.SlotMatch;5import org.openqa.selenium.grid.data.SlotMatcher;6import org.openqa.selenium.grid.node.NodeId;7import org.openqa.selenium.internal.Require;8import org.openqa.selenium.remote.CapabilityType;9import org.openqa.selenium.remote.tracing.Tracer;10import org.openqa.selenium.remote.tracing.opentelemetry.OpenTelemetryTracer;11import org.openqa.selenium.remote.tracing.opentelemetry.OpenTelemetryTracerFactory;12import org.openqa.selenium.remote.tracing.opentelemetry.OpenTelemetryTracerOptions;13import org.openqa.selenium.remote.tracing.opentelemetry.Span;14import org.openqa.selenium.remote.tracing.opentelemetry.SpanOptions;15import org.openqa.selenium.remote.tracing.opentelemetry.SpanOptionsBuilder;16import org.openqa.selenium.remote.tracing.opentelemetry.SpanOptionsBuilder.SpanKind;17import org.openqa.selenium.remote.tracing.opentelemetry.SpanOptionsBuilder.SpanStatus;18import org.openqa.selenium.remote.tracing.opentelemetry.SpanOptionsBuilder.SpanStatusBuilder;19import org.openqa.selenium.remote.tracing.opentelemetry.SpanOptionsBuilder.SpanStatusBuilder.SpanStatusCode;20import org.openqa.selenium.remote.tracing.opentelemetry.SpanOptionsBuilder.SpanStatusBuilder.SpanStatusCodeBuilder;21import org.openqa.selenium.remote.tracing.opentelemetry.SpanOptionsBuilder.SpanStatusBuilder.SpanStatusCodeBuilder.SpanStatusDescriptionBuilder;22import org.openqa.selenium.remote.tracing.opentelemetry.SpanOptionsBuilder.SpanStatusBuilder.SpanStatusCodeBuilder.SpanStatusDescriptionBuilder.SpanStatusDescription;23import org.openqa.selenium.remote.tracing.opentelemetry.SpanOptionsBuilder.SpanStatusBuilder.SpanStatusCodeBuilder.SpanStatusDescriptionBuilder.SpanStatusDescriptionBuilderWithCode;24import org.openqa.selenium.remote.tracing.opentelemetry.SpanOptionsBuilder.SpanStatusBuilder.SpanStatusCodeBuilder.SpanStatusDescriptionBuilder.SpanStatusDescriptionBuilderWithCode.SpanStatusDescriptionBuilderWithCodeAndDescription;25import org.openqa.selenium.remote.tracing.opentelemetry.SpanOptionsBuilder.SpanStatusBuilder.SpanStatusCodeBuilder.SpanStatusDescriptionBuilder.SpanStatusDescriptionBuilderWithCodeAndDescription.SpanStatusDescriptionBuilderWithCodeAndDescriptionAndDescription;26import org.openqa.selenium.remote.tracing.opentelemetry.SpanOptionsBuilder.SpanStatusBuilder.SpanStatusCodeBuilder.SpanStatusDescriptionBuilder.SpanStatusDescriptionBuilderWithCodeAndDescription.SpanStatusDescriptionBuilderWithCodeAndDescriptionAndDescription.SpanStatusDescriptionBuilderWithCodeAndDescriptionAndDescriptionAndDescription;27import org.openqa.selenium.remote.tracing.opentelemetry.SpanOptionsBuilder.SpanStatusBuilder.SpanStatusCodeBuilder.SpanStatusDescription

Full Screen

Full Screen

matches

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.grid.data.DefaultSlotMatcher;2import org.openqa.selenium.grid.data.Slot;3import org.openqa.selenium.grid.data.Slot.Builder;4import org.openqa.selenium.grid.data.SlotMatch;5import org.openqa.selenium.grid.data.SlotMatcher;6import org.openqa.selenium.internal.Require;7import org.openqa.selenium.remote.CapabilityType;8import org.openqa.selenium.remote.SessionId;9import java.net.URI;10import java.util.Map;11import java.util.Optional;12public class DefaultSlotMatcherExample {13 public static void main(String[] args) {14 SlotMatcher matcher = new DefaultSlotMatcher();15 Builder builder = new Builder(16 new SessionId("1234"));17 builder.setLastStarted(0);18 builder.setLastSession(0);19 Map<String, Object> capabilities = ImmutableMap.of(20 CapabilityType.BROWSER_NAME, "firefox");21 builder.setCapabilities(capabilities);

Full Screen

Full Screen

matches

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.grid.data.DefaultSlotMatcher;2import org.openqa.selenium.grid.data.Slot;3import org.openqa.selenium.remote.CapabilityType;4import org.openqa.selenium.remote.DesiredCapabilities;5import org.openqa.selenium.remote.server.log.LoggingOptions;6import java.util.Arrays;7import java.util.HashMap;8import java.util.Map;9public class SlotMatcherExample {10 public static void main(String[] args) {11 Map<String, Object> capabilities = new HashMap<>();12 capabilities.put(CapabilityType.BROWSER_NAME, "chrome");13 capabilities.put("goog:chromeOptions", new HashMap<>());14 capabilities.put("seleniumProtocol", "WebDriver");15 DesiredCapabilities desiredCapabilities = new DesiredCapabilities(capabilities);16 DefaultSlotMatcher matcher = new DefaultSlotMatcher(Arrays.asList(slot));17 Map<String, Object> matchCapabilities = new HashMap<>();18 matchCapabilities.put(CapabilityType.BROWSER_NAME, "chrome");19 matchCapabilities.put("goog:chromeOptions", new HashMap<>());20 matchCapabilities.put("seleniumProtocol", "WebDriver");21 DesiredCapabilities matchDesiredCapabilities = new DesiredCapabilities(matchCapabilities);22 System.out.println(matcher.matches(matchDesiredCapabilities));23 }24}

Full Screen

Full Screen

matches

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.grid.data.DefaultSlotMatcher;2public class DefaultSlotMatcherExample {3 public static void main(String[] args) {4 DefaultSlotMatcher matcher = new DefaultSlotMatcher();5 System.out.println(matcher.matches("browserName", "chrome"));6 System.out.println(matcher.matches("browserName", "firefox"));7 }8}

Full Screen

Full Screen

matches

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.grid.data.DefaultSlotMatcher;2import org.openqa.selenium.grid.data.Slot;3import org.openqa.selenium.grid.data.SlotId;4import org.openqa.selenium.remote.NewSessionPayload;5import org.openqa.selenium.remote.tracing.Tracer;6import org.openqa.selenium.remote.tracing.opentelemetry.OpenTelemetryTracer;7import java.util.ArrayList;8import java.util.List;9public class SlotMatcher {10 public static void main(String[] args) {11 Tracer tracer = new OpenTelemetryTracer();12 DefaultSlotMatcher slotMatcher = new DefaultSlotMatcher(tracer);13 List<Slot> slots = new ArrayList<>();14 slots.add(new Slot(new SlotId("slot1"), null, null, null, null, null, null, null, null, null));15 slots.add(new Slot(new SlotId("slot2"), null, null, null, null, null, null, null, null, null));16 slots.add(new Slot(new SlotId("slot3"), null, null, null, null, null, null, null, null, null));17 NewSessionPayload payload = new NewSessionPayload(null, null, null, null, null, null, null, null, null, null, null);18 Slot matchedSlot = slotMatcher.matches(slots, payload);19 SlotId matchedSlotId = matchedSlot.getId();20 System.out.println(matchedSlotId);21 }22}

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 DefaultSlotMatcher

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful