How to use CreateSessionResponse class of org.openqa.selenium.grid.data package

Best Selenium code snippet using org.openqa.selenium.grid.data.CreateSessionResponse

Source:NodeTest.java Github

copy

Full Screen

...29import org.openqa.selenium.NoSuchSessionException;30import org.openqa.selenium.SessionNotCreatedException;31import org.openqa.selenium.events.EventBus;32import org.openqa.selenium.grid.data.CreateSessionRequest;33import org.openqa.selenium.grid.data.CreateSessionResponse;34import org.openqa.selenium.grid.data.Session;35import org.openqa.selenium.grid.node.local.LocalNode;36import org.openqa.selenium.grid.node.remote.RemoteNode;37import org.openqa.selenium.events.local.GuavaEventBus;38import org.openqa.selenium.grid.testing.PassthroughHttpClient;39import org.openqa.selenium.grid.testing.TestSessionFactory;40import org.openqa.selenium.grid.web.CommandHandler;41import org.openqa.selenium.remote.Dialect;42import org.openqa.selenium.remote.SessionId;43import org.openqa.selenium.remote.http.HttpClient;44import org.openqa.selenium.remote.http.HttpRequest;45import org.openqa.selenium.remote.http.HttpResponse;46import org.openqa.selenium.remote.tracing.DistributedTracer;47import org.openqa.selenium.support.ui.FluentWait;48import org.openqa.selenium.support.ui.Wait;49import java.io.IOException;50import java.net.URI;51import java.net.URISyntaxException;52import java.time.Clock;53import java.time.Duration;54import java.time.Instant;55import java.time.ZoneId;56import java.util.Optional;57import java.util.UUID;58import java.util.concurrent.atomic.AtomicBoolean;59import java.util.concurrent.atomic.AtomicReference;60public class NodeTest {61 private DistributedTracer tracer;62 private EventBus bus;63 private HttpClient.Factory clientFactory;64 private LocalNode local;65 private Node node;66 private ImmutableCapabilities caps;67 private URI uri;68 @Before69 public void setUp() throws URISyntaxException {70 tracer = DistributedTracer.builder().build();71 bus = new GuavaEventBus();72 clientFactory = HttpClient.Factory.createDefault();73 caps = new ImmutableCapabilities("browserName", "cheese");74 uri = new URI("http://localhost:1234");75 class Handler extends Session implements CommandHandler {76 private Handler(Capabilities capabilities) {77 super(new SessionId(UUID.randomUUID()), uri, capabilities);78 }79 @Override80 public void execute(HttpRequest req, HttpResponse resp) {81 // Does nothing82 }83 }84 local = LocalNode.builder(tracer, bus, clientFactory, uri)85 .add(caps, new TestSessionFactory((id, c) -> new Handler(c)))86 .add(caps, new TestSessionFactory((id, c) -> new Handler(c)))87 .add(caps, new TestSessionFactory((id, c) -> new Handler(c)))88 .maximumConcurrentSessions(2)89 .build();90 node = new RemoteNode(91 tracer,92 new PassthroughHttpClient.Factory<>(local),93 UUID.randomUUID(),94 uri,95 ImmutableSet.of(caps));96 }97 @Test98 public void shouldRefuseToCreateASessionIfNoFactoriesAttached() {99 Node local = LocalNode.builder(tracer, bus, clientFactory, uri).build();100 HttpClient.Factory clientFactory = new PassthroughHttpClient.Factory<>(local);101 Node node = new RemoteNode(tracer, clientFactory, UUID.randomUUID(), uri, ImmutableSet.of());102 Optional<Session> session = node.newSession(createSessionRequest(caps))103 .map(CreateSessionResponse::getSession);104 assertThat(session.isPresent()).isFalse();105 }106 @Test107 public void shouldCreateASessionIfTheCorrectCapabilitiesArePassedToIt() {108 Optional<Session> session = node.newSession(createSessionRequest(caps))109 .map(CreateSessionResponse::getSession);110 assertThat(session.isPresent()).isTrue();111 }112 @Test113 public void shouldOnlyCreateAsManySessionsAsFactories() {114 Node node = LocalNode.builder(tracer, bus, clientFactory, uri)115 .add(caps, new TestSessionFactory((id, c) -> new Session(id, uri, c)))116 .build();117 Optional<Session> session = node.newSession(createSessionRequest(caps))118 .map(CreateSessionResponse::getSession);119 assertThat(session.isPresent()).isTrue();120 session = node.newSession(createSessionRequest(caps))121 .map(CreateSessionResponse::getSession);122 assertThat(session.isPresent()).isFalse();123 }124 @Test125 public void willRefuseToCreateMoreSessionsThanTheMaxSessionCount() {126 Optional<Session> session = node.newSession(createSessionRequest(caps))127 .map(CreateSessionResponse::getSession);128 assertThat(session.isPresent()).isTrue();129 session = node.newSession(createSessionRequest(caps))130 .map(CreateSessionResponse::getSession);131 assertThat(session.isPresent()).isTrue();132 session = node.newSession(createSessionRequest(caps))133 .map(CreateSessionResponse::getSession);134 assertThat(session.isPresent()).isFalse();135 }136 @Test137 public void stoppingASessionReducesTheNumberOfCurrentlyActiveSessions() {138 assertThat(local.getCurrentSessionCount()).isEqualTo(0);139 Session session = local.newSession(createSessionRequest(caps))140 .map(CreateSessionResponse::getSession)141 .orElseThrow(() -> new RuntimeException("Session not created"));142 assertThat(local.getCurrentSessionCount()).isEqualTo(1);143 local.stop(session.getId());144 assertThat(local.getCurrentSessionCount()).isEqualTo(0);145 }146 @Test147 public void sessionsThatAreStoppedWillNotBeReturned() {148 Session expected = node.newSession(createSessionRequest(caps))149 .map(CreateSessionResponse::getSession)150 .orElseThrow(() -> new RuntimeException("Session not created"));151 node.stop(expected.getId());152 assertThatExceptionOfType(NoSuchSessionException.class)153 .isThrownBy(() -> local.getSession(expected.getId()));154 assertThatExceptionOfType(NoSuchSessionException.class)155 .isThrownBy(() -> node.getSession(expected.getId()));156 }157 @Test158 public void stoppingASessionThatDoesNotExistWillThrowAnException() {159 assertThatExceptionOfType(NoSuchSessionException.class)160 .isThrownBy(() -> local.stop(new SessionId(UUID.randomUUID())));161 assertThatExceptionOfType(NoSuchSessionException.class)162 .isThrownBy(() -> node.stop(new SessionId(UUID.randomUUID())));163 }164 @Test165 public void attemptingToGetASessionThatDoesNotExistWillCauseAnExceptionToBeThrown() {166 assertThatExceptionOfType(NoSuchSessionException.class)167 .isThrownBy(() -> local.getSession(new SessionId(UUID.randomUUID())));168 assertThatExceptionOfType(NoSuchSessionException.class)169 .isThrownBy(() -> node.getSession(new SessionId(UUID.randomUUID())));170 }171 @Test172 public void willRespondToWebDriverCommandsSentToOwnedSessions() throws IOException {173 AtomicBoolean called = new AtomicBoolean(false);174 class Recording extends Session implements CommandHandler {175 private Recording() {176 super(new SessionId(UUID.randomUUID()), uri, caps);177 }178 @Override179 public void execute(HttpRequest req, HttpResponse resp) {180 called.set(true);181 }182 }183 Node local = LocalNode.builder(tracer, bus, clientFactory, uri)184 .add(caps, new TestSessionFactory((id, c) -> new Recording()))185 .build();186 Node remote = new RemoteNode(187 tracer,188 new PassthroughHttpClient.Factory<>(local),189 UUID.randomUUID(),190 uri,191 ImmutableSet.of(caps));192 Session session = remote.newSession(createSessionRequest(caps))193 .map(CreateSessionResponse::getSession)194 .orElseThrow(() -> new RuntimeException("Session not created"));195 HttpRequest req = new HttpRequest(POST, String.format("/session/%s/url", session.getId()));196 remote.execute(req, new HttpResponse());197 assertThat(called.get()).isTrue();198 }199 @Test200 public void shouldOnlyRespondToWebDriverCommandsForSessionsTheNodeOwns() {201 Session session = node.newSession(createSessionRequest(caps))202 .map(CreateSessionResponse::getSession)203 .orElseThrow(() -> new RuntimeException("Session not created"));204 HttpRequest req = new HttpRequest(POST, String.format("/session/%s/url", session.getId()));205 assertThat(local.test(req)).isTrue();206 assertThat(node.test(req)).isTrue();207 req = new HttpRequest(POST, String.format("/session/%s/url", UUID.randomUUID()));208 assertThat(local.test(req)).isFalse();209 assertThat(node.test(req)).isFalse();210 }211 @Test212 public void aSessionThatTimesOutWillBeStoppedAndRemovedFromTheSessionMap() {213 AtomicReference<Instant> now = new AtomicReference<>(Instant.now());214 Clock clock = new MyClock(now);215 Node node = LocalNode.builder(tracer, bus, clientFactory, uri)216 .add(caps, new TestSessionFactory((id, c) -> new Session(id, uri, c)))217 .sessionTimeout(Duration.ofMinutes(3))218 .advanced()219 .clock(clock)220 .build();221 Session session = node.newSession(createSessionRequest(caps))222 .map(CreateSessionResponse::getSession)223 .orElseThrow(() -> new RuntimeException("Session not created"));224 now.set(now.get().plus(Duration.ofMinutes(5)));225 assertThatExceptionOfType(NoSuchSessionException.class)226 .isThrownBy(() -> node.getSession(session.getId()));227 }228 @Test229 public void shouldNotPropagateExceptionsWhenSessionCreationFails() {230 Node local = LocalNode.builder(tracer, bus, clientFactory, uri)231 .add(caps, new TestSessionFactory((id, c) -> {232 throw new SessionNotCreatedException("eeek");233 }))234 .build();235 Optional<Session> session = local.newSession(createSessionRequest(caps))236 .map(CreateSessionResponse::getSession);237 assertThat(session.isPresent()).isFalse();238 }239 @Test240 public void eachSessionShouldReportTheNodesUrl() throws URISyntaxException {241 URI sessionUri = new URI("http://cheese:42/peas");242 Node node = LocalNode.builder(tracer, bus, clientFactory, uri)243 .add(caps, new TestSessionFactory((id, c) -> new Session(id, sessionUri, c)))244 .build();245 Optional<Session> session = node.newSession(createSessionRequest(caps))246 .map(CreateSessionResponse::getSession);247 assertThat(session.isPresent()).isTrue();248 assertThat(session.get().getUri()).isEqualTo(uri);249 }250 @Test251 public void quittingASessionShouldCauseASessionClosedEventToBeFired() {252 AtomicReference<Object> obj = new AtomicReference<>();253 bus.addListener(SESSION_CLOSED, event -> obj.set(event.getData(Object.class)));254 Session session = node.newSession(createSessionRequest(caps))255 .map(CreateSessionResponse::getSession)256 .orElseThrow(() -> new AssertionError("Cannot create session"));257 node.stop(session.getId());258 // Because we're using the event bus, we can't expect the event to fire instantly. We're using259 // an inproc bus, so in reality it's reasonable to expect the event to fire synchronously, but260 // let's play it safe.261 Wait<AtomicReference<Object>> wait = new FluentWait<>(obj).withTimeout(ofSeconds(2));262 wait.until(ref -> ref.get() != null);263 }264 private CreateSessionRequest createSessionRequest(Capabilities caps) {265 return new CreateSessionRequest(266 ImmutableSet.copyOf(Dialect.values()),267 caps,268 ImmutableMap.of());269 }...

Full Screen

Full Screen

Source:LocalDistributor.java Github

copy

Full Screen

...23import org.openqa.selenium.concurrent.Regularly;24import org.openqa.selenium.events.EventBus;25import org.openqa.selenium.grid.config.Config;26import org.openqa.selenium.grid.data.CreateSessionRequest;27import org.openqa.selenium.grid.data.CreateSessionResponse;28import org.openqa.selenium.grid.data.DistributorStatus;29import org.openqa.selenium.grid.data.NodeAddedEvent;30import org.openqa.selenium.grid.data.NodeDrainComplete;31import org.openqa.selenium.grid.data.NodeId;32import org.openqa.selenium.grid.data.NodeRemovedEvent;33import org.openqa.selenium.grid.data.NodeStatus;34import org.openqa.selenium.grid.data.NodeStatusEvent;35import org.openqa.selenium.grid.data.Slot;36import org.openqa.selenium.grid.data.SlotId;37import org.openqa.selenium.grid.distributor.Distributor;38import org.openqa.selenium.grid.distributor.selector.DefaultSlotSelector;39import org.openqa.selenium.grid.log.LoggingOptions;40import org.openqa.selenium.grid.node.HealthCheck;41import org.openqa.selenium.grid.node.Node;42import org.openqa.selenium.grid.node.remote.RemoteNode;43import org.openqa.selenium.grid.security.Secret;44import org.openqa.selenium.grid.server.BaseServerOptions;45import org.openqa.selenium.grid.server.EventBusOptions;46import org.openqa.selenium.grid.server.NetworkOptions;47import org.openqa.selenium.grid.sessionmap.SessionMap;48import org.openqa.selenium.grid.sessionmap.config.SessionMapOptions;49import org.openqa.selenium.internal.Require;50import org.openqa.selenium.remote.http.HttpClient;51import org.openqa.selenium.remote.tracing.Tracer;52import org.openqa.selenium.status.HasReadyState;53import java.time.Duration;54import java.util.ArrayList;55import java.util.HashMap;56import java.util.List;57import java.util.Map;58import java.util.Optional;59import java.util.Set;60import java.util.concurrent.locks.Lock;61import java.util.concurrent.locks.ReadWriteLock;62import java.util.concurrent.locks.ReentrantReadWriteLock;63import java.util.function.Supplier;64import java.util.logging.Level;65import java.util.logging.Logger;66import static com.google.common.collect.ImmutableSet.toImmutableSet;67import static org.openqa.selenium.grid.data.Availability.DOWN;68import static org.openqa.selenium.grid.data.Availability.DRAINING;69public class LocalDistributor extends Distributor {70 private static final Logger LOG = Logger.getLogger(LocalDistributor.class.getName());71 private final Tracer tracer;72 private final EventBus bus;73 private final HttpClient.Factory clientFactory;74 private final SessionMap sessions;75 private final Secret registrationSecret;76 private final Regularly hostChecker = new Regularly("distributor host checker");77 private final Map<NodeId, Runnable> allChecks = new HashMap<>();78 private final ReadWriteLock lock = new ReentrantReadWriteLock(/* fair */ true);79 private final GridModel model;80 private final Map<NodeId, Node> nodes;81 public LocalDistributor(82 Tracer tracer,83 EventBus bus,84 HttpClient.Factory clientFactory,85 SessionMap sessions,86 Secret registrationSecret) {87 super(tracer, clientFactory, new DefaultSlotSelector(), sessions, registrationSecret);88 this.tracer = Require.nonNull("Tracer", tracer);89 this.bus = Require.nonNull("Event bus", bus);90 this.clientFactory = Require.nonNull("HTTP client factory", clientFactory);91 this.sessions = Require.nonNull("Session map", sessions);92 this.model = new GridModel(bus, registrationSecret);93 this.nodes = new HashMap<>();94 this.registrationSecret = Require.nonNull("Registration secret", registrationSecret);95 bus.addListener(NodeStatusEvent.listener(this::register));96 bus.addListener(NodeStatusEvent.listener(model::refresh));97 bus.addListener(NodeDrainComplete.listener(this::remove));98 }99 public static Distributor create(Config config) {100 Tracer tracer = new LoggingOptions(config).getTracer();101 EventBus bus = new EventBusOptions(config).getEventBus();102 HttpClient.Factory clientFactory = new NetworkOptions(config).getHttpClientFactory(tracer);103 SessionMap sessions = new SessionMapOptions(config).getSessionMap();104 BaseServerOptions serverOptions = new BaseServerOptions(config);105 return new LocalDistributor(tracer, bus, clientFactory, sessions, serverOptions.getRegistrationSecret());106 }107 @Override108 public boolean isReady() {109 try {110 return ImmutableSet.of(bus, sessions).parallelStream()111 .map(HasReadyState::isReady)112 .reduce(true, Boolean::logicalAnd);113 } catch (RuntimeException e) {114 return false;115 }116 }117 private void register(NodeStatus status) {118 Require.nonNull("Node", status);119 Lock writeLock = lock.writeLock();120 writeLock.lock();121 try {122 if (nodes.containsKey(status.getId())) {123 return;124 }125 Set<Capabilities> capabilities = status.getSlots().stream()126 .map(Slot::getStereotype)127 .map(ImmutableCapabilities::copyOf)128 .collect(toImmutableSet());129 // A new node! Add this as a remote node, since we've not called add130 RemoteNode remoteNode = new RemoteNode(131 tracer,132 clientFactory,133 status.getId(),134 status.getUri(),135 registrationSecret,136 capabilities);137 add(remoteNode);138 } finally {139 writeLock.unlock();140 }141 }142 @Override143 public LocalDistributor add(Node node) {144 Require.nonNull("Node", node);145 LOG.info(String.format("Added node %s at %s.", node.getId(), node.getUri()));146 nodes.put(node.getId(), node);147 model.add(node.getStatus());148 // Extract the health check149 Runnable runnableHealthCheck = asRunnableHealthCheck(node);150 allChecks.put(node.getId(), runnableHealthCheck);151 hostChecker.submit(runnableHealthCheck, Duration.ofMinutes(5), Duration.ofSeconds(30));152 bus.fire(new NodeAddedEvent(node.getId()));153 return this;154 }155 private Runnable asRunnableHealthCheck(Node node) {156 HealthCheck healthCheck = node.getHealthCheck();157 NodeId id = node.getId();158 return () -> {159 HealthCheck.Result result;160 try {161 result = healthCheck.check();162 } catch (Exception e) {163 LOG.log(Level.WARNING, "Unable to process node " + id, e);164 result = new HealthCheck.Result(DOWN, "Unable to run healthcheck. Assuming down");165 }166 Lock writeLock = lock.writeLock();167 writeLock.lock();168 try {169 model.setAvailability(id, result.getAvailability());170 } finally {171 writeLock.unlock();172 }173 };174 }175 @Override176 public boolean drain(NodeId nodeId) {177 Node node = nodes.get(nodeId);178 if (node == null) {179 LOG.info("Asked to drain unregistered node " + nodeId);180 return false;181 }182 Lock writeLock = lock.writeLock();183 writeLock.lock();184 try {185 node.drain();186 model.setAvailability(nodeId, DRAINING);187 } finally {188 writeLock.unlock();189 }190 return node.isDraining();191 }192 public void remove(NodeId nodeId) {193 Lock writeLock = lock.writeLock();194 writeLock.lock();195 try {196 model.remove(nodeId);197 Runnable runnable = allChecks.remove(nodeId);198 if (runnable != null) {199 hostChecker.remove(runnable);200 }201 } finally {202 writeLock.unlock();203 bus.fire(new NodeRemovedEvent(nodeId));204 }205 }206 @Override207 public DistributorStatus getStatus() {208 Lock readLock = this.lock.readLock();209 readLock.lock();210 try {211 return new DistributorStatus(model.getSnapshot());212 } finally {213 readLock.unlock();214 }215 }216 @Beta217 public void refresh() {218 List<Runnable> allHealthChecks = new ArrayList<>();219 Lock readLock = this.lock.readLock();220 readLock.lock();221 try {222 allHealthChecks.addAll(allChecks.values());223 } finally {224 readLock.unlock();225 }226 allHealthChecks.parallelStream().forEach(Runnable::run);227 }228 @Override229 protected Set<NodeStatus> getAvailableNodes() {230 Lock readLock = this.lock.readLock();231 readLock.lock();232 try {233 return model.getSnapshot().stream()234 .filter(node -> !DOWN.equals(node.getAvailability()))235 .collect(toImmutableSet());236 } finally {237 readLock.unlock();238 }239 }240 @Override241 protected Supplier<CreateSessionResponse> reserve(SlotId slotId, CreateSessionRequest request) {242 Require.nonNull("Slot ID", slotId);243 Require.nonNull("New Session request", request);244 Lock writeLock = this.lock.writeLock();245 writeLock.lock();246 try {247 Node node = nodes.get(slotId.getOwningNodeId());248 if (node == null) {249 return () -> {250 throw new SessionNotCreatedException("Unable to find node");251 };252 }253 model.reserve(slotId);254 return () -> {255 Optional<CreateSessionResponse> response = node.newSession(request);256 if (!response.isPresent()) {257 model.setSession(slotId, null);258 throw new SessionNotCreatedException("Unable to create session for " + request);259 }260 model.setSession(slotId, response.get().getSession());261 return response.get();262 };263 } finally {264 writeLock.unlock();265 }266 }267}...

Full Screen

Full Screen

Source:AddingNodesTest.java Github

copy

Full Screen

...27import org.openqa.selenium.NoSuchSessionException;28import org.openqa.selenium.events.EventBus;29import org.openqa.selenium.grid.component.HealthCheck;30import org.openqa.selenium.grid.data.CreateSessionRequest;31import org.openqa.selenium.grid.data.CreateSessionResponse;32import org.openqa.selenium.grid.data.DistributorStatus;33import org.openqa.selenium.grid.data.NodeStatus;34import org.openqa.selenium.grid.data.NodeStatusEvent;35import org.openqa.selenium.grid.data.Session;36import org.openqa.selenium.grid.data.SessionClosedEvent;37import org.openqa.selenium.grid.distributor.local.LocalDistributor;38import org.openqa.selenium.grid.distributor.remote.RemoteDistributor;39import org.openqa.selenium.grid.node.CapabilityResponseEncoder;40import org.openqa.selenium.grid.node.Node;41import org.openqa.selenium.grid.node.local.LocalNode;42import org.openqa.selenium.events.local.GuavaEventBus;43import org.openqa.selenium.grid.testing.TestSessionFactory;44import org.openqa.selenium.grid.sessionmap.local.LocalSessionMap;45import org.openqa.selenium.grid.web.CombinedHandler;46import org.openqa.selenium.grid.web.RoutableHttpClientFactory;47import org.openqa.selenium.remote.SessionId;48import org.openqa.selenium.remote.http.HttpClient;49import org.openqa.selenium.remote.http.HttpRequest;50import org.openqa.selenium.remote.http.HttpResponse;51import org.openqa.selenium.remote.tracing.DistributedTracer;52import org.openqa.selenium.support.ui.FluentWait;53import org.openqa.selenium.support.ui.Wait;54import java.net.MalformedURLException;55import java.net.URI;56import java.net.URISyntaxException;57import java.net.URL;58import java.time.Duration;59import java.util.HashSet;60import java.util.Objects;61import java.util.Optional;62import java.util.Set;63import java.util.UUID;64import java.util.function.Function;65public class AddingNodesTest {66 private static final Capabilities CAPS = new ImmutableCapabilities("cheese", "gouda");67 private Distributor distributor;68 private DistributedTracer tracer;69 private EventBus bus;70 private HttpClient.Factory clientFactory;71 private Wait<Object> wait;72 private URL externalUrl;73 private CombinedHandler handler;74 @Before75 public void setUpDistributor() throws MalformedURLException {76 tracer = DistributedTracer.builder().build();77 bus = new GuavaEventBus();78 handler = new CombinedHandler();79 externalUrl = new URL("http://example.com");80 clientFactory = new RoutableHttpClientFactory(81 externalUrl,82 handler,83 HttpClient.Factory.createDefault());84 LocalSessionMap sessions = new LocalSessionMap(tracer, bus);85 Distributor local = new LocalDistributor(tracer, bus, clientFactory, sessions);86 handler.addHandler(local);87 distributor = new RemoteDistributor(tracer, clientFactory, externalUrl);88 wait = new FluentWait<>(new Object()).withTimeout(Duration.ofSeconds(2));89 }90 @Test91 public void shouldBeAbleToRegisterALocalNode() throws URISyntaxException {92 URI sessionUri = new URI("http://example:1234");93 Node node = LocalNode.builder(tracer, bus, clientFactory, externalUrl.toURI())94 .add(CAPS, new TestSessionFactory((id, caps) -> new Session(id, sessionUri, caps)))95 .build();96 handler.addHandler(node);97 distributor.add(node);98 wait.until(obj -> distributor.getStatus().hasCapacity());99 DistributorStatus.NodeSummary summary = getOnlyElement(distributor.getStatus().getNodes());100 assertEquals(1, summary.getStereotypes().get(CAPS).intValue());101 }102 @Test103 public void shouldBeAbleToRegisterACustomNode() throws URISyntaxException {104 URI sessionUri = new URI("http://example:1234");105 Node node = new CustomNode(106 tracer,107 bus,108 UUID.randomUUID(),109 externalUrl.toURI(),110 c -> new Session(new SessionId(UUID.randomUUID()), sessionUri, c));111 handler.addHandler(node);112 distributor.add(node);113 wait.until(obj -> distributor.getStatus().hasCapacity());114 DistributorStatus.NodeSummary summary = getOnlyElement(distributor.getStatus().getNodes());115 assertEquals(1, summary.getStereotypes().get(CAPS).intValue());116 }117 @Test118 public void shouldBeAbleToRegisterNodesByListeningForEvents() throws URISyntaxException {119 URI sessionUri = new URI("http://example:1234");120 Node node = LocalNode.builder(tracer, bus, clientFactory, externalUrl.toURI())121 .add(CAPS, new TestSessionFactory((id, caps) -> new Session(id, sessionUri, caps)))122 .build();123 handler.addHandler(node);124 bus.fire(new NodeStatusEvent(node.getStatus()));125 wait.until(obj -> distributor.getStatus().hasCapacity());126 DistributorStatus.NodeSummary summary = getOnlyElement(distributor.getStatus().getNodes());127 assertEquals(1, summary.getStereotypes().get(CAPS).intValue());128 }129 @Test130 public void distributorShouldUpdateStateOfExistingNodeWhenNodePublishesStateChange()131 throws URISyntaxException {132 URI sessionUri = new URI("http://example:1234");133 Node node = LocalNode.builder(tracer, bus, clientFactory, externalUrl.toURI())134 .add(CAPS, new TestSessionFactory((id, caps) -> new Session(id, sessionUri, caps)))135 .build();136 handler.addHandler(node);137 bus.fire(new NodeStatusEvent(node.getStatus()));138 // Start empty139 wait.until(obj -> distributor.getStatus().hasCapacity());140 DistributorStatus.NodeSummary summary = getOnlyElement(distributor.getStatus().getNodes());141 assertEquals(1, summary.getStereotypes().get(CAPS).intValue());142 // Craft a status that makes it look like the node is busy, and post it on the bus.143 NodeStatus status = node.getStatus();144 NodeStatus crafted = new NodeStatus(145 status.getNodeId(),146 status.getUri(),147 status.getMaxSessionCount(),148 status.getStereotypes(),149 ImmutableSet.of(new NodeStatus.Active(CAPS, new SessionId(UUID.randomUUID()), CAPS)));150 bus.fire(new NodeStatusEvent(crafted));151 // We claimed the only slot is filled. Life is good.152 wait.until(obj -> !distributor.getStatus().hasCapacity());153 }154 static class CustomNode extends Node {155 private final EventBus bus;156 private final Function<Capabilities, Session> factory;157 private Session running;158 protected CustomNode(159 DistributedTracer tracer,160 EventBus bus,161 UUID nodeId,162 URI uri,163 Function<Capabilities, Session> factory) {164 super(tracer, nodeId, uri);165 this.bus = bus;166 this.factory = Objects.requireNonNull(factory);167 }168 @Override169 public Optional<CreateSessionResponse> newSession(CreateSessionRequest sessionRequest) {170 Objects.requireNonNull(sessionRequest);171 if (running != null) {172 return Optional.empty();173 }174 Session session = factory.apply(sessionRequest.getCapabilities());175 running = session;176 return Optional.of(177 new CreateSessionResponse(178 session,179 CapabilityResponseEncoder.getEncoder(W3C).apply(session)));180 }181 @Override182 public void executeWebDriverCommand(HttpRequest req, HttpResponse resp) {183 throw new UnsupportedOperationException("executeWebDriverCommand");184 }185 @Override186 public Session getSession(SessionId id) throws NoSuchSessionException {187 if (running == null || !running.getId().equals(id)) {188 throw new NoSuchSessionException();189 }190 return running;191 }...

Full Screen

Full Screen

Source:RemoteNode.java Github

copy

Full Screen

...19import com.google.common.collect.ImmutableSet;20import org.openqa.selenium.Capabilities;21import org.openqa.selenium.NoSuchSessionException;22import org.openqa.selenium.grid.data.CreateSessionRequest;23import org.openqa.selenium.grid.data.CreateSessionResponse;24import org.openqa.selenium.grid.data.NodeId;25import org.openqa.selenium.grid.data.NodeStatus;26import org.openqa.selenium.grid.data.Session;27import org.openqa.selenium.grid.node.HealthCheck;28import org.openqa.selenium.grid.node.Node;29import org.openqa.selenium.grid.security.AddSecretFilter;30import org.openqa.selenium.grid.security.Secret;31import org.openqa.selenium.grid.web.Values;32import org.openqa.selenium.internal.Require;33import org.openqa.selenium.json.Json;34import org.openqa.selenium.json.JsonInput;35import org.openqa.selenium.remote.SessionId;36import org.openqa.selenium.remote.http.Filter;37import org.openqa.selenium.remote.http.HttpClient;38import org.openqa.selenium.remote.http.HttpHandler;39import org.openqa.selenium.remote.http.HttpRequest;40import org.openqa.selenium.remote.http.HttpResponse;41import org.openqa.selenium.remote.tracing.HttpTracing;42import org.openqa.selenium.remote.tracing.Tracer;43import java.io.IOException;44import java.io.Reader;45import java.io.UncheckedIOException;46import java.net.URI;47import java.util.Collection;48import java.util.Map;49import java.util.Objects;50import java.util.Optional;51import java.util.Set;52import static java.net.HttpURLConnection.HTTP_OK;53import static org.openqa.selenium.grid.data.Availability.DOWN;54import static org.openqa.selenium.grid.data.Availability.DRAINING;55import static org.openqa.selenium.grid.data.Availability.UP;56import static org.openqa.selenium.net.Urls.fromUri;57import static org.openqa.selenium.remote.http.Contents.asJson;58import static org.openqa.selenium.remote.http.Contents.reader;59import static org.openqa.selenium.remote.http.HttpMethod.DELETE;60import static org.openqa.selenium.remote.http.HttpMethod.GET;61import static org.openqa.selenium.remote.http.HttpMethod.POST;62public class RemoteNode extends Node {63 public static final Json JSON = new Json();64 private final HttpHandler client;65 private final URI externalUri;66 private final Set<Capabilities> capabilities;67 private final HealthCheck healthCheck;68 private final Filter addSecret;69 public RemoteNode(70 Tracer tracer,71 HttpClient.Factory clientFactory,72 NodeId id,73 URI externalUri,74 Secret registrationSecret,75 Collection<Capabilities> capabilities) {76 super(tracer, id, externalUri, registrationSecret);77 this.externalUri = Require.nonNull("External URI", externalUri);78 this.capabilities = ImmutableSet.copyOf(capabilities);79 this.client = Require.nonNull("HTTP client factory", clientFactory).createClient(fromUri(externalUri));80 this.healthCheck = new RemoteCheck();81 Require.nonNull("Registration secret", registrationSecret);82 this.addSecret = new AddSecretFilter(registrationSecret);83 }84 @Override85 public boolean isReady() {86 try {87 return client.execute(new HttpRequest(GET, "/readyz")).isSuccessful();88 } catch (Exception e) {89 return false;90 }91 }92 @Override93 public boolean isSupporting(Capabilities capabilities) {94 return this.capabilities.stream()95 .anyMatch(caps -> caps.getCapabilityNames().stream()96 .allMatch(name -> Objects.equals(97 caps.getCapability(name),98 capabilities.getCapability(name))));99 }100 @Override101 public Optional<CreateSessionResponse> newSession(CreateSessionRequest sessionRequest) {102 Require.nonNull("Capabilities for session", sessionRequest);103 HttpRequest req = new HttpRequest(POST, "/se/grid/node/session");104 HttpTracing.inject(tracer, tracer.getCurrentContext(), req);105 req.setContent(asJson(sessionRequest));106 HttpResponse res = client.with(addSecret).execute(req);107 return Optional.ofNullable(Values.get(res, CreateSessionResponse.class));108 }109 @Override110 public boolean isSessionOwner(SessionId id) {111 Require.nonNull("Session ID", id);112 HttpRequest req = new HttpRequest(GET, "/se/grid/node/owner/" + id);113 HttpTracing.inject(tracer, tracer.getCurrentContext(), req);114 HttpResponse res = client.with(addSecret).execute(req);115 return Boolean.TRUE.equals(Values.get(res, Boolean.class));116 }117 @Override118 public Session getSession(SessionId id) throws NoSuchSessionException {119 Require.nonNull("Session ID", id);120 HttpRequest req = new HttpRequest(GET, "/se/grid/node/session/" + id);121 HttpTracing.inject(tracer, tracer.getCurrentContext(), req);...

Full Screen

Full Screen

Source:RemoteDistributor.java Github

copy

Full Screen

...16// under the License.17package org.openqa.selenium.grid.distributor.remote;18import org.openqa.selenium.SessionNotCreatedException;19import org.openqa.selenium.grid.data.CreateSessionRequest;20import org.openqa.selenium.grid.data.CreateSessionResponse;21import org.openqa.selenium.grid.data.DistributorStatus;22import org.openqa.selenium.grid.data.NodeId;23import org.openqa.selenium.grid.data.NodeStatus;24import org.openqa.selenium.grid.data.SlotId;25import org.openqa.selenium.grid.distributor.Distributor;26import org.openqa.selenium.grid.node.Node;27import org.openqa.selenium.grid.security.AddSecretFilter;28import org.openqa.selenium.grid.security.Secret;29import org.openqa.selenium.grid.sessionmap.NullSessionMap;30import org.openqa.selenium.grid.web.Values;31import org.openqa.selenium.internal.Require;32import org.openqa.selenium.remote.http.Filter;33import org.openqa.selenium.remote.http.HttpClient;34import org.openqa.selenium.remote.http.HttpHandler;35import org.openqa.selenium.remote.http.HttpRequest;36import org.openqa.selenium.remote.http.HttpResponse;37import org.openqa.selenium.remote.tracing.HttpTracing;38import org.openqa.selenium.remote.tracing.Tracer;39import java.net.URL;40import java.util.Set;41import java.util.function.Supplier;42import java.util.logging.Logger;43import static org.openqa.selenium.remote.http.Contents.asJson;44import static org.openqa.selenium.remote.http.HttpMethod.DELETE;45import static org.openqa.selenium.remote.http.HttpMethod.GET;46import static org.openqa.selenium.remote.http.HttpMethod.POST;47public class RemoteDistributor extends Distributor {48 private static final Logger LOG = Logger.getLogger("Selenium Distributor (Remote)");49 private final HttpHandler client;50 private final Filter addSecret;51 public RemoteDistributor(Tracer tracer, HttpClient.Factory factory, URL url, Secret registrationSecret) {52 super(53 tracer,54 factory,55 (caps, nodes) -> {throw new UnsupportedOperationException("host selection");},56 new NullSessionMap(tracer),57 registrationSecret);58 this.client = factory.createClient(url);59 this.addSecret = new AddSecretFilter(registrationSecret);60 }61 @Override62 public boolean isReady() {63 try {64 return client.execute(new HttpRequest(GET, "/readyz")).isSuccessful();65 } catch (Exception e) {66 return false;67 }68 }69 @Override70 public CreateSessionResponse newSession(HttpRequest request)71 throws SessionNotCreatedException {72 HttpRequest upstream = new HttpRequest(POST, "/se/grid/distributor/session");73 HttpTracing.inject(tracer, tracer.getCurrentContext(), upstream);74 upstream.setContent(request.getContent());75 HttpResponse response = client.with(addSecret).execute(upstream);76 return Values.get(response, CreateSessionResponse.class);77 }78 @Override79 public RemoteDistributor add(Node node) {80 HttpRequest request = new HttpRequest(POST, "/se/grid/distributor/node");81 HttpTracing.inject(tracer, tracer.getCurrentContext(), request);82 request.setContent(asJson(node.getStatus()));83 HttpResponse response = client.with(addSecret).execute(request);84 Values.get(response, Void.class);85 LOG.info(String.format("Added node %s.", node.getId()));86 return this;87 }88 @Override89 public boolean drain(NodeId nodeId) {90 Require.nonNull("Node ID", nodeId);91 HttpRequest request = new HttpRequest(POST, "/se/grid/distributor/node/" + nodeId + "/drain");92 HttpTracing.inject(tracer, tracer.getCurrentContext(), request);93 request.setContent(asJson(nodeId));94 HttpResponse response = client.with(addSecret).execute(request);95 return Values.get(response, Boolean.class);96 }97 @Override98 public void remove(NodeId nodeId) {99 Require.nonNull("Node ID", nodeId);100 HttpRequest request = new HttpRequest(DELETE, "/se/grid/distributor/node/" + nodeId);101 HttpTracing.inject(tracer, tracer.getCurrentContext(), request);102 HttpResponse response = client.with(addSecret).execute(request);103 Values.get(response, Void.class);104 }105 @Override106 public DistributorStatus getStatus() {107 HttpRequest request = new HttpRequest(GET, "/se/grid/distributor/status");108 HttpTracing.inject(tracer, tracer.getCurrentContext(), request);109 HttpResponse response = client.execute(request);110 return Values.get(response, DistributorStatus.class);111 }112 @Override113 protected Set<NodeStatus> getAvailableNodes() {114 throw new UnsupportedOperationException("getModel is not required for remote sessions");115 }116 @Override117 protected Supplier<CreateSessionResponse> reserve(SlotId slot, CreateSessionRequest request) {118 throw new UnsupportedOperationException("reserve is not required for remote sessions");119 }120}...

Full Screen

Full Screen

Source:Distributor.java Github

copy

Full Screen

...19import static org.openqa.selenium.grid.web.Routes.get;20import static org.openqa.selenium.grid.web.Routes.post;21import static org.openqa.selenium.remote.http.Contents.bytes;22import org.openqa.selenium.SessionNotCreatedException;23import org.openqa.selenium.grid.data.CreateSessionResponse;24import org.openqa.selenium.grid.data.DistributorStatus;25import org.openqa.selenium.grid.data.Session;26import org.openqa.selenium.grid.node.Node;27import org.openqa.selenium.grid.web.CommandHandler;28import org.openqa.selenium.grid.web.HandlerNotFoundException;29import org.openqa.selenium.grid.web.Routes;30import org.openqa.selenium.json.Json;31import org.openqa.selenium.remote.http.HttpClient;32import org.openqa.selenium.remote.http.HttpRequest;33import org.openqa.selenium.remote.http.HttpResponse;34import org.openqa.selenium.remote.tracing.DistributedTracer;35import java.io.IOException;36import java.util.Map;37import java.util.Objects;38import java.util.Optional;39import java.util.UUID;40import java.util.function.Predicate;41/**42 * Responsible for being the central place where the {@link Node}s on which {@link Session}s run43 * are determined.44 * <p>45 * This class responds to the following URLs:46 * <table summary="HTTP commands the Distributor understands">47 * <tr>48 * <th>Verb</th>49 * <th>URL Template</th>50 * <th>Meaning</th>51 * </tr>52 * <tr>53 * <td>POST</td>54 * <td>/session</td>55 * <td>This is exactly the same as the New Session command from the WebDriver spec.</td>56 * </tr>57 * <tr>58 * <td>POST</td>59 * <td>/se/grid/distributor/node</td>60 * <td>Adds a new {@link Node} to this distributor. Please read the javadocs for {@link Node} for61 * how the Node should be serialized.</td>62 * </tr>63 * <tr>64 * <td>DELETE</td>65 * <td>/se/grid/distributor/node/{nodeId}</td>66 * <td>Remove the {@link Node} identified by {@code nodeId} from this distributor. It is expected67 * that any sessions running on the Node are allowed to complete: this simply means that no new68 * sessions will be scheduled on this Node.</td>69 * </tr>70 * </table>71 */72public abstract class Distributor implements Predicate<HttpRequest>, CommandHandler {73 private final Routes routes;74 protected Distributor(DistributedTracer tracer, HttpClient.Factory httpClientFactory) {75 Objects.requireNonNull(tracer);76 Objects.requireNonNull(httpClientFactory);77 Json json = new Json();78 routes = Routes.combine(79 post("/session").using((req, res) -> {80 CreateSessionResponse sessionResponse = newSession(req);81 res.setContent(bytes(sessionResponse.getDownstreamEncodedResponse()));82 }),83 post("/se/grid/distributor/session")84 .using(() -> new CreateSession(json, this)),85 post("/se/grid/distributor/node")86 .using(() -> new AddNode(tracer, this, json, httpClientFactory)),87 delete("/se/grid/distributor/node/{nodeId}")88 .using((Map<String,String> params) -> new RemoveNode(this, UUID.fromString(params.get("nodeId")))),89 get("/se/grid/distributor/status")90 .using(() -> new GetDistributorStatus(json, this)))91 .build();92 }93 public abstract CreateSessionResponse newSession(HttpRequest request)94 throws SessionNotCreatedException;95 public abstract Distributor add(Node node);96 public abstract void remove(UUID nodeId);97 public abstract DistributorStatus getStatus();98 @Override99 public boolean test(HttpRequest req) {100 return routes.match(req).isPresent();101 }102 @Override103 public void execute(HttpRequest req, HttpResponse resp) throws IOException {104 Optional<CommandHandler> handler = routes.match(req);105 if (!handler.isPresent()) {106 throw new HandlerNotFoundException(req);107 }...

Full Screen

Full Screen

Source:Slot.java Github

copy

Full Screen

...20import static org.openqa.selenium.grid.distributor.local.Slot.Status.RESERVED;21import org.openqa.selenium.Capabilities;22import org.openqa.selenium.SessionNotCreatedException;23import org.openqa.selenium.grid.data.CreateSessionRequest;24import org.openqa.selenium.grid.data.CreateSessionResponse;25import org.openqa.selenium.grid.data.Session;26import org.openqa.selenium.grid.node.Node;27import org.openqa.selenium.remote.SessionId;28import java.util.Objects;29import java.util.function.Supplier;30public class Slot {31 private final Node node;32 private final Capabilities registeredCapabilities;33 private Status currentStatus;34 private long lastStartedNanos;35 private Session currentSession;36 public Slot(Node node, Capabilities capabilities, Status status) {37 this.node = Objects.requireNonNull(node);38 this.registeredCapabilities = Objects.requireNonNull(capabilities);39 this.currentStatus = Objects.requireNonNull(status);40 }41 public Capabilities getStereotype() {42 return registeredCapabilities;43 }44 public Status getStatus() {45 return currentStatus;46 }47 public long getLastSessionCreated() {48 return lastStartedNanos;49 }50 public boolean isSupporting(Capabilities caps) {51 // Simple implementation --- only checks current values52 return registeredCapabilities.getCapabilityNames().stream()53 .map(name -> Objects.equals(54 registeredCapabilities.getCapability(name),55 caps.getCapability(name)))56 .reduce(Boolean::logicalAnd)57 .orElse(false);58 }59 public Supplier<CreateSessionResponse> onReserve(CreateSessionRequest sessionRequest) {60 if (getStatus() != AVAILABLE) {61 throw new IllegalStateException("Node is not available");62 }63 currentStatus = RESERVED;64 return () -> {65 try {66 CreateSessionResponse sessionResponse = node.newSession(sessionRequest)67 .orElseThrow(68 () -> new SessionNotCreatedException(69 "Unable to create session for " + sessionRequest));70 onStart(sessionResponse.getSession());71 return sessionResponse;72 } catch (Throwable t) {73 currentStatus = AVAILABLE;74 currentSession = null;75 throw t;76 }77 };78 }79 public void onStart(Session session) {80 if (getStatus() != RESERVED) {...

Full Screen

Full Screen

Source:NewNodeSession.java Github

copy

Full Screen

...17package org.openqa.selenium.grid.node;18import static org.openqa.selenium.remote.http.Contents.string;19import static org.openqa.selenium.remote.http.Contents.utf8String;20import org.openqa.selenium.grid.data.CreateSessionRequest;21import org.openqa.selenium.grid.data.CreateSessionResponse;22import org.openqa.selenium.grid.web.CommandHandler;23import org.openqa.selenium.json.Json;24import org.openqa.selenium.remote.http.HttpRequest;25import org.openqa.selenium.remote.http.HttpResponse;26import java.util.HashMap;27import java.util.Objects;28import java.util.function.BiConsumer;29class NewNodeSession implements CommandHandler {30 private final BiConsumer<HttpResponse, Object> encodeJson;31 private final Node node;32 private final Json json;33 NewNodeSession(Node node, Json json) {34 this.node = Objects.requireNonNull(node);35 this.json = Objects.requireNonNull(json);36 this.encodeJson = (res, obj) -> res.setContent(utf8String(json.toJson(obj)));37 }38 @Override39 public void execute(HttpRequest req, HttpResponse resp) {40 CreateSessionRequest incoming = json.toType(string(req), CreateSessionRequest.class);41 CreateSessionResponse sessionResponse = node.newSession(incoming).orElse(null);42 HashMap<String, Object> value = new HashMap<>();43 value.put("value", sessionResponse);44 encodeJson.accept(resp, value);45 }46}...

Full Screen

Full Screen

CreateSessionResponse

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.grid.data.CreateSessionResponse;2import org.openqa.selenium.grid.data.Session;3import org.openqa.selenium.grid.data.SessionId;4import org.openqa.selenium.grid.data.SessionInfo;5import org.openqa.selenium.grid.data.Slot;6import org.openqa.selenium.grid.data.SlotId;7import org.openqa.selenium.grid.data.SlotMatch;8import org.openqa.selenium.grid.data.SlotMatchScore;9import org.openqa.selenium.grid.data.SlotRequest;10import org.openqa.selenium.grid.data.SlotRequestId;11import org.openqa.selenium.grid.data.SlotSession;12import org.openqa.selenium.grid.data.SlotSessionId;13import org.openqa.selenium.grid.data.SlotSessionRequest;14import org.openqa.selenium.grid.data.SlotSessionRequestEvent;15import org.openqa.selenium.grid.data.SlotSessionRequestEvent.State;16import org.openqa.selenium.grid.data.SlotSessionRequestEvent.StateChange;17import org.openqa.selenium.grid.data.SlotSessionRequestEvent.Type;18import org.openqa.selenium.grid.data.SlotSessionRequestEvent.TypeChange;19import org.openqa.selenium.grid.data.SlotSessionRequestEvent.TypeChange.TypeChanged;20import org.openqa.selenium.grid.data.SlotSessionRequestEvent.TypeChange.TypeCreated;21import org.openqa.selenium.grid.data.SlotSessionRequestEvent.TypeChange.TypeDeleted;22import org.openqa.selenium.grid.data.SlotSessionRequestEvent.TypeChange.TypeUpdated;23import org.openqa.selenium.grid.data.SlotSessionRequestEvent.TypeCreatedEvent;24import org.openqa.selenium.grid.data.SlotSessionRequestEvent.TypeDeletedEvent;25import org.openqa.selenium.grid.data.SlotSessionRequestEvent.TypeUpdatedEvent;26import org.openqa.selenium.grid.data.SlotSessionRequestEvent.TypeUpdatedEvent.TypeUpdatedData;27import org.openqa.selenium.grid.data.SlotSessionRequestEvent.TypeUpdatedEvent.TypeUpdatedData.StateChangeData;28import org.openqa.selenium.grid.data.SlotSessionRequestEvent.TypeUpdatedEvent.TypeUpdatedData.TypeChangedData;29import org.openqa.selenium.grid.data.SlotSessionRequestEvent.TypeUpdatedEvent.TypeUpdatedData.TypeCreatedData;30import org.openqa.selenium.grid.data.SlotSessionRequestEvent.TypeUpdatedEvent.TypeUpdatedData.TypeDeletedData;31import org.openqa.selenium.grid.data.SlotSessionRequestEvent.TypeUpdatedEvent.TypeUpdatedData.TypeUpdatedData;32import org.openqa.selenium.grid.data.SlotSessionRequestEvent.TypeUpdatedEvent.TypeUpdatedData.TypeUpdatedData.StateChangeData.StateChangedData;33import org.openqa.selenium.grid.data.SlotSessionRequestEvent.TypeUpdatedEvent.TypeUpdatedData.TypeUpdatedData.StateChangeData.StateCreatedData;34import org.openqa.selenium.grid.data.SlotSessionRequestEvent.TypeUpdatedEvent.TypeUpdatedData.Type

Full Screen

Full Screen

CreateSessionResponse

Using AI Code Generation

copy

Full Screen

1package com.selenium.test;2import org.openqa.selenium.remote.http.HttpClient;3import org.openqa.selenium.remote.http.HttpRequest;4import org.openqa.selenium.remote.http.HttpResponse;5import org.openqa.selenium.remote.http.HttpMethod;6import org.openqa.selenium.grid.data.CreateSessionResponse;7import org.openqa.selenium.grid.data.Session;8import org.openqa.selenium.grid.data.SessionId;9import org.openqa.selenium.grid.data.SlotId;10import org.openqa.selenium.grid.data.Slot;11import org.openqa.selenium.grid.data.SlotMatch;12import org.openqa.selenium.grid.data.Distributor;13import org.openqa.selenium.grid.data.DefaultDistributor;14import org.openqa.selenium.grid.data.DefaultDistributorStatus;15import org.openqa.selenium.grid.node.Node;16import org.openqa.selenium.grid.node.DefaultNode;17import org.openqa.selenium.grid.node.local.LocalNode;18import org.openqa.selenium.grid.node.local.LocalNodeConfig;19import org.openqa.selenium.grid.node.local.LocalNodeFactory;20import org.openqa.selenium.grid.node.local.LocalNodeOptions;21import org.openqa.selenium.grid.node.local.LocalNodeStatus;22import org.openqa.selenium.grid.node.config.NodeOptions;23import org.openqa.selenium.grid.node.config.NodeConfig;24import org.openqa.selenium.grid.node.proxy.ProxyCdpClientFactory;25import org.openqa.selenium.grid.node.proxy.ProxyCdpClient;26import org.openqa.selenium.grid.node.proxy.ProxyCdpClientOptions;27import org.openqa.selenium.grid.node.proxy.ProxyCdpClientConfig;28import org.openqa.selenium.grid.node.proxy.ProxyCdpClientFactory;29import org.openqa.selenium.grid.node.proxy.ProxyCdpClient;30import org.openqa.selenium.grid.node.proxy.ProxyCdpClientOptions;31import org.openqa.selenium.grid.node.proxy.ProxyCdpClientConfig;32import org.openqa.selenium.grid.node.proxy.ProxyCdpClientFactory;33import org.openqa.selenium.grid.node.proxy.ProxyCdpClient;34import org.openqa.selenium.grid.node.proxy.ProxyCdpClientOptions;35import org.openqa.selenium.grid.node.proxy.ProxyCdpClientConfig;36import org.openqa.selenium.grid.node.proxy.ProxyCdpClientFactory;37import org.openqa.selenium.grid.node.proxy.ProxyCdpClient;38import org.openqa.selenium.grid.node.proxy.ProxyCdpClientOptions;39import org.openqa.selenium.grid.node.proxy.ProxyCdpClientConfig;40import org.openqa.selenium.grid.node.proxy.ProxyCdpClientFactory;41import org.openqa.selenium.grid.node.proxy.ProxyCdpClient;42import org.openqa.selenium.grid.node.proxy.ProxyCdpClientOptions;43import org.openqa.selenium.grid.node.proxy.ProxyCdpClientConfig;44import org.openqa.selenium.grid.node.proxy.ProxyCdpClientFactory;45import org.openqa.selenium.grid.node.proxy.ProxyCdpClient;

Full Screen

Full Screen

CreateSessionResponse

Using AI Code Generation

copy

Full Screen

1CreateSessionResponse response = new CreateSessionResponse(session.getId(), session.getCapabilities());2CreateSessionResponse response = new CreateSessionResponse(session.getId(), session.getCapabilities());3CreateSessionResponse response = new CreateSessionResponse(session.getId(), session.getCapabilities());4CreateSessionResponse response = new CreateSessionResponse(session.getId(), session.getCapabilities());5CreateSessionResponse response = new CreateSessionResponse(session.getId(), session.getCapabilities());6CreateSessionResponse response = new CreateSessionResponse(session.getId(), session.getCapabilities());7CreateSessionResponse response = new CreateSessionResponse(session.getId(), session.getCapabilities());8CreateSessionResponse response = new CreateSessionResponse(session.getId(), session.getCapabilities());9CreateSessionResponse response = new CreateSessionResponse(session.getId(), session.getCapabilities());10CreateSessionResponse response = new CreateSessionResponse(session.getId(), session.getCapabilities());11CreateSessionResponse response = new CreateSessionResponse(session.getId(), session.getCapabilities());12CreateSessionResponse response = new CreateSessionResponse(session.getId(), session.getCapabilities());13CreateSessionResponse response = new CreateSessionResponse(session

Full Screen

Full Screen

CreateSessionResponse

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.grid.data.CreateSessionResponse;2import org.openqa.selenium.grid.data.Session;3public class SessionResponse {4 public static void main(String[] args) {5 CreateSessionResponse response = new CreateSessionResponse(session);6 System.out.println(response.getSessionId());7 System.out.println(response.getDownstreamDialects());8 System.out.println(response.getDownstreamStatus());9 System.out.println(response.getUpstreamStatus());10 System.out.println(response.getUpstreamUri());11 }12}

Full Screen

Full Screen

CreateSessionResponse

Using AI Code Generation

copy

Full Screen

1CreateSessionResponse response = new CreateSessionResponse(session.getId(),2session.getUri(),3ImmutableMap.of("browserName", "firefox"));4return new HttpResponse()5.setStatusCode(200)6.setContent(new StringContent(response.toJson()));7}

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 methods in CreateSessionResponse

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful