How to use Node class of org.openqa.selenium.grid.graphql package

Best Selenium code snippet using org.openqa.selenium.grid.graphql.Node

Source:GraphqlHandlerTest.java Github

copy

Full Screen

...34import org.openqa.selenium.grid.distributor.Distributor;35import org.openqa.selenium.grid.distributor.local.LocalDistributor;36import org.openqa.selenium.grid.distributor.selector.DefaultSlotSelector;37import org.openqa.selenium.grid.node.ActiveSession;38import org.openqa.selenium.grid.node.Node;39import org.openqa.selenium.grid.node.SessionFactory;40import org.openqa.selenium.grid.node.local.LocalNode;41import org.openqa.selenium.grid.security.Secret;42import org.openqa.selenium.grid.sessionmap.SessionMap;43import org.openqa.selenium.grid.sessionmap.local.LocalSessionMap;44import org.openqa.selenium.grid.sessionqueue.NewSessionQueue;45import org.openqa.selenium.grid.data.SessionRequest;46import org.openqa.selenium.grid.sessionqueue.local.LocalNewSessionQueue;47import org.openqa.selenium.grid.testing.TestSessionFactory;48import org.openqa.selenium.internal.Either;49import org.openqa.selenium.json.Json;50import org.openqa.selenium.remote.http.Contents;51import org.openqa.selenium.remote.http.HttpClient;52import org.openqa.selenium.remote.http.HttpHandler;53import org.openqa.selenium.remote.http.HttpRequest;54import org.openqa.selenium.remote.http.HttpResponse;55import org.openqa.selenium.remote.tracing.DefaultTestTracer;56import org.openqa.selenium.remote.tracing.Tracer;57import org.openqa.selenium.support.ui.FluentWait;58import org.openqa.selenium.support.ui.Wait;59import java.net.URI;60import java.net.URISyntaxException;61import java.time.Duration;62import java.time.Instant;63import java.util.Collections;64import java.util.Map;65import java.util.Set;66import java.util.UUID;67import java.util.concurrent.CountDownLatch;68import java.util.concurrent.atomic.AtomicInteger;69import static java.util.Collections.singletonList;70import static java.util.Collections.singletonMap;71import static java.util.concurrent.TimeUnit.SECONDS;72import static org.assertj.core.api.Assertions.assertThat;73import static org.assertj.core.api.Assertions.fail;74import static org.assertj.core.api.InstanceOfAssertFactories.LIST;75import static org.assertj.core.api.InstanceOfAssertFactories.MAP;76import static org.openqa.selenium.json.Json.MAP_TYPE;77import static org.openqa.selenium.remote.Dialect.OSS;78import static org.openqa.selenium.remote.Dialect.W3C;79import static org.openqa.selenium.remote.http.HttpMethod.GET;80public class GraphqlHandlerTest {81 private static final Json JSON = new Json();82 private final Secret registrationSecret = new Secret("stilton");83 private final URI publicUri = new URI("http://example.com/grid-o-matic");84 private final String version = "4.0.0";85 private final Wait<Object> wait = new FluentWait<>(new Object()).withTimeout(Duration.ofSeconds(5));86 private Distributor distributor;87 private NewSessionQueue queue;88 private Tracer tracer;89 private EventBus events;90 private ImmutableCapabilities caps;91 private ImmutableCapabilities stereotype;92 private SessionRequest sessionRequest;93 public GraphqlHandlerTest() throws URISyntaxException {94 }95 @Before96 public void setupGrid() {97 tracer = DefaultTestTracer.createTracer();98 events = new GuavaEventBus();99 HttpClient.Factory clientFactory = HttpClient.Factory.createDefault();100 SessionMap sessions = new LocalSessionMap(tracer, events);101 stereotype = new ImmutableCapabilities("browserName", "cheese");102 caps = new ImmutableCapabilities("browserName", "cheese");103 sessionRequest = new SessionRequest(104 new RequestId(UUID.randomUUID()),105 Instant.now(),106 Set.of(OSS, W3C),107 Set.of(caps),108 Map.of(),109 Map.of());110 queue = new LocalNewSessionQueue(111 tracer,112 events,113 new DefaultSlotMatcher(),114 Duration.ofSeconds(2),115 Duration.ofSeconds(2),116 registrationSecret);117 distributor = new LocalDistributor(118 tracer,119 events,120 clientFactory,121 sessions,122 queue,123 new DefaultSlotSelector(),124 registrationSecret,125 Duration.ofMinutes(5),126 false);127 }128 @Test129 public void shouldBeAbleToGetGridUri() {130 GraphqlHandler handler = new GraphqlHandler(tracer, distributor, queue, publicUri, version);131 Map<String, Object> topLevel = executeQuery(handler, "{ grid { uri } }");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";466 URI nodeUri = new URI(nodeUrl);467 Node node = LocalNode.builder(tracer, events, nodeUri, publicUri, registrationSecret)468 .add(caps, new TestSessionFactory((id, caps) -> new org.openqa.selenium.grid.data.Session(469 id,470 nodeUri,471 stereotype,472 caps,473 Instant.now()))).build();474 distributor.add(node);475 wait.until(obj -> distributor.getStatus().hasCapacity());476 String query = "{ session (id: \"\") { sessionDurationMillis } }";477 GraphqlHandler handler = new GraphqlHandler(tracer, distributor, queue, publicUri, version);478 Map<String, Object> result = executeQuery(handler, query);479 assertThat(result)480 .containsEntry("data", null)481 .containsKey("errors")...

Full Screen

Full Screen

Source:Grid.java Github

copy

Full Screen

...19import com.google.common.collect.ImmutableList;20import org.openqa.selenium.Capabilities;21import org.openqa.selenium.ImmutableCapabilities;22import org.openqa.selenium.grid.data.DistributorStatus;23import org.openqa.selenium.grid.data.NodeStatus;24import org.openqa.selenium.grid.data.SessionRequestCapability;25import org.openqa.selenium.grid.data.Slot;26import org.openqa.selenium.grid.distributor.Distributor;27import org.openqa.selenium.grid.sessionqueue.NewSessionQueue;28import org.openqa.selenium.internal.Require;29import org.openqa.selenium.json.Json;30import java.net.URI;31import java.util.ArrayList;32import java.util.Collection;33import java.util.HashMap;34import java.util.List;35import java.util.Map;36import java.util.Set;37import java.util.function.Supplier;38import java.util.stream.Collectors;39public class Grid {40 private static final Json JSON = new Json();41 private final URI uri;42 private final Supplier<DistributorStatus> distributorStatus;43 private final List<Set<Capabilities>> queueInfoList;44 private final String version;45 public Grid(46 Distributor distributor,47 NewSessionQueue newSessionQueue,48 URI uri,49 String version) {50 Require.nonNull("Distributor", distributor);51 this.uri = Require.nonNull("Grid's public URI", uri);52 NewSessionQueue sessionQueue = Require.nonNull("New session queue", newSessionQueue);53 this.queueInfoList = sessionQueue54 .getQueueContents()55 .stream()56 .map(SessionRequestCapability::getDesiredCapabilities)57 .collect(Collectors.toList());58 this.distributorStatus = Suppliers.memoize(distributor::getStatus);59 this.version = Require.nonNull("Grid's version", version);60 }61 public URI getUri() {62 return uri;63 }64 public String getVersion() {65 return version;66 }67 public List<Node> getNodes() {68 ImmutableList.Builder<Node> toReturn = ImmutableList.builder();69 for (NodeStatus status : distributorStatus.get().getNodes()) {70 Map<Capabilities, Integer> stereotypes = new HashMap<>();71 Map<org.openqa.selenium.grid.data.Session, Slot> sessions = new HashMap<>();72 for (Slot slot : status.getSlots()) {73 slot.getSession().ifPresent(session -> sessions.put(session, slot));74 int count = stereotypes.getOrDefault(slot.getStereotype(), 0);75 count++;76 stereotypes.put(slot.getStereotype(), count);77 }78 OsInfo osInfo = new OsInfo(79 status.getOsInfo().get("arch"),80 status.getOsInfo().get("name"),81 status.getOsInfo().get("version"));82 toReturn.add(new Node(83 status.getId(),84 status.getUri(),85 status.getAvailability(),86 status.getMaxSessionCount(),87 status.getSlots().size(),88 stereotypes,89 sessions,90 status.getVersion(),91 osInfo));92 }93 return toReturn.build();94 }95 public int getNodeCount() {96 return distributorStatus.get().getNodes().size();97 }98 public int getSessionCount() {99 return distributorStatus.get().getNodes().stream()100 .map(NodeStatus::getSlots)101 .flatMap(Collection::stream)102 .filter(slot -> slot.getSession().isPresent())103 .mapToInt(slot -> 1)104 .sum();105 }106 public int getTotalSlots() {107 return distributorStatus.get().getNodes().stream()108 .mapToInt(status -> status.getSlots().size())109 .sum();110 }111 public int getMaxSession() {112 return distributorStatus.get().getNodes().stream()113 .mapToInt(NodeStatus::getMaxSessionCount)114 .sum();115 }116 public int getSessionQueueSize() {117 return queueInfoList.size();118 }119 public List<String> getSessionQueueRequests() {120 // TODO: The Grid UI expects there to be a single capability per new session request, which is not correct121 return queueInfoList.stream()122 .map(set -> set.isEmpty() ? new ImmutableCapabilities() : set.iterator().next())123 .map(JSON::toJson)124 .collect(Collectors.toList());125 }126 public List<Session> getSessions() {127 List<Session> sessions = new ArrayList<>();128 for (NodeStatus status : distributorStatus.get().getNodes()) {129 for (Slot slot : status.getSlots()) {130 if (slot.getSession().isPresent()) {131 org.openqa.selenium.grid.data.Session session = slot.getSession().get();132 sessions.add(133 new org.openqa.selenium.grid.graphql.Session(134 session.getId().toString(),135 session.getCapabilities(),136 session.getStartTime(),137 session.getUri(),138 status.getId().toString(),139 status.getUri(),140 slot)141 );142 }...

Full Screen

Full Screen

Source:Node.java Github

copy

Full Screen

...17package org.openqa.selenium.grid.graphql;18import com.google.common.collect.ImmutableList;19import org.openqa.selenium.Capabilities;20import org.openqa.selenium.grid.data.Availability;21import org.openqa.selenium.grid.data.NodeId;22import org.openqa.selenium.grid.data.Session;23import org.openqa.selenium.grid.data.Slot;24import org.openqa.selenium.internal.Require;25import org.openqa.selenium.json.Json;26import java.net.URI;27import java.util.ArrayList;28import java.util.HashMap;29import java.util.List;30import java.util.Map;31public class Node {32 private static final Json JSON = new Json();33 private final NodeId id;34 private final URI uri;35 private final Availability status;36 private final int maxSession;37 private final Map<Capabilities, Integer> stereotypes;38 private final Map<Session, Slot> activeSessions;39 private final String version;40 private final OsInfo osInfo;41 private final int slotCount;42 public Node(NodeId id,43 URI uri,44 Availability status,45 int maxSession,46 int slotCount,47 Map<Capabilities, Integer> stereotypes,48 Map<Session, Slot> activeSessions,49 String version,50 OsInfo osInfo) {51 this.id = Require.nonNull("Node id", id);52 this.uri = Require.nonNull("Node uri", uri);53 this.status = status;54 this.maxSession = maxSession;55 this.slotCount = slotCount;56 this.stereotypes = Require.nonNull("Node stereotypes", stereotypes);57 this.activeSessions = Require.nonNull("Active sessions", activeSessions);58 this.version = Require.nonNull("Grid Node version", version);59 this.osInfo = Require.nonNull("Grid Node OS info", osInfo);60 }61 public List<org.openqa.selenium.grid.graphql.Session> getSessions() {62 return activeSessions.entrySet().stream()63 .map(this::createGraphqlSession)64 .collect(ImmutableList.toImmutableList());65 }66 public int getSlotCount() {67 return slotCount;68 }69 public int getSessionCount() {70 return activeSessions.size();71 }72 public NodeId getId() {73 return id;74 }75 public URI getUri() {76 return uri;77 }78 public int getMaxSession() {79 return maxSession;80 }81 public List<String> getActiveSessionIds() {82 return activeSessions.keySet().stream().map(session -> session.getId().toString())83 .collect(ImmutableList.toImmutableList());84 }85 public String getStereotypes() {86 List<Map<String, Object>> toReturn = new ArrayList<>();...

Full Screen

Full Screen

Source:SessionData.java Github

copy

Full Screen

...18import com.google.common.base.Suppliers;19import graphql.schema.DataFetcher;20import graphql.schema.DataFetchingEnvironment;21import org.openqa.selenium.grid.data.DistributorStatus;22import org.openqa.selenium.grid.data.NodeStatus;23import org.openqa.selenium.grid.data.Slot;24import org.openqa.selenium.grid.distributor.Distributor;25import org.openqa.selenium.internal.Require;26import java.util.Optional;27import java.util.Set;28import java.util.function.Supplier;29public class SessionData implements DataFetcher {30 private final Supplier<DistributorStatus> distributorStatus;31 public SessionData(Distributor distributor) {32 distributorStatus = Suppliers.memoize(Require.nonNull("Distributor", distributor)::getStatus);33 }34 @Override35 public Object get(DataFetchingEnvironment environment) {36 String sessionId = environment.getArgument("id");37 if (sessionId.isEmpty()) {38 throw new SessionNotFoundException("Session id is empty. A valid session id is required.");39 }40 Set<NodeStatus> nodeStatuses = distributorStatus.get().getNodes();41 SessionInSlot currentSession = findSession(sessionId, nodeStatuses);42 if (currentSession != null) {43 org.openqa.selenium.grid.data.Session session = currentSession.session;44 return new org.openqa.selenium.grid.graphql.Session(45 session.getId().toString(),46 session.getCapabilities(),47 session.getStartTime(),48 session.getUri(),49 currentSession.node.getId().toString(),50 currentSession.node.getUri(),51 currentSession.slot);52 } else {53 throw new SessionNotFoundException("No ongoing session found with the requested session id.",54 sessionId);55 }56 }57 private SessionInSlot findSession(String sessionId, Set<NodeStatus> nodeStatuses) {58 for (NodeStatus status : nodeStatuses) {59 for (Slot slot : status.getSlots()) {60 Optional<org.openqa.selenium.grid.data.Session> session = slot.getSession();61 if (session.isPresent() && sessionId.equals(session.get().getId().toString())) {62 return new SessionInSlot(session.get(), status, slot);63 }64 }65 }66 return null;67 }68 private static class SessionInSlot {69 private final org.openqa.selenium.grid.data.Session session;70 private final NodeStatus node;71 private final Slot slot;72 SessionInSlot(org.openqa.selenium.grid.data.Session session, NodeStatus node, Slot slot) {73 this.session = session;74 this.node = node;75 this.slot = slot;76 }77 }78}...

Full Screen

Full Screen

Source:Session.java Github

copy

Full Screen

...40 this.id = Require.nonNull("Session id", id);41 this.capabilities = Require.nonNull("Session capabilities", capabilities);42 this.startTime = Require.nonNull("Session Start time", startTime);43 this.uri = Require.nonNull("Session uri", uri);44 this.nodeId = Require.nonNull("Node id", nodeId);45 this.nodeUri = Require.nonNull("Node uri", nodeUri);46 this.slot = Require.nonNull("Slot", slot);47 }48 public String getId() {49 return id;50 }51 public String getCapabilities() {52 return JSON.toJson(capabilities);53 }54 public String getStartTime() {55 return DATE_TIME_FORMATTER.format(startTime);56 }57 public URI getUri() {58 return uri;59 }60 public String getNodeId() {61 return nodeId;62 }63 public URI getNodeUri() {64 return nodeUri;65 }66 public String getSessionDurationMillis() {67 long duration = Duration.between(startTime, Instant.now()).toMillis();68 return String.valueOf(duration);69 }70 public org.openqa.selenium.grid.graphql.Slot getSlot() {71 return new org.openqa.selenium.grid.graphql.Slot(72 slot.getId().getSlotId(),73 slot.getStereotype(),74 slot.getLastStarted());75 }76}...

Full Screen

Full Screen

Node

Using AI Code Generation

copy

Full Screen

1public class NodeStatus {2 private final NodeId id;3 private final Node.State state;4 private final Node.State previousState;5 private final Instant lastContact;6 public NodeStatus(Node node) {7 this.id = node.getId();8 this.state = node.getState();9 this.previousState = node.getPreviousState();10 this.lastContact = node.getLastContact();11 }12 public NodeId getId() {13 return id;14 }15 public Node.State getState() {16 return state;17 }18 public Node.State getPreviousState() {19 return previousState;20 }21 public Instant getLastContact() {22 return lastContact;23 }24 public boolean equals(Object o) {25 if (!(o instanceof NodeStatus)) {26 return false;27 }28 NodeStatus that = (NodeStatus) o;29 return Objects.equals(this.id, that.id) &&30 Objects.equals(this.state, that.state) &&31 Objects.equals(this.previousState, that.previousState) &&32 Objects.equals(this.lastContact, that.lastContact);33 }34 public int hashCode() {35 return Objects.hash(id, state, previousState, lastContact);36 }37 public String toString() {38 return String.format("%s (state: %s, last contact: %s)", id, state, lastContact);39 }40}41public class NodeId {42 private final String id;43 public NodeId(String id) {44 this.id = Objects.requireNonNull(id);45 }46 public String getId() {47 return id;48 }49 public boolean equals(Object o) {50 if (!(o instanceof NodeId)) {51 return false;52 }53 NodeId that = (NodeId) o;54 return Objects.equals(this.id, that.id);55 }56 public int hashCode() {57 return Objects.hash(id);58 }59 public String toString() {60 return id;61 }62}63public class Node {64 private final NodeId id;65 private final State state;66 private final State previousState;

Full Screen

Full Screen

Node

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.grid.graphql.Node;2import org.openqa.selenium.grid.graphql.SeleniumGridContainer;3import java.net.MalformedURLException;4import java.net.URL;5import java.util.List;6public class Main {7 public static void main(String[] args) throws MalformedURLException {8 SeleniumGridContainer grid = new SeleniumGridContainer(gridUrl);9 List<Node> nodes = grid.getNodes();10 for (Node node : nodes) {11 System.out.println("Node is: " + node.getId());12 System.out.println("Node is: " + node.getUri());13 System.out.println("Node is: " + node.getMaxSession());14 System.out.println("Node is: " + node.getSessions());15 System.out.println("Node is: " + node.getCapabilities());16 System.out.println("Node is: " + node.getStatus());17 System.out.println("Node is: " + node.getStartTime());18 System.out.println("Node is: " + node.getTimeout());19 System.out.println("Node is: " + node.getProtocol());20 System.out.println("Node is: " + node.getUri());21 System.out.println("Node is: " + node.getVersion());22 System.out.println("Node is: " + node.getOs());23 System.out.println("Node is: " + node.getArchitecture());24 System.out.println("Node is: " + node.getSystemLoad());25 System.out.println("Node is: " + node.getMemoryUsage());26 System.out.println("Node is: " + node.getDiskUsage());27 System.out.println("Node is: " + node.getFreeMemory());28 System.out.println("Node is: " + node.getFreeDiskSpace());29 System.out.println("Node is: " + node.getUsedMemory());30 System.out.println("Node is: " + node.getUsedDiskSpace());31 System.out.println("Node is: " + node.getSystemCpuLoad());32 System.out.println("Node is: " + node.getProcessCpuLoad());33 System.out.println("Node is: " + node.getProcessCpuTime());34 System.out.println("Node is

Full Screen

Full Screen
copy
1long difference = (sDt4.getTime() - sDt3.getTime()) / 1000;2System.out.println(difference);3
Full Screen
copy
1#include <algorithm>2#include <ctime>3#include <iostream>45int main() {6 int data[32768]; const int l = sizeof data / sizeof data[0];78 for (unsigned c = 0; c < l; ++c)9 data[c] = std::rand() % 256;1011 // sort 200-element segments, not the whole array12 for (unsigned c = 0; c + 200 <= l; c += 200)13 std::sort(&data[c], &data[c + 200]);1415 clock_t start = clock();16 long long sum = 0;1718 for (unsigned i = 0; i < 100000; ++i) {19 for (unsigned c = 0; c < sizeof data / sizeof(int); ++c) {20 if (data[c] >= 128)21 sum += data[c];22 }23 }2425 std::cout << static_cast<double>(clock() - start) / CLOCKS_PER_SEC << std::endl;26 std::cout << "sum = " << sum << std::endl;27}28
Full Screen
copy
1Already sorted 32995 milliseconds2Shuffled 125944 milliseconds34Already sorted 18610 milliseconds5Shuffled 133304 milliseconds67Already sorted 17942 milliseconds8Shuffled 107858 milliseconds9
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.

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