How to use drain method of org.openqa.selenium.grid.node.remote.RemoteNode class

Best Selenium code snippet using org.openqa.selenium.grid.node.remote.RemoteNode.drain

Source:NodeTest.java Github

copy

Full Screen

...361 assertThat(baseDir).doesNotExist();362 }363 @Test364 public void shouldNotCreateSessionIfDraining() {365 node.drain();366 assertThat(local.isDraining()).isTrue();367 assertThat(node.isDraining()).isTrue();368 Optional<CreateSessionResponse> sessionResponse = node.newSession(createSessionRequest(caps));369 assertThat(sessionResponse.isPresent()).isFalse();370 }371 @Test372 public void shouldNotShutdownDuringOngoingSessionsIfDraining() throws InterruptedException {373 Optional<Session> firstSession =374 node.newSession(createSessionRequest(caps)).map(CreateSessionResponse::getSession);375 Optional<Session> secondSession =376 node.newSession(createSessionRequest(caps)).map(CreateSessionResponse::getSession);377 CountDownLatch latch = new CountDownLatch(1);378 bus.addListener(NodeDrainComplete.listener(ignored -> latch.countDown()));379 node.drain();380 assertThat(local.isDraining()).isTrue();381 assertThat(node.isDraining()).isTrue();382 Optional<CreateSessionResponse> sessionResponse = node.newSession(createSessionRequest(caps));383 assertThat(sessionResponse.isPresent()).isFalse();384 assertThat(firstSession.isPresent()).isTrue();385 assertThat(secondSession.isPresent()).isTrue();386 assertThat(local.getCurrentSessionCount()).isEqualTo(2);387 latch.await(1, SECONDS);388 assertThat(latch.getCount()).isEqualTo(1);389 }390 @Test391 public void shouldShutdownAfterSessionsCompleteIfDraining() throws InterruptedException {392 CountDownLatch latch = new CountDownLatch(1);393 bus.addListener(NodeDrainComplete.listener(ignored -> latch.countDown()));394 Optional<Session> firstSession =395 node.newSession(createSessionRequest(caps)).map(CreateSessionResponse::getSession);396 Optional<Session> secondSession =397 node.newSession(createSessionRequest(caps)).map(CreateSessionResponse::getSession);398 node.drain();399 assertThat(firstSession.isPresent()).isTrue();400 assertThat(secondSession.isPresent()).isTrue();401 node.stop(firstSession.get().getId());402 node.stop(secondSession.get().getId());403 latch.await(5, SECONDS);404 assertThat(latch.getCount()).isEqualTo(0);405 }406 @Test407 public void shouldAllowsWebDriverCommandsForOngoingSessionIfDraining() throws InterruptedException {408 CountDownLatch latch = new CountDownLatch(1);409 bus.addListener(NodeDrainComplete.listener(ignored -> latch.countDown()));410 Optional<Session> session =411 node.newSession(createSessionRequest(caps)).map(CreateSessionResponse::getSession);412 node.drain();413 SessionId sessionId = session.get().getId();414 HttpRequest req = new HttpRequest(POST, String.format("/session/%s/url", sessionId));415 HttpResponse response = node.execute(req);416 assertThat(response.getStatus()).isEqualTo(200);417 assertThat(latch.getCount()).isEqualTo(1);418 }419 private File createTmpFile(String content) {420 try {421 File f = File.createTempFile("webdriver", "tmp");422 f.deleteOnExit();423 Files.write(f.toPath(), content.getBytes(StandardCharsets.UTF_8));424 return f;425 } catch (IOException e) {426 throw new UncheckedIOException(e);...

Full Screen

Full Screen

Source:LocalDistributor.java Github

copy

Full Screen

...172 }173 };174 }175 @Override176 public boolean drain(NodeId nodeId) {177 Node node = nodes.get(nodeId);178 if (node == null) {179 LOG.info("Asked to drain unregistered node " + nodeId);180 return false;181 }182 Lock writeLock = lock.writeLock();183 writeLock.lock();184 try {185 node.drain();186 model.setAvailability(nodeId, DRAINING);187 } finally {188 writeLock.unlock();189 }190 return node.isDraining();191 }192 public void remove(NodeId nodeId) {193 Lock writeLock = lock.writeLock();194 writeLock.lock();195 try {196 model.remove(nodeId);197 Runnable runnable = allChecks.remove(nodeId);198 if (runnable != null) {199 hostChecker.remove(runnable);...

Full Screen

Full Screen

Source:RemoteNode.java Github

copy

Full Screen

...163 public HealthCheck getHealthCheck() {164 return healthCheck;165 }166 @Override167 public void drain() {168 HttpRequest req = new HttpRequest(POST, "/se/grid/node/drain");169 HttpTracing.inject(tracer, tracer.getCurrentContext(), req);170 HttpResponse res = client.execute(req);171 if(res.getStatus()== HTTP_OK) {172 draining = true;173 }174 }175 private Map<String, Object> toJson() {176 return ImmutableMap.of(177 "id", getId(),178 "uri", externalUri,179 "capabilities", capabilities);180 }181 private class RemoteCheck implements HealthCheck {182 @Override183 public Result check() {184 HttpRequest req = new HttpRequest(GET, "/status");185 try {186 HttpResponse res = client.execute(req);...

Full Screen

Full Screen

drain

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.grid.node.remote.RemoteNode;2import org.openqa.selenium.remote.http.HttpClient;3import org.openqa.selenium.remote.http.HttpRequest;4import org.openqa.selenium.remote.http.HttpResponse;5import java.io.IOException;6import java.net.URI;7import java.net.URISyntaxException;8import java.util.concurrent.TimeUnit;9public class RemoteNodeDrain {10 public static void main(String[] args) throws URISyntaxException, IOException {11 HttpClient client = HttpClient.Factory.createDefault().createClient(uri);12 RemoteNode node = new RemoteNode(client, uri);13 HttpRequest request = new HttpRequest("POST", "/drain");14 HttpResponse response = node.execute(request);15 System.out.println("Drain status code: " + response.getStatus());16 }17}

Full Screen

Full Screen

drain

Using AI Code Generation

copy

Full Screen

1package org.openqa.selenium.grid.node.remote;2import org.openqa.selenium.Capabilities;3import org.openqa.selenium.ImmutableCapabilities;4import org.openqa.selenium.SessionNotCreatedException;5import org.openqa.selenium.grid.data.CreateSessionRequest;6import org.openqa.selenium.grid.data.Session;7import org.openqa.selenium.grid.distributor.Distributor;8import org.openqa.selenium.grid.node.Node;9import org.openqa.selenium.grid.node.NodeStatus;10import org.openqa.selenium.grid.node.SessionFactory;11import org.openqa.selenium.grid.web.Values;12import org.openqa.selenium.internal.Require;13import org.openqa.selenium.json.Json;14import org.openqa.selenium.remote.Dialect;15import org.openqa.selenium.remote.http.HttpClient;16import org.openqa.selenium.remote.http.HttpRequest;17import org.openqa.selenium.remote.http.HttpResponse;18import org.openqa.selenium.remote.tracing.Tracer;19import java.io.IOException;20import java.net.URI;21import java.net.URISyntaxException;22import java.time.Duration;23import java.util.Map;24import java.util.Objects;25import java.util.Optional;26import java.util.Set;27import java.util.UUID;28import java.util.concurrent.ConcurrentHashMap;29import java.util.concurrent.ConcurrentMap;30import java.util.logging.Logger;31public class RemoteNode implements Node {32 private static final Logger LOG = Logger.getLogger(RemoteNode.class.getName());33 private static final Json JSON = new Json();34 private final HttpClient client;35 private final URI uri;36 private final ConcurrentMap<UUID, Session> activeSessions = new ConcurrentHashMap<>();37 private final Set<Dialect> dialects;38 private final Tracer tracer;39 public RemoteNode(Tracer tracer, HttpClient client, URI uri, Set<Dialect> dialects) {40 this.tracer = Require.nonNull("Tracer", tracer);41 this.client = Require.nonNull("HTTP client", client);42 this.uri = Require.nonNull("Node URI", uri);43 this.dialects = Require.nonNull("Dialects", dialects);44 }45 public void start() {46 }47 public void stop() {48 }49 public boolean isReady() {50 try {51 HttpResponse response = client.execute(new HttpRequest(GET, uri));52 if (response.getStatus() != 200) {53 return false;54 }55 Map<String, Object> raw = JSON.toType(response.getContentString(), JSON.MAP_TYPE);56 NodeStatus status = new NodeStatus(raw);57 return status.isReady();58 } catch (IOException

Full Screen

Full Screen

drain

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.grid.node.remote.RemoteNode;2import org.openqa.selenium.remote.http.HttpClient;3import org.openqa.selenium.remote.http.HttpRequest;4import org.openqa.selenium.remote.http.HttpResponse;5import java.io.IOException;6import java.net.MalformedURLException;7import java.net.URL;8import java.util.concurrent.TimeUnit;9public class NodeDrain {10 public static void main(String[] args) throws MalformedURLException, IOException {11 HttpRequest request = new HttpRequest(HttpRequest.POST, "/se/grid/node/drain");12 HttpResponse response = client.execute(request);13 System.out.println("Response Code: " + response.getStatus());14 System.out.println("Response Body: " + response.getContentString());15 client.close();16 }17}

Full Screen

Full Screen

drain

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.grid.node.remote.RemoteNode;2import org.openqa.selenium.remote.http.HttpClient;3import org.openqa.selenium.remote.http.HttpRequest;4import org.openqa.selenium.remote.http.HttpResponse;5import java.net.MalformedURLException;6import java.net.URL;7import java.util.concurrent.TimeUnit;8public class RemoteNodeDrain {9 public static void main(String[] args) throws MalformedURLException, InterruptedException {10 HttpRequest request = new HttpRequest("POST", "/se/grid/node/drain");11 HttpResponse response = client.execute(request);12 System.out.println(response);13 }14}15Server: Jetty(9.4.20.v20190813)16{17 {18 },19 {20 },21 {

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