Best Selenium code snippet using org.openqa.selenium.grid.sessionmap.local.LocalSessionMap.add
Source:DistributorTest.java
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.distributor;18import static org.assertj.core.api.Assertions.assertThat;19import static org.assertj.core.api.Assertions.assertThatExceptionOfType;20import org.junit.Before;21import org.junit.Test;22import org.openqa.selenium.ImmutableCapabilities;23import org.openqa.selenium.MutableCapabilities;24import org.openqa.selenium.SessionNotCreatedException;25import org.openqa.selenium.grid.data.Session;26import org.openqa.selenium.grid.distributor.local.LocalDistributor;27import org.openqa.selenium.grid.distributor.remote.RemoteDistributor;28import org.openqa.selenium.grid.node.local.LocalNode;29import org.openqa.selenium.grid.sessionmap.local.LocalSessionMap;30import org.openqa.selenium.grid.web.PassthroughHttpClient;31import org.openqa.selenium.remote.NewSessionPayload;32import org.openqa.selenium.remote.SessionId;33import org.openqa.selenium.remote.tracing.DistributedTracer;34import java.net.URI;35import java.net.URISyntaxException;36import java.util.UUID;37public class DistributorTest {38 private DistributedTracer tracer;39 private Distributor local;40 private Distributor distributor;41 private ImmutableCapabilities caps;42 @Before43 public void setUp() {44 tracer = DistributedTracer.builder().build();45 local = new LocalDistributor(tracer);46 distributor = new RemoteDistributor(tracer, new PassthroughHttpClient<>(local));47 caps = new ImmutableCapabilities("browserName", "cheese");48 }49 @Test50 public void creatingANewSessionWithoutANodeEndsInFailure() {51 try (NewSessionPayload payload = NewSessionPayload.create(caps)) {52 assertThatExceptionOfType(SessionNotCreatedException.class)53 .isThrownBy(() -> distributor.newSession(payload));54 }55 }56 @Test57 public void shouldBeAbleToAddANodeAndCreateASession() throws URISyntaxException {58 URI nodeUri = new URI("http://example:5678");59 URI routableUri = new URI("http://localhost:1234");60 LocalSessionMap sessions = new LocalSessionMap();61 LocalNode node = LocalNode.builder(tracer, routableUri, sessions)62 .add(caps, c -> new Session(new SessionId(UUID.randomUUID()), nodeUri, c))63 .build();64 Distributor distributor = new LocalDistributor(tracer);65 distributor.add(node);66 MutableCapabilities sessionCaps = new MutableCapabilities(caps);67 sessionCaps.setCapability("sausages", "gravy");68 try (NewSessionPayload payload = NewSessionPayload.create(sessionCaps)) {69 Session session = distributor.newSession(payload);70 assertThat(session.getCapabilities()).isEqualTo(sessionCaps);71 assertThat(session.getUri()).isEqualTo(routableUri);72 }73 }74 @Test75 public void shouldBeAbleToRemoveANode() throws URISyntaxException {76 URI nodeUri = new URI("http://example:5678");77 URI routableUri = new URI("http://localhost:1234");78 LocalSessionMap sessions = new LocalSessionMap();79 LocalNode node = LocalNode.builder(tracer, routableUri, sessions)80 .add(caps, c -> new Session(new SessionId(UUID.randomUUID()), nodeUri, c))81 .build();82 Distributor local = new LocalDistributor(tracer);83 distributor = new RemoteDistributor(tracer, new PassthroughHttpClient<>(local));84 distributor.add(node);85 distributor.remove(node.getId());86 try (NewSessionPayload payload = NewSessionPayload.create(caps)) {87 assertThatExceptionOfType(SessionNotCreatedException.class)88 .isThrownBy(() -> distributor.newSession(payload));89 }90 }91 @Test92 public void registeringTheSameNodeMultipleTimesOnlyCountsTheFirstTime()93 throws URISyntaxException {94 URI nodeUri = new URI("http://example:5678");95 URI routableUri = new URI("http://localhost:1234");96 LocalSessionMap sessions = new LocalSessionMap();97 LocalNode node = LocalNode.builder(tracer, routableUri, sessions)98 .add(caps, c -> new Session(new SessionId(UUID.randomUUID()), nodeUri, c))99 .build();100 local.add(node);101 local.add(node);102 DistributorStatus status = local.getStatus();103 assertThat(status.getNodes().size()).isEqualTo(1);104 }105 @Test106 public void theMostLightlyLoadedNodeIsSelectedFirst() {107 }108}...
Source:LocalSessionMap.java
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.sessionmap.local;18import static org.openqa.selenium.grid.data.SessionClosedEvent.SESSION_CLOSED;19import org.openqa.selenium.NoSuchSessionException;20import org.openqa.selenium.events.EventBus;21import org.openqa.selenium.grid.data.Session;22import org.openqa.selenium.grid.sessionmap.SessionMap;23import org.openqa.selenium.remote.SessionId;24import org.openqa.selenium.remote.tracing.DistributedTracer;25import org.openqa.selenium.remote.tracing.Span;26import java.util.HashMap;27import java.util.Map;28import java.util.Objects;29import java.util.concurrent.locks.Lock;30import java.util.concurrent.locks.ReadWriteLock;31import java.util.concurrent.locks.ReentrantReadWriteLock;32public class LocalSessionMap extends SessionMap {33 private final DistributedTracer tracer;34 private final EventBus bus;35 private final Map<SessionId, Session> knownSessions = new HashMap<>();36 private final ReadWriteLock lock = new ReentrantReadWriteLock(/* be fair */ true);37 public LocalSessionMap(DistributedTracer tracer, EventBus bus) {38 this.tracer = Objects.requireNonNull(tracer);39 this.bus = Objects.requireNonNull(bus);40 bus.addListener(SESSION_CLOSED, event -> {41 SessionId id = event.getData(SessionId.class);42 knownSessions.remove(id);43 });44 }45 @Override46 public boolean add(Session session) {47 Objects.requireNonNull(session, "Session has not been set");48 try (Span span = tracer.createSpan("sessionmap.add", tracer.getActiveSpan())) {49 span.addTag("session.id", session.getId());50 span.addTag("session.capabilities", session.getCapabilities());51 span.addTag("session.uri", session.getUri());52 Lock writeLock = lock.writeLock();53 writeLock.lock();54 try {55 knownSessions.put(session.getId(), session);56 } finally {57 writeLock.unlock();58 }59 return true;60 }61 }62 @Override63 public Session get(SessionId id) {64 Objects.requireNonNull(id, "Session ID has not been set");65 try (Span span = tracer.createSpan("sessionmap.get", tracer.getActiveSpan())) {66 span.addTag("session.id", id);67 Lock readLock = lock.readLock();68 readLock.lock();69 try {70 Session session = knownSessions.get(id);71 if (session == null) {72 throw new NoSuchSessionException("Unable to find session with ID: " + id);73 }74 span.addTag("session.capabilities", session.getCapabilities());75 span.addTag("session.uri", session.getUri());76 return session;77 } finally {78 readLock.unlock();79 }80 }81 }82 @Override83 public void remove(SessionId id) {84 Objects.requireNonNull(id, "Session ID has not been set");85 try (Span span = tracer.createSpan("sessionmap.remove", tracer.getActiveSpan())) {86 span.addTag("session.id", id);87 Lock writeLock = lock.writeLock();88 writeLock.lock();89 try {90 knownSessions.remove(id);91 } finally {92 writeLock.unlock();93 }94 }95 }96}...
Source:Hub.java
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.commands;18import com.google.auto.service.AutoService;19import com.beust.jcommander.JCommander;20import com.beust.jcommander.ParameterException;21import org.openqa.selenium.cli.CliCommand;22import org.openqa.selenium.grid.config.AnnotatedConfig;23import org.openqa.selenium.grid.config.CompoundConfig;24import org.openqa.selenium.grid.config.ConcatenatingConfig;25import org.openqa.selenium.grid.config.Config;26import org.openqa.selenium.grid.config.EnvConfig;27import org.openqa.selenium.grid.distributor.Distributor;28import org.openqa.selenium.grid.distributor.local.LocalDistributor;29import org.openqa.selenium.grid.node.local.NodeFlags;30import org.openqa.selenium.grid.router.Router;31import org.openqa.selenium.grid.server.BaseServer;32import org.openqa.selenium.grid.server.BaseServerFlags;33import org.openqa.selenium.grid.server.BaseServerOptions;34import org.openqa.selenium.grid.server.HelpFlags;35import org.openqa.selenium.grid.server.Server;36import org.openqa.selenium.grid.server.W3CCommandHandler;37import org.openqa.selenium.grid.sessionmap.SessionMap;38import org.openqa.selenium.grid.sessionmap.local.LocalSessionMap;39import org.openqa.selenium.grid.web.Routes;40import org.openqa.selenium.remote.tracing.DistributedTracer;41@AutoService(CliCommand.class)42public class Hub implements CliCommand {43 @Override44 public String getName() {45 return "hub";46 }47 @Override48 public String getDescription() {49 return "A grid hub, composed of sessions, distributor, and router.";50 }51 @Override52 public Executable configure(String... args) {53 HelpFlags help = new HelpFlags();54 BaseServerFlags baseFlags = new BaseServerFlags(4444);55 NodeFlags nodeFlags = new NodeFlags();56 JCommander commander = JCommander.newBuilder()57 .programName("standalone")58 .addObject(baseFlags)59 .addObject(help)60 .addObject(nodeFlags)61 .build();62 return () -> {63 try {64 commander.parse(args);65 } catch (ParameterException e) {66 System.err.println(e.getMessage());67 commander.usage();68 return;69 }70 if (help.displayHelp(commander, System.out)) {71 return;72 }73 Config config = new CompoundConfig(74 new AnnotatedConfig(help),75 new AnnotatedConfig(baseFlags),76 new EnvConfig(),77 new ConcatenatingConfig("selenium", '.', System.getProperties()));78 DistributedTracer tracer = DistributedTracer.getInstance();79 SessionMap sessions = new LocalSessionMap();80 Distributor distributor = new LocalDistributor(tracer);81 Router router = new Router(sessions, distributor);82 Server<?> server = new BaseServer<>(83 tracer,84 new BaseServerOptions(config));85 server.addRoute(Routes.matching(router).using(router).decorateWith(W3CCommandHandler.class));86 server.start();87 };88 }89}...
Source:SessionMapTest.java
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.sessionmap;18import static org.assertj.core.api.Assertions.catchThrowableOfType;19import static org.junit.Assert.assertEquals;20import static org.junit.Assert.assertTrue;21import org.junit.Before;22import org.junit.Test;23import org.openqa.selenium.ImmutableCapabilities;24import org.openqa.selenium.NoSuchSessionException;25import org.openqa.selenium.grid.data.Session;26import org.openqa.selenium.grid.sessionmap.local.LocalSessionMap;27import org.openqa.selenium.grid.sessionmap.remote.RemoteSessionMap;28import org.openqa.selenium.grid.web.PassthroughHttpClient;29import org.openqa.selenium.remote.SessionId;30import org.openqa.selenium.remote.http.HttpClient;31import java.net.URI;32import java.net.URISyntaxException;33import java.util.UUID;34/**35 * We test the session map by ensuring that the HTTP protocol is properly adhered to. If this is36 * true, then any implementations are interoperable, and we can breathe a sigh of relief.37 */38public class SessionMapTest {39 private SessionId id;40 private Session expected;41 private SessionMap local;42 private HttpClient client;43 private SessionMap remote;44 @Before45 public void setUp() throws URISyntaxException {46 id = new SessionId(UUID.randomUUID());47 expected = new Session(48 id,49 new URI("http://localhost:1234"),50 new ImmutableCapabilities());51 local = new LocalSessionMap();52 client = new PassthroughHttpClient<>(local);53 remote = new RemoteSessionMap(client);54 }55 @Test56 public void shouldBeAbleToAddASession() {57 assertTrue(remote.add(expected));58 assertEquals(expected, local.get(id));59 }60 @Test61 public void shouldBeAbleToRetrieveASessionUri() {62 local.add(expected);63 assertEquals(expected, remote.get(id));64 }65 @Test66 public void shouldThrowANoSuchSessionExceptionIfSessionCannotBeFound() {67 catchThrowableOfType(() -> local.get(id), NoSuchSessionException.class);68 catchThrowableOfType(() -> remote.get(id), NoSuchSessionException.class);69 }70 @Test71 public void shouldAllowSessionsToBeRemoved() {72 local.add(expected);73 assertEquals(expected, remote.get(id));74 remote.remove(id);75 catchThrowableOfType(() -> local.get(id), NoSuchSessionException.class);76 catchThrowableOfType(() -> remote.get(id), NoSuchSessionException.class);77 }78 /**79 * This is because multiple areas within the grid may all try and remove a session.80 */81 @Test82 public void removingASessionThatDoesNotExistIsNotAnError() {83 remote.remove(id);84 }85 @Test(expected = NoSuchSessionException.class)86 public void shouldThrowAnExceptionIfGettingASessionThatDoesNotExist() {...
Source:SessionMapServer.java
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.sessionmap.httpd;18import static org.openqa.selenium.grid.web.Routes.matching;19import com.google.auto.service.AutoService;20import com.beust.jcommander.JCommander;21import com.beust.jcommander.ParameterException;22import org.openqa.selenium.cli.CliCommand;23import org.openqa.selenium.grid.config.AnnotatedConfig;24import org.openqa.selenium.grid.config.CompoundConfig;25import org.openqa.selenium.grid.config.ConcatenatingConfig;26import org.openqa.selenium.grid.config.Config;27import org.openqa.selenium.grid.config.EnvConfig;28import org.openqa.selenium.grid.server.BaseServer;29import org.openqa.selenium.grid.server.BaseServerFlags;30import org.openqa.selenium.grid.server.BaseServerOptions;31import org.openqa.selenium.grid.server.HelpFlags;32import org.openqa.selenium.grid.server.Server;33import org.openqa.selenium.grid.server.W3CCommandHandler;34import org.openqa.selenium.grid.sessionmap.SessionMap;35import org.openqa.selenium.grid.sessionmap.local.LocalSessionMap;36import org.openqa.selenium.remote.tracing.DistributedTracer;37@AutoService(CliCommand.class)38public class SessionMapServer implements CliCommand {39 @Override40 public String getName() {41 return "sessions";42 }43 @Override44 public String getDescription() {45 return "Adds this server as the session map in a selenium grid.";46 }47 @Override48 public Executable configure(String... args) {49 HelpFlags help = new HelpFlags();50 BaseServerFlags serverFlags = new BaseServerFlags(5556);51 JCommander commander = JCommander.newBuilder()52 .programName(getName())53 .addObject(help)54 .addObject(serverFlags)55 .build();56 return () -> {57 try {58 commander.parse(args);59 } catch (ParameterException e) {60 System.err.println(e.getMessage());61 commander.usage();62 return;63 }64 if (help.displayHelp(commander, System.out)) {65 return;66 }67 Config config = new CompoundConfig(68 new AnnotatedConfig(help),69 new AnnotatedConfig(serverFlags),70 new EnvConfig(),71 new ConcatenatingConfig("sessions", '.', System.getProperties()));72 SessionMap sessions = new LocalSessionMap();73 BaseServerOptions serverOptions = new BaseServerOptions(config);74 Server<?> server = new BaseServer<>(DistributedTracer.getInstance(), serverOptions);75 server.addRoute(matching(sessions).using(sessions).decorateWith(W3CCommandHandler.class));76 server.start();77 };78 }79}...
add
Using AI Code Generation
1package org.openqa.selenium.grid.sessionmap.local;2import org.openqa.selenium.grid.config.MapConfig;3import org.openqa.selenium.grid.config.MemoizedConfig;4import org.openqa.selenium.grid.config.TomlConfig;5import org.openqa.selenium.grid.data.Session;6import org.openqa.selenium.grid.data.SessionId;7import org.openqa.selenium.grid.sessionmap.SessionMap;8import org.openqa.selenium.internal.Require;9import org.openqa.selenium.json.Json;10import org.openqa.selenium.remote.http.HttpClient;11import java.util.Objects;12import java.util.Optional;13import java.util.logging.Logger;14public class LocalSessionMap implements SessionMap {15 private static final Logger LOG = Logger.getLogger(LocalSessionMap.class.getName());16 private final LocalSessionMapOptions options;17 public LocalSessionMap(LocalSessionMapOptions options) {18 this.options = Require.nonNull("Options", options);19 }20 public static SessionMap create(MapConfig config) {21 return new LocalSessionMap(new LocalSessionMapOptions(new TomlConfig("sessionmap", config)));22 }23 public Optional<Session> get(SessionId id) {24 return Optional.empty();25 }26 public void add(Session session) {27 System.out.println("Added session: " + session);28 }29 public void remove(SessionId id) {30 System.out.println("Removed session: " + id);31 }32 public void close() {33 }34}
add
Using AI Code Generation
1import org.openqa.selenium.grid.config.MapConfig;2import org.openqa.selenium.grid.config.Config;3import org.openqa.selenium.grid.sessionmap.local.LocalSessionMap;4import org.openqa.selenium.grid.sessionmap.SessionMap;5import org.openqa.selenium.grid.sessionmap.SessionMapOptions;6import org.openqa.selenium.grid.sessionmap.config.SessionMapOptions;7import org.openqa.selenium.grid.sessionmap.SessionId;8import org.openqa.selenium.remote.SessionId;9import org.openqa.selenium.remote.tracing.Tracer;10import org.openqa.selenium.remote.tracing.NoopTracer;11import org.openqa.selenium.remote.tracing.GlobalDistributedTracer;12import org.openqa.selenium.remote.tracing.DistributedTracer;13import java.net.URI;14import java.net.URISyntaxException;15import java.util.HashMap;16import java.util.Map;17import java.util.Optional;18public class LocalSessionMapAdd {19 public static void main(String[] args) {20 DistributedTracer tracer = GlobalDistributedTracer.get();21 SessionMap sessionMap = new LocalSessionMap(tracer);22 SessionId sessionId = new SessionId("session-id");23 Map<String, Object> capabilities = new HashMap<>();24 capabilities.put("browserName", "chrome");25 sessionMap.add(sessionId, sessionUri, capabilities);26 }27}28import org.openqa.selenium.grid.config.MapConfig;29import org.openqa.selenium.grid.config.Config;30import org.openqa.selenium.grid.sessionmap.local.LocalSessionMap;31import org.openqa.selenium.grid.sessionmap.SessionMap;32import org.openqa.selenium.grid.sessionmap.SessionMapOptions;33import org.openqa.selenium.grid.sessionmap.config.SessionMapOptions;34import org.openqa.selenium.grid.sessionmap.SessionId;35import org.openqa.selenium.remote.SessionId;36import org.openqa.selenium.remote.tracing.Tracer;37import org.openqa.selenium.remote.tracing.NoopTracer;38import org.openqa.selenium.remote.tracing.GlobalDistributedTracer;39import org.openqa.selenium.remote.tracing.DistributedTracer;40import java.net.URI;41import java.net.URISyntaxException;42import java.util.HashMap;43import
add
Using AI Code Generation
1import org.openqa.selenium.grid.sessionmap.local.LocalSessionMap;2import java.util.UUID;3import org.openqa.selenium.remote.SessionId;4LocalSessionMap map = new LocalSessionMap();5map.add(new SessionId(UUID.randomUUID().toString()), "value");6import org.openqa.selenium.grid.sessionmap.remote.RemoteSessionMap;7import java.net.URI;8import java.net.URISyntaxException;9import java.util.UUID;10import org.openqa.selenium.remote.SessionId;11map.add(new SessionId(UUID.randomUUID().toString()), "value");12import org.openqa.selenium.grid.sessionmap.local.LocalSessionMap;13import java.util.UUID;14import org.openqa.selenium.remote.SessionId;15LocalSessionMap map = new LocalSessionMap();16map.add(new SessionId(UUID.randomUUID().toString()), "value");17map.get(new SessionId(UUID.randomUUID().toString()));18import org.openqa.selenium.grid.sessionmap.remote.RemoteSessionMap;19import java.net.URI;20import java.net.URISyntaxException;21import java.util.UUID;22import org.openqa.selenium.remote.SessionId;23map.add(new SessionId(UUID.randomUUID().toString()), "value");24map.get(new SessionId(UUID.randomUUID().toString()));25import org.openqa.selenium.grid.sessionmap.local.LocalSessionMap;26import java.util.UUID;27import org.openqa.selenium.remote.SessionId;28LocalSessionMap map = new LocalSessionMap();29map.add(new SessionId(UUID.randomUUID().toString()), "value");30map.remove(new SessionId(UUID.randomUUID().toString()));31import org.openqa.selenium.grid.sessionmap.remote.RemoteSessionMap;32import java.net.URI;33import java.net.URISyntaxException;34import java.util.UUID;35import org.openqa.selenium.remote.SessionId;36map.add(new SessionId(UUID.randomUUID().toString()), "value");37map.remove(new SessionId(UUID.randomUUID().toString()));
add
Using AI Code Generation
1public class LocalSessionMap {2 private final Map<SessionId, Session> sessions = new ConcurrentHashMap<>();3 public Session add(Session session) {4 return sessions.put(session.getId(), session);5 }6}7public class LocalSessionMap {8 private final Map<SessionId, Session> sessions = new ConcurrentHashMap<>();9 public Session remove(SessionId id) {10 return sessions.remove(id);11 }12}13public class LocalSessionMap {14 private final Map<SessionId, Session> sessions = new ConcurrentHashMap<>();15 public Optional<Session> get(SessionId id) {16 return Optional.ofNullable(sessions.get(id));17 }18}19public class LocalSessionMap {20 private final Map<SessionId, Session> sessions = new ConcurrentHashMap<>();21 public Collection<Session> getAll() {22 return Collections.unmodifiableCollection(sessions.values());23 }24}25public class LocalSessionMap {26 private final Map<SessionId, Session> sessions = new ConcurrentHashMap<>();27 public int size() {28 return sessions.size();29 }30}31public class LocalSessionMap {32 private final Map<SessionId, Session> sessions = new ConcurrentHashMap<>();33 public void clear() {34 sessions.clear();35 }36}37public class LocalSessionMap {38 private final Map<SessionId, Session> sessions = new ConcurrentHashMap<>();39 public void addListener(SessionListener listener) {40 }41}42public class LocalSessionMap {43 private final Map<SessionId, Session> sessions = new ConcurrentHashMap<>();44 public void removeListener(SessionListener listener) {45 }46}47public class LocalSessionMap {48 private final Map<SessionId, Session> sessions = new ConcurrentHashMap<>();
add
Using AI Code Generation
1LocalSessionMap localSessionMap = new LocalSessionMap();2Session session = new Session(3 new SessionId(UUID.randomUUID()), 4 new TestSlot(5 new TestSlotId(UUID.randomUUID()),6 new DefaultCapabilities(7 new ImmutableCapabilities(8 ImmutableMap.of(9 new TestSession(10 new SessionId(UUID.randomUUID()), 11 new TestSlot(12 new TestSlotId(UUID.randomUUID()),13 new DefaultCapabilities(14 new ImmutableCapabilities(15 ImmutableMap.of(16 new ExternalSession(17 new SessionId(UUID.randomUUID()), 18 new TestSlot(19 new TestSlotId(UUID.randomUUID()),20 new DefaultCapabilities(21 new ImmutableCapabilities(22 ImmutableMap.of(23);24localSessionMap.add(session);25localSessionMap.remove(session.getId());26RemoteSessionMap remoteSessionMap = new RemoteSessionMap(27 new HttpClient.Factory()28);29remoteSessionMap.add(session);30remoteSessionMap.remove(session.getId());31ConfigBackedSessionMap configBackedSessionMap = new ConfigBackedSessionMap(32 new ImmutableMap.Builder<String, Class<? extends SessionMap>>()33 .put("local", LocalSessionMap.class)34 .put("remote", RemoteSessionMap.class)35 .build(),36 new ImmutableMap.Builder<String, Class<? extends SessionMap.Factory>>()37 .put("local", LocalSessionMap.Factory.class)38 .put("remote", RemoteSessionMap.Factory.class)39 .build(),40 Config.create()41);42configBackedSessionMap.add(session
add
Using AI Code Generation
1import java.time.Duration;2import java.time.Instant;3import java.util.Map;4import java.util.Optional;5import java.util.UUID;6import org.openqa.selenium.Capabilities;7import org.openqa.selenium.ImmutableCapabilities;8import org.openqa.selenium.grid.data.Session;9import org.openqa.selenium.grid.sessionmap.local.LocalSessionMap;10import org.openqa.selenium.internal.Require;11import org.openqa.selenium.remote.SessionId;12import org.openqa.selenium.remote.tracing.DefaultTestTracer;13import org.openqa.selenium.remote.tracing.Tracer;14public class LocalSessionMapTest {15 public static void main(String[] args) {16 Tracer tracer = DefaultTestTracer.createTracer();17 LocalSessionMap sessions = new LocalSessionMap(tracer);18 Capabilities capabilities = new ImmutableCapabilities("browserName", "chrome");19 SessionId id = new SessionId(UUID.randomUUID());20 Session session = new Session(id, capabilities, Instant.now(), Duration.ofMinutes(1));21 sessions.add(session);22 Optional<Session> gotSession = sessions.get(id);23 Require.state(gotSession.isPresent());24 Require.equals(session, gotSession.get());25 sessions.remove(id);26 gotSession = sessions.get(id);27 Require.state(!gotSession.isPresent());28 sessions.remove(id);29 gotSession = sessions.get(id);30 Require.state(!gotSession.isPresent());31 }32}33package org.openqa.selenium.grid.sessionmap.local;34import org.openqa.selenium.Capabilities;35import org.openqa.selenium.ImmutableCapabilities;36import org.openqa.selenium.grid.data.Session;37import org.openqa.selenium.internal.Require;38import org.openqa.selenium.remote.SessionId;39import org.openqa.selenium.remote.tracing.DefaultTestTracer;40import org.openqa.selenium.remote.tracing.Tracer;41import org.testng.annotations.Test;42import java.time.Duration;43import java.time.Instant;44import java.util.Optional;45import java.util.UUID;46import static org.openqa.selenium.remote.CapabilityType
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!!