How to use getStatus method of org.openqa.selenium.grid.node.Node class

Best Selenium code snippet using org.openqa.selenium.grid.node.Node.getStatus

Source:AddingNodesTest.java Github

copy

Full Screen

...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 }192 @Override193 public void stop(SessionId id) throws NoSuchSessionException {194 getSession(id);195 running = null;196 bus.fire(new SessionClosedEvent(id));197 }198 @Override199 protected boolean isSessionOwner(SessionId id) {200 return running != null && running.getId().equals(id);201 }202 @Override203 public boolean isSupporting(Capabilities capabilities) {204 return Objects.equals("cake", capabilities.getCapability("cheese"));205 }206 @Override207 public NodeStatus getStatus() {208 Set<NodeStatus.Active> actives = new HashSet<>();209 if (running != null) {210 actives.add(new NodeStatus.Active(CAPS, running.getId(), running.getCapabilities()));211 }212 return new NodeStatus(213 getId(),214 getUri(),215 1,216 ImmutableMap.of(CAPS, 1),217 actives);218 }219 @Override220 public HealthCheck getHealthCheck() {221 return () -> new HealthCheck.Result(true, "tl;dr");...

Full Screen

Full Screen

Source:NodeServer.java Github

copy

Full Screen

...102 LOG.info("Reporting self as: " + serverOptions.getExternalUri());103 NodeOptions nodeOptions = new NodeOptions(config);104 this.node = nodeOptions.getNode();105 HttpHandler readinessCheck = req -> {106 if (node.getStatus().hasCapacity()) {107 return new HttpResponse()108 .setStatus(HTTP_NO_CONTENT);109 }110 return new HttpResponse()111 .setStatus(HTTP_INTERNAL_ERROR)112 .setHeader("Content-Type", MediaType.PLAIN_TEXT_UTF_8.toString())113 .setContent(Contents.utf8String("No capacity available"));114 };115 bus.addListener(NodeAddedEvent.listener(nodeId -> {116 if (node.getId().equals(nodeId)) {117 LOG.info("Node has been added");118 }119 }));120 bus.addListener(NodeDrainComplete.listener(nodeId -> {121 if (!node.getId().equals(nodeId)) {122 return;123 }124 // Wait a beat before shutting down so the final response from the125 // node can escape.126 new Thread(127 () -> {128 try {129 Thread.sleep(1000);130 } catch (InterruptedException e) {131 // Swallow, the next thing we're doing is shutting down132 }133 LOG.info("Shutting down");134 System.exit(0);135 },136 "Node shutdown: " + nodeId)137 .start();138 }));139 Route httpHandler = Route.combine(140 node,141 get("/readyz").to(() -> readinessCheck));142 return new Handlers(httpHandler, new ProxyNodeCdp(clientFactory, node));143 }144 @Override145 public Server<?> asServer(Config initialConfig) {146 Require.nonNull("Config", initialConfig);147 Config config = new MemoizedConfig(new CompoundConfig(initialConfig, getDefaultConfig()));148 Handlers handler = createHandlers(config);149 return new NettyServer(150 new BaseServerOptions(config),151 handler.httpHandler,152 handler.websocketHandler) {153 @Override154 public NettyServer start() {155 super.start();156 // Unlimited attempts, initial 5 seconds interval, backoff rate of 1.0005, max interval of 5 minutes157 RetryPolicy<Object> registrationPolicy = new RetryPolicy<>()158 .withMaxAttempts(-1)159 .handleResultIf(result -> true)160 .withBackoff(Duration.ofSeconds(5).getSeconds(), Duration.ofMinutes(5).getSeconds(), ChronoUnit.SECONDS, 1.0005);161 LOG.info("Starting registration process for node id " + node.getId());162 Executors.newSingleThreadExecutor().submit(() -> {163 Failsafe.with(registrationPolicy).run(164 () -> {165 LOG.fine("Sending registration event");166 HealthCheck.Result check = node.getHealthCheck().check();167 if (DOWN.equals(check.getAvailability())) {168 LOG.severe("Node is not alive: " + check.getMessage());169 // Throw an exception to force another check sooner.170 throw new UnsupportedOperationException("Node cannot be registered");171 }172 bus.fire(new NodeStatusEvent(node.getStatus()));173 }174 );175 });176 return this;177 }178 };179 }180 @Override181 protected void execute(Config config) {182 Require.nonNull("Config", config);183 Server<?> server = asServer(config).start();184 BuildInfo info = new BuildInfo();185 LOG.info(String.format(186 "Started Selenium node %s (revision %s): %s",...

Full Screen

Full Screen

Source:RouterTest.java Github

copy

Full Screen

...74 router = new Router(tracer, clientFactory, sessions, distributor);75 }76 @Test77 public void shouldListAnEmptyDistributorAsMeaningTheGridIsNotReady() {78 Map<String, Object> status = getStatus(router);79 assertFalse((Boolean) status.get("ready"));80 }81 @Test82 public void addingANodeThatIsDownMeansTheGridIsNotReady() throws URISyntaxException {83 Capabilities capabilities = new ImmutableCapabilities("cheese", "peas");84 URI uri = new URI("http://exmaple.com");85 AtomicReference<Availability> isUp = new AtomicReference<>(DOWN);86 Node node = LocalNode.builder(tracer, bus, uri, uri, registrationSecret)87 .add(capabilities, new TestSessionFactory((id, caps) -> new Session(id, uri, new ImmutableCapabilities(), caps, Instant.now())))88 .advanced()89 .healthCheck(() -> new HealthCheck.Result(isUp.get(), "TL;DR"))90 .build();91 distributor.add(node);92 Map<String, Object> status = getStatus(router);93 assertFalse(status.toString(), (Boolean) status.get("ready"));94 }95 @Test96 public void aNodeThatIsUpAndHasSpareSessionsMeansTheGridIsReady() throws URISyntaxException {97 Capabilities capabilities = new ImmutableCapabilities("cheese", "peas");98 URI uri = new URI("http://exmaple.com");99 AtomicReference<Availability> isUp = new AtomicReference<>(UP);100 Node node = LocalNode.builder(tracer, bus, uri, uri, registrationSecret)101 .add(capabilities, new TestSessionFactory((id, caps) -> new Session(id, uri, new ImmutableCapabilities(), caps, Instant.now())))102 .advanced()103 .healthCheck(() -> new HealthCheck.Result(isUp.get(), "TL;DR"))104 .build();105 distributor.add(node);106 Map<String, Object> status = getStatus(router);107 assertTrue(status.toString(), (Boolean) status.get("ready"));108 }109 @Test110 public void shouldListAllNodesTheDistributorIsAwareOf() {111 }112 @Test113 public void ifNodesHaveSpareSlotsButAlreadyHaveMaxSessionsGridIsNotReady() {114 }115 private Map<String, Object> getStatus(Router router) {116 HttpResponse response = router.execute(new HttpRequest(GET, "/status"));117 Map<String, Object> status = Values.get(response, MAP_TYPE);118 assertNotNull(status);119 return status;120 }121}...

Full Screen

Full Screen

Source:RemoteNode.java Github

copy

Full Screen

...98 }99 @Override100 public void executeWebDriverCommand(HttpRequest req, HttpResponse resp) {101 HttpResponse fromUpstream = client.apply(req);102 resp.setStatus(fromUpstream.getStatus());103 for (String name : fromUpstream.getHeaderNames()) {104 for (String value : fromUpstream.getHeaders(name)) {105 resp.addHeader(name, value);106 }107 }108 resp.setContent(fromUpstream.getContent());109 }110 @Override111 public void stop(SessionId id) throws NoSuchSessionException {112 Objects.requireNonNull(id, "Session ID has not been set");113 HttpRequest req = new HttpRequest(DELETE, "/se/grid/node/session/" + id);114 HttpResponse res = client.apply(req);115 Values.get(res, Void.class);116 }117 @Override118 public NodeStatus getStatus() {119 HttpRequest req = new HttpRequest(GET, "/status");120 HttpResponse res = client.apply(req);121 return Values.get(res, NodeStatus.class);122 }123 private Map<String, Object> toJson() {124 return ImmutableMap.of(125 "id", getId(),126 "uri", externalUri,127 "capabilities", capabilities);128 }129}...

Full Screen

Full Screen

Source:LocalDistributor.java Github

copy

Full Screen

...57 public void remove(UUID nodeId) {58 nodes.removeIf(node -> nodeId.equals(node.getId()));59 }60 @Override61 public DistributorStatus getStatus() {62 ImmutableList<NodeStatus> nodesStatuses = this.nodes.stream()63 .map(Node::getStatus)64 .collect(toImmutableList());65 return new DistributorStatus(nodesStatuses);66 }67}...

Full Screen

Full Screen

getStatus

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.grid.node.Node;2import org.openqa.selenium.grid.node.local.LocalNode;3import org.openqa.selenium.grid.session.remote.RemoteSession;4import org.openqa.selenium.grid.web.Routable;5import org.openqa.selenium.remote.http.HttpMethod;6import org.openqa.selenium.remote.http.HttpRequest;7import org.openqa.selenium.remote.http.HttpResponse;8import org.openqa.selenium.remote.tracing.Tracer;9import org.openqa.selenium.remote.tracing.opentelemetry.OpenTelemetryTracer;10import java.io.IOException;11import java.net.URI;12import java.util.Objects;13import java.util.function.Function;14public class NodeStatus implements Routable {15 private final Tracer tracer;16 private final Node node;17 public NodeStatus(Tracer tracer, Node node) {18 this.tracer = Objects.requireNonNull(tracer);19 this.node = Objects.requireNonNull(node);20 }21 public Function<HttpRequest, HttpResponse> apply(String prefix) {22 return req -> {23 if (!req.getMethod().equals(HttpMethod.GET)) {24 return new HttpResponse().setStatus(405);25 }26 return new HttpResponse()27 .setContent(node.getStatus().toString())28 .setStatus(200);29 };30 }31 public static void main(String[] args) throws IOException {32 Tracer tracer = OpenTelemetryTracer.create("node-status");33 NodeStatus nodeStatus = new NodeStatus(tracer, node);34 node.add(nodeStatus);35 System.out.println("Node status: " + node.getStatus());36 }37}

Full Screen

Full Screen

getStatus

Using AI Code Generation

copy

Full Screen

1 public String getStatus() {2 return status;3 }4 public void setStatus(String status) {5 this.status = status;6 }7}8Node node = new Node();9node.setStatus("online");10Node node = new Node();11String status = node.getStatus();

Full Screen

Full Screen

getStatus

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.grid.node.Node;2Node node = new Node();3String status = node.getStatus();4System.out.println(status);5import org.openqa.selenium.grid.node.Node;6Node node = new Node();7String uri = node.getUri();8System.out.println(uri);9import org.openqa.selenium.grid.node.Node;10Node node = new Node();11Map<String, Object> capabilities = node.getCapabilities();12System.out.println(capabilities);13import org.openqa.selenium.grid.node.Node;14Node node = new Node();15Set<SessionId> activeSessions = node.getActiveSessions();16System.out.println(activeSessions);

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful