How to use toString method of org.openqa.selenium.grid.data.CreateSessionRequest class

Best Selenium code snippet using org.openqa.selenium.grid.data.CreateSessionRequest.toString

Source:LocalNode.java Github

copy

Full Screen

...232 return this.gridUri;233 }234 @ManagedAttribute(name = "NodeId")235 public String getNodeId() {236 return getId().toString();237 }238 @Override239 public boolean isSupporting(Capabilities capabilities) {240 return factories.parallelStream().anyMatch(factory -> factory.test(capabilities));241 }242 @Override243 public Either<WebDriverException, CreateSessionResponse> newSession(CreateSessionRequest sessionRequest) {244 Require.nonNull("Session request", sessionRequest);245 try (Span span = tracer.getCurrentContext().createSpan("node.new_session")) {246 Map<String, EventAttributeValue> attributeMap = new HashMap<>();247 attributeMap248 .put(AttributeKey.LOGGER_CLASS.getKey(), EventAttribute.setValue(getClass().getName()));249 attributeMap.put("session.request.capabilities",250 EventAttribute.setValue(sessionRequest.getDesiredCapabilities().toString()));251 attributeMap.put("session.request.downstreamdialect",252 EventAttribute.setValue(sessionRequest.getDownstreamDialects().toString()));253 int currentSessionCount = getCurrentSessionCount();254 span.setAttribute("current.session.count", currentSessionCount);255 attributeMap.put("current.session.count", EventAttribute.setValue(currentSessionCount));256 if (getCurrentSessionCount() >= maxSessionCount) {257 span.setAttribute("error", true);258 span.setStatus(Status.RESOURCE_EXHAUSTED);259 attributeMap.put("max.session.count", EventAttribute.setValue(maxSessionCount));260 span.addEvent("Max session count reached", attributeMap);261 return Either.left(new RetrySessionRequestException("Max session count reached."));262 }263 if (isDraining()) {264 span.setStatus(Status.UNAVAILABLE.withDescription("The node is draining. Cannot accept new sessions."));265 return Either.left(266 new RetrySessionRequestException("The node is draining. Cannot accept new sessions."));267 }268 // Identify possible slots to use as quickly as possible to enable concurrent session starting269 SessionSlot slotToUse = null;270 synchronized (factories) {271 for (SessionSlot factory : factories) {272 if (!factory.isAvailable() || !factory.test(sessionRequest.getDesiredCapabilities())) {273 continue;274 }275 factory.reserve();276 slotToUse = factory;277 break;278 }279 }280 if (slotToUse == null) {281 span.setAttribute("error", true);282 span.setStatus(Status.NOT_FOUND);283 span.addEvent("No slot matched the requested capabilities. ", attributeMap);284 return Either.left(285 new RetrySessionRequestException("No slot matched the requested capabilities."));286 }287 Either<WebDriverException, ActiveSession> possibleSession = slotToUse.apply(sessionRequest);288 if (possibleSession.isRight()) {289 ActiveSession session = possibleSession.right();290 currentSessions.put(session.getId(), slotToUse);291 SessionId sessionId = session.getId();292 Capabilities caps = session.getCapabilities();293 SESSION_ID.accept(span, sessionId);294 CAPABILITIES.accept(span, caps);295 String downstream = session.getDownstreamDialect().toString();296 String upstream = session.getUpstreamDialect().toString();297 String sessionUri = session.getUri().toString();298 span.setAttribute(AttributeKey.DOWNSTREAM_DIALECT.getKey(), downstream);299 span.setAttribute(AttributeKey.UPSTREAM_DIALECT.getKey(), upstream);300 span.setAttribute(AttributeKey.SESSION_URI.getKey(), sessionUri);301 // The session we return has to look like it came from the node, since we might be dealing302 // with a webdriver implementation that only accepts connections from localhost303 Session externalSession = createExternalSession(304 session,305 externalUri,306 slotToUse.isSupportingCdp() || caps.getCapability("se:cdp") != null);307 return Either.right(new CreateSessionResponse(308 externalSession,309 getEncoder(session.getDownstreamDialect()).apply(externalSession)));310 } else {311 slotToUse.release();312 span.setAttribute("error", true);313 span.addEvent("Unable to create session with the driver", attributeMap);314 return Either.left(possibleSession.left());315 }316 }317 }318 @Override319 public boolean isSessionOwner(SessionId id) {320 Require.nonNull("Session ID", id);321 return currentSessions.getIfPresent(id) != null;322 }323 @Override324 public Session getSession(SessionId id) throws NoSuchSessionException {325 Require.nonNull("Session ID", id);326 SessionSlot slot = currentSessions.getIfPresent(id);327 if (slot == null) {328 throw new NoSuchSessionException("Cannot find session with id: " + id);329 }330 return createExternalSession(slot.getSession(), externalUri, slot.isSupportingCdp());331 }332 @Override333 public TemporaryFilesystem getTemporaryFilesystem(SessionId id) throws IOException {334 try {335 return tempFileSystems.get(id, () -> TemporaryFilesystem.getTmpFsBasedOn(336 TemporaryFilesystem.getDefaultTmpFS().createTempDir("session", id.toString())));337 } catch (ExecutionException e) {338 throw new IOException(e);339 }340 }341 @Override342 public HttpResponse executeWebDriverCommand(HttpRequest req) {343 // True enough to be good enough344 SessionId id = getSessionId(req.getUri()).map(SessionId::new)345 .orElseThrow(() -> new NoSuchSessionException("Cannot find session: " + req));346 SessionSlot slot = currentSessions.getIfPresent(id);347 if (slot == null) {348 throw new NoSuchSessionException("Cannot find session with id: " + id);349 }350 HttpResponse toReturn = slot.execute(req);...

Full Screen

Full Screen

Source:GraphqlHandlerTest.java Github

copy

Full Screen

...132 assertThat(topLevel).isEqualTo(133 singletonMap(134 "data", singletonMap(135 "grid", singletonMap(136 "uri", publicUri.toString()))));137 }138 @Test139 public void shouldBeAbleToGetGridVersion() {140 GraphqlHandler handler = new GraphqlHandler(tracer, distributor, queue, publicUri, version);141 Map<String, Object> topLevel = executeQuery(handler, "{ grid { version } }");142 assertThat(topLevel).isEqualTo(143 singletonMap(144 "data", singletonMap(145 "grid", singletonMap(146 "version", version))));147 }148 private void continueOnceAddedToQueue(SessionRequest request) {149 // Add to the queue in the background150 CountDownLatch latch = new CountDownLatch(1);151 events.addListener(NewSessionRequestEvent.listener(id -> latch.countDown()));152 new Thread(() -> {153 queue.addToQueue(request);154 }).start();155 try {156 assertThat(latch.await(5, SECONDS)).isTrue();157 } catch (InterruptedException e) {158 Thread.currentThread().interrupt();159 throw new RuntimeException(e);160 }161 }162 @Test163 public void shouldBeAbleToGetSessionQueueSize() throws URISyntaxException {164 SessionRequest request = new SessionRequest(165 new RequestId(UUID.randomUUID()),166 Instant.now(),167 Set.of(W3C),168 Set.of(caps),169 Map.of(),170 Map.of());171 continueOnceAddedToQueue(request);172 GraphqlHandler handler = new GraphqlHandler(tracer, distributor, queue, publicUri, version);173 Map<String, Object> topLevel = executeQuery(handler, "{ grid { sessionQueueSize } }");174 assertThat(topLevel).isEqualTo(175 singletonMap(176 "data", singletonMap(177 "grid", singletonMap(178 "sessionQueueSize", 1L))));179 }180 @Test181 public void shouldBeAbleToGetSessionQueueRequests() throws URISyntaxException {182 SessionRequest request = new SessionRequest(183 new RequestId(UUID.randomUUID()),184 Instant.now(),185 Set.of(W3C),186 Set.of(caps),187 Map.of(),188 Map.of());189 continueOnceAddedToQueue(request);190 GraphqlHandler handler = new GraphqlHandler(tracer, distributor, queue, publicUri, version);191 Map<String, Object> topLevel = executeQuery(handler,192 "{ sessionsInfo { sessionQueueRequests } }");193 assertThat(topLevel).isEqualTo(194 singletonMap(195 "data", singletonMap(196 "sessionsInfo", singletonMap(197 "sessionQueueRequests", singletonList(JSON.toJson(caps))))));198 }199 @Test200 public void shouldBeReturnAnEmptyListIfQueueIsEmpty() {201 GraphqlHandler handler = new GraphqlHandler(tracer, distributor, queue, publicUri, version);202 Map<String, Object> topLevel = executeQuery(handler,203 "{ sessionsInfo { sessionQueueRequests } }");204 assertThat(topLevel).isEqualTo(205 singletonMap(206 "data", singletonMap(207 "sessionsInfo", singletonMap(208 "sessionQueueRequests", Collections.emptyList()))));209 }210 @Test211 public void shouldReturnAnEmptyListForNodesIfNoneAreRegistered() {212 GraphqlHandler handler = new GraphqlHandler(tracer, distributor, queue, publicUri, version);213 Map<String, Object> topLevel = executeQuery(handler, "{ nodesInfo { nodes { uri } } }");214 assertThat(topLevel).describedAs(topLevel.toString()).isEqualTo(215 singletonMap(216 "data", singletonMap(217 "nodesInfo", singletonMap(218 "nodes", Collections.emptyList()))));219 }220 @Test221 public void shouldBeAbleToGetUrlsOfAllNodes() throws URISyntaxException {222 Capabilities stereotype = new ImmutableCapabilities("cheese", "stilton");223 String nodeUri = "http://localhost:5556";224 Node node = LocalNode.builder(tracer, events, new URI(nodeUri), publicUri, registrationSecret)225 .add(stereotype, new SessionFactory() {226 @Override227 public Either<WebDriverException, ActiveSession> apply(228 CreateSessionRequest createSessionRequest) {229 return Either.left(new SessionNotCreatedException("Factory for testing"));230 }231 @Override232 public boolean test(Capabilities capabilities) {233 return false;234 }235 })236 .build();237 distributor.add(node);238 wait.until(obj -> distributor.getStatus().hasCapacity());239 GraphqlHandler handler = new GraphqlHandler(tracer, distributor, queue, publicUri, version);240 Map<String, Object> topLevel = executeQuery(handler, "{ nodesInfo { nodes { uri } } }");241 assertThat(topLevel).describedAs(topLevel.toString()).isEqualTo(242 singletonMap(243 "data", singletonMap(244 "nodesInfo", singletonMap(245 "nodes", singletonList(singletonMap("uri", nodeUri))))));246 }247 @Test248 public void shouldBeAbleToGetSessionCount() throws URISyntaxException {249 String nodeUrl = "http://localhost:5556";250 URI nodeUri = new URI(nodeUrl);251 Node node = LocalNode.builder(tracer, events, nodeUri, publicUri, registrationSecret)252 .add(caps, new TestSessionFactory((id, caps) -> new org.openqa.selenium.grid.data.Session(253 id,254 nodeUri,255 stereotype,256 caps,257 Instant.now()))).build();258 distributor.add(node);259 wait.until(obj -> distributor.getStatus().hasCapacity());260 Either<SessionNotCreatedException, CreateSessionResponse> response = distributor.newSession(sessionRequest);261 if (response.isRight()) {262 Session session = response.right().getSession();263 assertThat(session).isNotNull();264 GraphqlHandler handler = new GraphqlHandler(tracer, distributor, queue, publicUri, version);265 Map<String, Object> topLevel = executeQuery(handler,266 "{ grid { sessionCount } }");267 assertThat(topLevel).isEqualTo(268 singletonMap(269 "data", singletonMap(270 "grid", singletonMap(271 "sessionCount", 1L ))));272 } else {273 fail("Session creation failed", response.left());274 }275 }276 @Test277 public void shouldBeAbleToGetSessionInfo() throws URISyntaxException {278 String nodeUrl = "http://localhost:5556";279 URI nodeUri = new URI(nodeUrl);280 Node node = LocalNode.builder(tracer, events, nodeUri, publicUri, registrationSecret)281 .add(caps, new TestSessionFactory((id, caps) -> new org.openqa.selenium.grid.data.Session(282 id,283 nodeUri,284 stereotype,285 caps,286 Instant.now()))).build();287 distributor.add(node);288 wait.until(obj -> distributor.getStatus().hasCapacity());289 Either<SessionNotCreatedException, CreateSessionResponse> response = distributor.newSession(sessionRequest);290 if (response.isRight()) {291 Session session = response.right().getSession();292 assertThat(session).isNotNull();293 String sessionId = session.getId().toString();294 Set<Slot> slots = distributor.getStatus().getNodes().stream().findFirst().get().getSlots();295 Slot slot = slots.stream().findFirst().get();296 org.openqa.selenium.grid.graphql.Session graphqlSession =297 new org.openqa.selenium.grid.graphql.Session(298 sessionId,299 session.getCapabilities(),300 session.getStartTime(),301 session.getUri(),302 node.getId().toString(),303 node.getUri(),304 slot);305 String query = String.format(306 "{ session (id: \"%s\") { id, capabilities, startTime, uri } }", sessionId);307 GraphqlHandler handler = new GraphqlHandler(tracer, distributor, queue, publicUri, version);308 Map<String, Object> result = executeQuery(handler, query);309 assertThat(result).describedAs(result.toString()).isEqualTo(310 singletonMap(311 "data", singletonMap(312 "session", ImmutableMap.of(313 "id", sessionId,314 "capabilities", graphqlSession.getCapabilities(),315 "startTime", graphqlSession.getStartTime(),316 "uri", graphqlSession.getUri().toString()))));317 } else {318 fail("Session creation failed", response.left());319 }320 }321 @Test322 public void shouldBeAbleToGetNodeInfoForSession() throws URISyntaxException {323 String nodeUrl = "http://localhost:5556";324 URI nodeUri = new URI(nodeUrl);325 Node node = LocalNode.builder(tracer, events, nodeUri, publicUri, registrationSecret)326 .add(caps, new TestSessionFactory((id, caps) -> new org.openqa.selenium.grid.data.Session(327 id,328 nodeUri,329 stereotype,330 caps,331 Instant.now()))).build();332 distributor.add(node);333 wait.until(obj -> distributor.getStatus().hasCapacity());334 Either<SessionNotCreatedException, CreateSessionResponse> response = distributor.newSession(sessionRequest);335 if (response.isRight()) {336 Session session = response.right().getSession();337 assertThat(session).isNotNull();338 String sessionId = session.getId().toString();339 Set<Slot> slots = distributor.getStatus().getNodes().stream().findFirst().get().getSlots();340 Slot slot = slots.stream().findFirst().get();341 org.openqa.selenium.grid.graphql.Session graphqlSession =342 new org.openqa.selenium.grid.graphql.Session(343 sessionId,344 session.getCapabilities(),345 session.getStartTime(),346 session.getUri(),347 node.getId().toString(),348 node.getUri(),349 slot);350 String query = String.format("{ session (id: \"%s\") { nodeId, nodeUri } }", sessionId);351 GraphqlHandler handler = new GraphqlHandler(tracer, distributor, queue, publicUri, version);352 Map<String, Object> result = executeQuery(handler, query);353 assertThat(result).describedAs(result.toString()).isEqualTo(354 singletonMap(355 "data", singletonMap(356 "session", ImmutableMap.of(357 "nodeId", graphqlSession.getNodeId(),358 "nodeUri", graphqlSession.getNodeUri().toString()))));359 } else {360 fail("Session creation failed", response.left());361 }362 }363 @Test364 public void shouldBeAbleToGetSlotInfoForSession() throws URISyntaxException {365 String nodeUrl = "http://localhost:5556";366 URI nodeUri = new URI(nodeUrl);367 Node node = LocalNode.builder(tracer, events, nodeUri, publicUri, registrationSecret)368 .add(caps, new TestSessionFactory((id, caps) -> new org.openqa.selenium.grid.data.Session(369 id,370 nodeUri,371 stereotype,372 caps,373 Instant.now()))).build();374 distributor.add(node);375 wait.until(obj -> distributor.getStatus().hasCapacity());376 Either<SessionNotCreatedException, CreateSessionResponse> response = distributor.newSession(sessionRequest);377 if (response.isRight()) {378 Session session = response.right().getSession();379 assertThat(session).isNotNull();380 String sessionId = session.getId().toString();381 Set<Slot> slots = distributor.getStatus().getNodes().stream().findFirst().get().getSlots();382 Slot slot = slots.stream().findFirst().get();383 org.openqa.selenium.grid.graphql.Session graphqlSession =384 new org.openqa.selenium.grid.graphql.Session(385 sessionId,386 session.getCapabilities(),387 session.getStartTime(),388 session.getUri(),389 node.getId().toString(),390 node.getUri(),391 slot);392 org.openqa.selenium.grid.graphql.Slot graphqlSlot = graphqlSession.getSlot();393 String query = String.format(394 "{ session (id: \"%s\") { slot { id, stereotype, lastStarted } } }", sessionId);395 GraphqlHandler handler = new GraphqlHandler(tracer, distributor, queue, publicUri, version);396 Map<String, Object> result = executeQuery(handler, query);397 assertThat(result).describedAs(result.toString()).isEqualTo(398 singletonMap(399 "data", singletonMap(400 "session", singletonMap(401 "slot", ImmutableMap.of(402 "id", graphqlSlot.getId(),403 "stereotype", graphqlSlot.getStereotype(),404 "lastStarted", graphqlSlot.getLastStarted())))));405 } else {406 fail("Session creation failed", response.left());407 }408 }409 @Test410 public void shouldBeAbleToGetSessionDuration() throws URISyntaxException {411 String nodeUrl = "http://localhost:5556";412 URI nodeUri = new URI(nodeUrl);413 Node node = LocalNode.builder(tracer, events, nodeUri, publicUri, registrationSecret)414 .add(caps, new TestSessionFactory((id, caps) -> new org.openqa.selenium.grid.data.Session(415 id,416 nodeUri,417 stereotype,418 caps,419 Instant.now()))).build();420 distributor.add(node);421 wait.until(obj -> distributor.getStatus().hasCapacity());422 Either<SessionNotCreatedException, CreateSessionResponse> response = distributor.newSession(sessionRequest);423 if (response.isRight()) {424 Session session = response.right().getSession();425 assertThat(session).isNotNull();426 String sessionId = session.getId().toString();427 String query = String.format("{ session (id: \"%s\") { sessionDurationMillis } }", sessionId);428 GraphqlHandler handler = new GraphqlHandler(tracer, distributor, queue, publicUri, version);429 Map<String, Object> result = executeQuery(handler, query);430 assertThat(result)431 .containsOnlyKeys("data")432 .extracting("data").asInstanceOf(MAP).containsOnlyKeys("session")433 .extracting("session").asInstanceOf(MAP).containsOnlyKeys("sessionDurationMillis");434 } else {435 fail("Session creation failed", response.left());436 }437 }438 @Test439 public void shouldThrowExceptionWhenSessionNotFound() throws URISyntaxException {440 String nodeUrl = "http://localhost:5556";441 URI nodeUri = new URI(nodeUrl);442 Node node = LocalNode.builder(tracer, events, nodeUri, publicUri, registrationSecret)443 .add(caps, new TestSessionFactory((id, caps) -> new org.openqa.selenium.grid.data.Session(444 id,445 nodeUri,446 stereotype,447 caps,448 Instant.now()))).build();449 distributor.add(node);450 wait.until(obj -> distributor.getStatus().hasCapacity());451 String randomSessionId = UUID.randomUUID().toString();452 String query = "{ session (id: \"" + randomSessionId + "\") { sessionDurationMillis } }";453 GraphqlHandler handler = new GraphqlHandler(tracer, distributor, queue, publicUri, version);454 Map<String, Object> result = executeQuery(handler, query);455 assertThat(result)456 .containsEntry("data", null)457 .containsKey("errors")458 .extracting("errors").asInstanceOf(LIST).isNotEmpty()459 .element(0).asInstanceOf(MAP).containsKey("extensions")460 .extracting("extensions").asInstanceOf(MAP).containsKey("sessionId")461 .extracting("sessionId").isEqualTo(randomSessionId);462 }463 @Test464 public void shouldThrowExceptionWhenSessionIsEmpty() throws URISyntaxException {465 String nodeUrl = "http://localhost:5556";...

Full Screen

Full Screen

Source:Distributor.java Github

copy

Full Screen

...160 Objects.requireNonNull(payload, "Requests to process must be set.");161 attributeMap.put(AttributeKey.LOGGER_CLASS.getKey(),162 EventAttribute.setValue(getClass().getName()));163 Iterator<Capabilities> iterator = payload.stream().iterator();164 attributeMap.put("request.payload", EventAttribute.setValue(payload.toString()));165 if (!iterator.hasNext()) {166 SessionNotCreatedException exception = new SessionNotCreatedException("No capabilities found");167 EXCEPTION.accept(attributeMap, exception);168 attributeMap.put(AttributeKey.EXCEPTION_MESSAGE.getKey(),169 EventAttribute.setValue("Unable to create session. No capabilities found: "170 + exception.getMessage()));171 span.addEvent(AttributeKey.EXCEPTION_EVENT.getKey(), attributeMap);172 throw exception;173 }174 Optional<Supplier<CreateSessionResponse>> selected;175 CreateSessionRequest firstRequest = new CreateSessionRequest(176 payload.getDownstreamDialects(),177 iterator.next(),178 ImmutableMap.of("span", span));179 Lock writeLock = this.lock.writeLock();180 writeLock.lock();181 try {182 Set<NodeStatus> model = ImmutableSet.copyOf(getAvailableNodes());183 // Find a host that supports the capabilities present in the new session184 Set<SlotId> slotIds = slotSelector.selectSlot(firstRequest.getCapabilities(), model);185 if (!slotIds.isEmpty()) {186 selected = Optional.of(reserve(slotIds.iterator().next(), firstRequest));187 } else {188 selected = Optional.empty();189 }190 } finally {191 writeLock.unlock();192 }193 CreateSessionResponse sessionResponse = selected194 .orElseThrow(195 () -> {196 span.setAttribute("error", true);197 SessionNotCreatedException198 exception =199 new SessionNotCreatedException(200 "Unable to find provider for session: " + payload.stream()201 .map(Capabilities::toString).collect(Collectors.joining(", ")));202 EXCEPTION.accept(attributeMap, exception);203 attributeMap.put(AttributeKey.EXCEPTION_MESSAGE.getKey(),204 EventAttribute.setValue(205 "Unable to find provider for session: "206 + exception.getMessage()));207 span.addEvent(AttributeKey.EXCEPTION_EVENT.getKey(), attributeMap);208 return exception;209 })210 .get();211 sessions.add(sessionResponse.getSession());212 SessionId sessionId = sessionResponse.getSession().getId();213 Capabilities caps = sessionResponse.getSession().getCapabilities();214 String sessionUri = sessionResponse.getSession().getUri().toString();215 SESSION_ID.accept(span, sessionId);216 CAPABILITIES.accept(span, caps);217 SESSION_ID_EVENT.accept(attributeMap, sessionId);218 CAPABILITIES_EVENT.accept(attributeMap, caps);219 span.setAttribute(AttributeKey.SESSION_URI.getKey(), sessionUri);220 attributeMap.put(AttributeKey.SESSION_URI.getKey(), EventAttribute.setValue(sessionUri));221 span.addEvent("Session created by the distributor", attributeMap);222 return sessionResponse;223 } catch (SessionNotCreatedException e) {224 span.setAttribute("error", true);225 span.setStatus(Status.ABORTED);226 EXCEPTION.accept(attributeMap, e);227 attributeMap.put(AttributeKey.EXCEPTION_MESSAGE.getKey(),228 EventAttribute.setValue("Unable to create session: " + e.getMessage()));...

Full Screen

Full Screen

Source:LocalDistributor.java Github

copy

Full Screen

...122 CreateSessionResponse sessionResponse = selected123 .orElseThrow(124 () -> new SessionNotCreatedException(125 "Unable to find provider for session: " + payload.stream()126 .map(Capabilities::toString)127 .collect(Collectors.joining(", "))))128 .get();129 sessions.add(sessionResponse.getSession());130 return sessionResponse;131 } catch (IOException e) {132 throw new SessionNotCreatedException(e.getMessage(), e);133 }134 }135 private void refresh(NodeStatus status) {136 Objects.requireNonNull(status);137 // Iterate over the available nodes to find a match.138 Lock writeLock = lock.writeLock();139 writeLock.lock();140 try {141 Optional<Host> existing = hosts.stream()142 .filter(host -> host.getId().equals(status.getNodeId()))143 .findFirst();144 if (existing.isPresent()) {145 // Modify the state146 existing.get().update(status);147 } else {148 // No match made. Add a new host.149 Node node = new RemoteNode(150 tracer,151 clientFactory,152 status.getNodeId(),153 status.getUri(),154 status.getStereotypes().keySet());155 add(node, status);156 }157 } finally {158 writeLock.unlock();159 }160 }161 @Override162 public LocalDistributor add(Node node) {163 return add(node, node.getStatus());164 }165 private LocalDistributor add(Node node, NodeStatus status) {166 StringBuilder sb = new StringBuilder();167 Lock writeLock = this.lock.writeLock();168 writeLock.lock();169 try (Span span = tracer.createSpan("distributor.add", tracer.getActiveSpan());170 JsonOutput out = JSON.newOutput(sb)) {171 out.setPrettyPrint(false).write(node);172 span.addTag("node", sb.toString());173 Host host = new Host(bus, node);174 host.update(status);175 hosts.add(host);176 LOG.info(String.format("Added node %s.", node.getId()));177 host.runHealthCheck();178 Runnable runnable = host::runHealthCheck;179 Collection<Runnable> nodeRunnables = allChecks.getOrDefault(node.getId(), new ArrayList<>());180 nodeRunnables.add(runnable);181 allChecks.put(node.getId(), nodeRunnables);182 hostChecker.submit(runnable, Duration.ofMinutes(5), Duration.ofSeconds(30));183 } finally {184 writeLock.unlock();185 }186 return this;...

Full Screen

Full Screen

Source:CreateSessionRequest.java Github

copy

Full Screen

...69 }70 input.endObject();71 return new CreateSessionRequest(downstreamDialects, capabilities, metadata);72 }73 public String toString() {74 return String.format("<CreateSessionRequest with %s>", capabilities);75 }76}...

Full Screen

Full Screen

toString

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.grid.data.CreateSessionRequest;2public class CreateSessionRequestToString {3 public static void main(String[] args) {4 CreateSessionRequest createSessionRequest = new CreateSessionRequest(5 new ImmutableCapabilities(), ImmutableMap.of("browserName", "chrome"));6 System.out.println(createSessionRequest.toString());7 }8}

Full Screen

Full Screen

toString

Using AI Code Generation

copy

Full Screen

1package com.example;2import java.io.IOException;3import java.net.URL;4import org.openqa.selenium.grid.data.CreateSessionRequest;5import org.openqa.selenium.remote.http.HttpRequest;6import org.openqa.selenium.remote.http.HttpResponse;7import org.openqa.selenium.remote.http.JsonHttpCommandCodec;8import org.openqa.selenium.remote.http.JsonHttpResponseCodec;9import org.openqa.selenium.remote.tracing.DefaultTestTracer;10import org.openqa.selenium.remote.tracing.Tracer;11public class CreateSessionRequestToString {12 public static void main(String[] args) throws IOException {13 HttpRequest request = new HttpRequest("POST", url);14 request.setContent("{\"capabilities\": {\"alwaysMatch\": {\"browserName\": \"chrome\", \"platformName\": \"linux\"}}}".getBytes());15 Tracer tracer = DefaultTestTracer.createTracer();16 JsonHttpCommandCodec codec = new JsonHttpCommandCodec();17 JsonHttpResponseCodec responseCodec = new JsonHttpResponseCodec();18 CreateSessionRequest sessionRequest = codec.decode(request, CreateSessionRequest.class);19 System.out.println(sessionRequest.toString());20 HttpResponse response = responseCodec.encode(sessionRequest);21 System.out.println(response.toString());22 }23}24CreateSessionRequest{capabilities=org.openqa.selenium.grid.data.CapabilitiesRequest@7c6f1f3a}25HttpResponse{statusCode=200, headers={Content-Type=[application/json; charset=utf-8], Content-Length=[0]}}

Full Screen

Full Screen

toString

Using AI Code Generation

copy

Full Screen

1public String toString() {2 return String.format(3 "CreateSessionRequest {capabilities: %s, session: %s, downstreamDialects: %s}",4 capabilities, session, downstreamDialects);5}6public String toString() {7 return String.format(8 "NewSessionRequest {capabilities: %s, downstreamDialects: %s}",9 capabilities, downstreamDialects);10}11public String toString() {12 return String.format(13 "Session {id: %s, capabilities: %s, source: %s}",14 id, capabilities, source);15}16public String toString() {17 return String.format(18 "SessionInfo {id: %s, capabilities: %s, source: %s, uri: %s}",19 id, capabilities, source, uri);20}21public String toString() {22 return String.format(23 "SessionRequest {id: %s, capabilities: %s, downstreamDialects: %s}",24 id, capabilities, downstreamDialects);25}26public String toString() {27 return String.format(28 "SessionRequest {id: %s, capabilities: %s, downstreamDialects: %s}",29 id, capabilities, downstreamDialects);30}31public String toString() {32 return String.format(33 "SessionResponse {value: %s, downstreamDialects: %s}",34 value, downstreamDialects);35}36public String toString() {37 return String.format(38 "SessionStatus {state: %s, message: %s}",39 state, message);40}

Full Screen

Full Screen

toString

Using AI Code Generation

copy

Full Screen

1CreateSessionRequest request = new CreateSessionRequest(2 Map.of("browserName", "chrome"),3 ImmutableCapabilities.fromCapabilities(Capabilities.chrome()),4 ImmutableMap.of("name", "Test"));5System.out.println(request.toString());6CreateSessionRequest request = new CreateSessionRequest(7 Map.of("browserName", "chrome"),8 ImmutableCapabilities.fromCapabilities(Capabilities.chrome()),9 ImmutableMap.of("name", "Test"));10System.out.println(request.toString());11CreateSessionRequest request = new CreateSessionRequest(12 Map.of("browserName", "chrome"),13 ImmutableCapabilities.fromCapabilities(Capabilities.chrome()),14 ImmutableMap.of("name", "Test"));15System.out.println(request.toString());16CreateSessionRequest request = new CreateSessionRequest(17 Map.of("browserName", "chrome"),18 ImmutableCapabilities.fromCapabilities(Capabilities.chrome()),19 ImmutableMap.of("name", "Test"));20System.out.println(request.toString());21CreateSessionRequest request = new CreateSessionRequest(22 Map.of("browserName", "chrome"),23 ImmutableCapabilities.fromCapabilities(Capabilities.chrome()),24 ImmutableMap.of("name", "Test"));25System.out.println(request.toString());26CreateSessionRequest request = new CreateSessionRequest(27 Map.of("browserName", "chrome"),28 ImmutableCapabilities.fromCapabilities(Capabilities.chrome()),29 ImmutableMap.of("name", "Test"));30System.out.println(request.toString());31CreateSessionRequest request = new CreateSessionRequest(32 Map.of("browserName", "chrome"),33 ImmutableCapabilities.fromCapabilities(Capabilities.chrome()),34 ImmutableMap.of("name", "Test"));35System.out.println(request.toString());36CreateSessionRequest request = new CreateSessionRequest(37 Map.of("browserName", "chrome"),38 ImmutableCapabilities.fromCapabilities(Capabilities.chrome()),39 ImmutableMap.of("name

Full Screen

Full Screen

toString

Using AI Code Generation

copy

Full Screen

1System.out.println(request.toString());2System.out.println(request.getBody());3System.out.println(request.getContent());4System.out.println(request.getInputStream());5System.out.println(request.getReader());6System.out.println(request.getContentAsString());7System.out.println(request.getContentAsStringOrThrow());8System.out.println(request.getContentAsString(StandardCharsets.UTF_8));9System.out.println(request.getContentAsStringOrThrow(StandardCharsets.UTF_8));10System.out.println(request.getContent().toString());11System.out.println(request.getContent().toString(StandardCharsets.UTF_8));12System.out.println(request.getContent().asString());13System.out.println(request.getContent().asString(StandardCharsets.UTF_8));14System.out.println(request.getContent().asStringOrThrow());15System.out.println(request.getContent().asStringOrThrow(StandardCharsets.UTF_8));16System.out.println(request.getContent().readString());17System.out.println(request.getContent().readString(StandardCharsets.UTF_8));18System.out.println(request.getContent().readStringOrThrow());19System.out.println(request.getContent().readStringOrThrow(StandardCharsets.UTF_8));20System.out.println(request.getContent().readString(StandardCharsets.UTF_8));21System.out.println(request.getContent().readStringOrThrow());22System.out.println(request.getContent().readStringOrThrow(StandardCharsets.UTF_8));23System.out.println(request.getContent().read());24System.out.println(request.getContent().read(StandardCharsets.UTF_8));25System.out.println(request.getContent().readOrThrow());26System.out.println(request.getContent().readOrThrow(StandardCharsets

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 CreateSessionRequest

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful