How to use getAvailableNodes method of org.openqa.selenium.grid.distributor.local.LocalDistributor class

Best Selenium code snippet using org.openqa.selenium.grid.distributor.local.LocalDistributor.getAvailableNodes

Source:DistributorTest.java Github

copy

Full Screen

...229 distributor.add(node);230 distributor.drain(node.getId());231 latch.await(5, SECONDS);232 assertThat(latch.getCount()).isEqualTo(0);233 assertThat(distributor.getAvailableNodes().size()).isEqualTo(0);234 try (NewSessionPayload payload = NewSessionPayload.create(caps)) {235 assertThatExceptionOfType(SessionNotCreatedException.class)236 .isThrownBy(() -> distributor.newSession(createRequest(payload)));237 }238 }239 @Test240 public void drainedNodeDoesNotShutDownIfNotEmpty() throws URISyntaxException, InterruptedException {241 URI nodeUri = new URI("http://example:5678");242 URI routableUri = new URI("http://localhost:1234");243 SessionMap sessions = new LocalSessionMap(tracer, bus);244 LocalNode node = LocalNode.builder(tracer, bus, routableUri, routableUri, registrationSecret)245 .add(caps, new TestSessionFactory((id, c) -> new Session(id, nodeUri, stereotype, c, Instant.now())))246 .build();247 CountDownLatch latch = new CountDownLatch(1);248 bus.addListener(NodeRemovedEvent.listener(ignored -> latch.countDown()));249 Distributor distributor = new LocalDistributor(250 tracer,251 bus,252 new PassthroughHttpClient.Factory(node),253 sessions,254 registrationSecret);255 distributor.add(node);256 NewSessionPayload payload = NewSessionPayload.create(caps);257 distributor.newSession(createRequest(payload));258 distributor.drain(node.getId());259 latch.await(5, SECONDS);260 assertThat(latch.getCount()).isEqualTo(1);261 assertThat(distributor.getAvailableNodes().size()).isEqualTo(1);262 }263 @Test264 public void drainedNodeShutsDownAfterSessionsFinish() throws URISyntaxException, InterruptedException {265 URI nodeUri = new URI("http://example:5678");266 URI routableUri = new URI("http://localhost:1234");267 SessionMap sessions = new LocalSessionMap(tracer, bus);268 LocalNode node = LocalNode.builder(tracer, bus, routableUri, routableUri, registrationSecret)269 .add(caps, new TestSessionFactory((id, c) -> new Session(id, nodeUri, stereotype, c, Instant.now())))270 .add(caps, new TestSessionFactory((id, c) -> new Session(id, nodeUri, stereotype, c, Instant.now())))271 .build();272 CountDownLatch latch = new CountDownLatch(1);273 bus.addListener(NodeRemovedEvent.listener(ignored -> latch.countDown()));274 Distributor distributor = new LocalDistributor(275 tracer,276 bus,277 new PassthroughHttpClient.Factory(node),278 sessions,279 registrationSecret);280 distributor.add(node);281 NewSessionPayload payload = NewSessionPayload.create(caps);282 CreateSessionResponse firstResponse = distributor.newSession(createRequest(payload));283 CreateSessionResponse secondResponse = distributor.newSession(createRequest(payload));284 distributor.drain(node.getId());285 assertThat(distributor.getAvailableNodes().size()).isEqualTo(1);286 node.stop(firstResponse.getSession().getId());287 node.stop(secondResponse.getSession().getId());288 latch.await(5, SECONDS);289 assertThat(latch.getCount()).isEqualTo(0);290 assertThat(distributor.getAvailableNodes().size()).isEqualTo(0);291 }292 @Test293 public void registeringTheSameNodeMultipleTimesOnlyCountsTheFirstTime()294 throws URISyntaxException {295 URI nodeUri = new URI("http://example:5678");296 URI routableUri = new URI("http://localhost:1234");297 LocalNode node = LocalNode.builder(tracer, bus, routableUri, routableUri, registrationSecret)298 .add(caps, new TestSessionFactory((id, c) -> new Session(id, nodeUri, stereotype, c, Instant.now())))299 .build();300 local.add(node);301 local.add(node);302 DistributorStatus status = local.getStatus();303 assertThat(status.getNodes().size()).isEqualTo(1);304 }...

Full Screen

Full Screen

Source:AddingNodesTest.java Github

copy

Full Screen

...122 handler.addHandler(node);123 LocalSessionMap sessions = new LocalSessionMap(tracer, bus);124 Distributor secretDistributor = new LocalDistributor(tracer, bus, clientFactory, sessions, registrationSecret);125 bus.fire(new NodeStatusEvent(node.getStatus()));126 assertEquals(0, secretDistributor.getAvailableNodes().size());127 }128 @Test129 public void shouldRegisterALocalNodeWithCorrectRegistrationSecret() throws URISyntaxException {130 URI sessionUri = new URI("http://example:1234");131 HttpClient.Factory clientFactory = new RoutableHttpClientFactory(132 externalUrl,133 handler,134 HttpClient.Factory.createDefault());135 Secret registrationSecret = new Secret("my_secret");136 Node node = LocalNode.builder(tracer, bus, externalUrl.toURI(), externalUrl.toURI(), registrationSecret)137 .add(CAPS, new TestSessionFactory((id, caps) -> new Session(id, sessionUri, stereotype, caps, Instant.now())))138 .build();139 handler.addHandler(node);140 LocalSessionMap sessions = new LocalSessionMap(tracer, bus);141 Distributor secretDistributor = new LocalDistributor(tracer, bus, clientFactory, sessions, registrationSecret);142 bus.fire(new NodeStatusEvent(node.getStatus()));143 wait.until(obj -> secretDistributor.getStatus().hasCapacity());144 assertEquals(1, secretDistributor.getAvailableNodes().size());145 }146 @Test147 public void shouldBeAbleToRegisterACustomNode() throws URISyntaxException {148 URI sessionUri = new URI("http://example:1234");149 Node node = new CustomNode(150 bus,151 new NodeId(UUID.randomUUID()),152 externalUrl.toURI(),153 c -> new Session(new SessionId(UUID.randomUUID()), sessionUri, stereotype, c, Instant.now()));154 handler.addHandler(node);155 distributor.add(node);156 wait.until(obj -> distributor.getStatus().hasCapacity());157 NodeStatus status = getOnlyElement(distributor.getStatus().getNodes());158 assertEquals(1, getStereotypes(status).get(CAPS).intValue());...

Full Screen

Full Screen

Source:LocalDistributor.java Github

copy

Full Screen

...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);...

Full Screen

Full Screen

getAvailableNodes

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.grid.distributor.local.LocalDistributor;2import org.openqa.selenium.grid.config.Config;3import org.openqa.selenium.grid.config.MapConfig;4import org.openqa.selenium.grid.config.TomlConfig;5import org.openqa.selenium.grid.server.BaseServerOptions;6import org.openqa.selenium.remote.http.HttpClient;7import org.openqa.selenium.remote.tracing.Tracer;8import org.openqa.selenium.remote.tracing.config.DefaultTracerConfig;9import org.openqa.selenium.remote.tracing.config.TracerConfig;10import org.openqa.selenium.remote.tracing.opentelemetry.OpenTelemetryTracer;11import java.io.IOException;12import java.util.Arrays;13import java.util.HashMap;14import java.util.List;15import java.util.Map;16import java.util.concurrent.ExecutionException;17public class DistributorGetAvailableNodes {18 public static void main(String[] args) throws IOException, ExecutionException, InterruptedException {19 Map<String, String> rawConfig = new HashMap<>();20 rawConfig.put("config", "C:\\Users\\myuser\\IdeaProjects\\selenium-grid\\config.toml");21 rawConfig.put("tracing", "C:\\Users\\myuser\\IdeaProjects\\selenium-grid\\tracing.json");22 Config config = new TomlConfig(new MapConfig(rawConfig));23 TracerConfig tracerConfig = DefaultTracerConfig.create(config);24 Tracer tracer = OpenTelemetryTracer.create(tracerConfig);25 BaseServerOptions serverOptions = new BaseServerOptions(config);26 HttpClient.Factory clientFactory = HttpClient.Factory.createDefault();27 LocalDistributor distributor = new LocalDistributor(28 config);29 List<String> nodes = distributor.getAvailableNodes();30 System.out.println("Available nodes: " + Arrays.toString(nodes.toArray()));31 }32}

Full Screen

Full Screen

getAvailableNodes

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.grid.distributor.local.LocalDistributor;2import org.openqa.selenium.grid.config.Config;3import org.openqa.selenium.grid.config.MapConfig;4import org.openqa.selenium.grid.node.Node;5import org.openqa.selenium.grid.node.remote.RemoteNode;6import org.openqa.selenium.remote.http.HttpClient;7import java.net.URI;8import java.util.Map;9import java.util.Set;10import java.util.stream.Collectors;11public class LocalDistributorExample {12 public static void main(String[] args) {13 Map<String, String> config = Map.of(14 Config gridConfig = new MapConfig(config);15 LocalDistributor distributor = new LocalDistributor(gridConfig);16 Set<Node> nodes = distributor.getAvailableNodes();17 nodes.stream().map(Node::getId).forEach(System.out::println);18 }19}20import org.openqa.selenium.grid.config.Config;21import org.openqa.selenium.grid.config.MapConfig;22import org.openqa.selenium.grid.distributor.local.LocalDistributor;23import org.openqa.selenium.grid.node.Node;24import org.openqa.selenium.grid.node.remote.RemoteNode;25import org.openqa.selenium.remote.http.HttpClient;26import java.net.URI;27import java.util.Map;28import java.util.Set;29import java.util.stream.Collectors;30public class LocalDistributorExample {31 public static void main(String[] args) {32 Map<String, String> config = Map.of(33 Config gridConfig = new MapConfig(config);34 LocalDistributor distributor = new LocalDistributor(gridConfig, client);35 Set<Node> nodes = distributor.getAvailableNodes();

Full Screen

Full Screen

getAvailableNodes

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.grid.distributor.local.LocalDistributor;2import org.openqa.selenium.grid.node.NodeStatus;3import org.openqa.selenium.remote.http.HttpClient;4import org.openqa.selenium.remote.tracing.DefaultTestTracer;5import org.openqa.selenium.remote.tracing.Tracer;6import java.net.URI;7import java.util.Set;8public class GetAvailableNodes {9 public static void main(String[] args) {10 Tracer tracer = DefaultTestTracer.createTracer();11 HttpClient.Factory clientFactory = HttpClient.Factory.createDefault();12 Set<NodeStatus> nodes = distributor.getAvailableNodes();13 System.out.println("List of nodes available in the grid are: " + nodes);14 }15}

Full Screen

Full Screen

getAvailableNodes

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.grid.distributor.local.LocalDistributor;2import org.openqa.selenium.grid.node.remote.RemoteNode;3import java.util.Set;4public class GetNodeUris {5 public static void main(String[] args) {6 LocalDistributor distributor = new LocalDistributor();7 Set<RemoteNode> nodes = distributor.getAvailableNodes();8 for (RemoteNode node : nodes) {9 System.out.println(node.getUri());10 }11 }12}

Full Screen

Full Screen

getAvailableNodes

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.grid.distributor.local.LocalDistributor;2import org.openqa.selenium.grid.node.Node;3import org.openqa.selenium.grid.node.local.LocalNode;4import org.openqa.selenium.remote.http.HttpClient;5import org.openqa.selenium.remote.http.HttpClient.Factory;6import org.openqa.selenium.remote.http.HttpResponse;7import org.openqa.selenium.remote.tracing.DefaultTestTracer;8import org.openqa.selenium.remote.tracing.Tracer;9import java.net.URI;10import java.util.ArrayList;11import java.util.List;12import java.util.Map;13import java.util.stream.Collectors;14public class TestGetAvailableNodes {15 public static void main(String[] args) throws Exception {16 Tracer tracer = DefaultTestTracer.createTracer();17 Factory clientFactory = HttpClient.Factory.createDefault();18 List<Node> nodes = new ArrayList<>();19 for (int i = 1; i <= 3; i++) {20 HttpResponse response = clientFactory.createClient(uri).execute(21 new org.openqa.selenium.remote.http.HttpRequest("GET", "/status"));22 Map<String, Object> status = new org.openqa.selenium.json.Json().toType(23 response.getContentString(), new org.openqa.selenium.json.TypeToken<Map<String, Object>>() {24 }.getType());25 nodes.add(new LocalNode(tracer, clientFactory, uri, status));26 }27 LocalDistributor distributor = new LocalDistributor(tracer, nodes);28 List<Node> availableNodes = distributor.getAvailableNodes();29 System.out.println(availableNodes.stream().map(node -> node.getId().toString()).collect(Collectors.joining(",")));30 }31}

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