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

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

Source:LocalDistributor.java Github

copy

Full Screen

...83 .filter(host -> host.hasCapacity(caps))84 .min(85 // Now sort by node which has the lowest load (natural ordering)86 Comparator.comparingDouble(Host::getLoad)87 // Then last session created (oldest first), so natural ordering again88 .thenComparingLong(Host::getLastSessionCreated)89 // And use the host id as a tie-breaker.90 .thenComparing(Host::getId))91 // And reserve some space92 .map(host -> host.reserve(caps));93 } finally {94 writeLock.unlock();95 }96 return selected97 .orElseThrow(98 () -> new SessionNotCreatedException("Unable to find provider for session: " + allCaps))99 .get();100 }101 @Override102 public LocalDistributor add(Node node) {103 StringBuilder sb = new StringBuilder();104 Lock writeLock = this.lock.writeLock();105 writeLock.lock();106 try (Span span = tracer.createSpan("distributor.add", tracer.getActiveSpan());107 JsonOutput out = JSON.newOutput(sb)) {108 out.setPrettyPrint(false).write(node);109 span.addTag("node", sb.toString());110 // TODO: We should check to see what happens for duplicate nodes.111 Host host = new Host(node);112 hosts.add(host);113 LOG.info(String.format("Added node %s.", node.getId()));114 host.refresh();115 Runnable runnable = host::refresh;116 Collection<Runnable> nodeRunnables = allChecks.getOrDefault(node.getId(), new ArrayList<>());117 nodeRunnables.add(runnable);118 allChecks.put(node.getId(), nodeRunnables);119 hostChecker.submit(runnable, Duration.ofMinutes(5), Duration.ofSeconds(30));120 } finally {121 writeLock.unlock();122 }123 return this;124 }125 @Override126 public void remove(UUID nodeId) {127 Lock writeLock = lock.writeLock();128 writeLock.lock();129 try (Span span = tracer.createSpan("distributor.remove", tracer.getActiveSpan())) {130 span.addTag("node.id", nodeId);131 hosts.removeIf(host -> nodeId.equals(host.getId()));132 allChecks.getOrDefault(nodeId, new ArrayList<>()).forEach(hostChecker::remove);133 } finally {134 writeLock.unlock();135 }136 }137 @Override138 public DistributorStatus getStatus() {139 Lock readLock = this.lock.readLock();140 readLock.lock();141 try {142 ImmutableList<NodeStatus> nodesStatuses = this.hosts.stream()143 .map(Host::getStatus)...

Full Screen

Full Screen

Source:EndToEndTest.java Github

copy

Full Screen

...53 SessionMap sessions = new LocalSessionMap();54 Distributor distributor = new LocalDistributor(tracer);55 URI nodeUri = new URI("http://localhost:4444");56 LocalNode node = LocalNode.builder(tracer, nodeUri, sessions)57 .add(driverCaps, createFactory(nodeUri))58 .build();59 distributor.add(node);60 Router router = new Router(sessions, distributor);61 Server<?> server = createServer();62 server.addRoute(Routes.matching(router).using(router));63 server.start();64 exerciseDriver(server);65 }66 private void exerciseDriver(Server<?> server) {67 WebDriver driver = new RemoteWebDriver(68 server.getUrl(),69 new ImmutableCapabilities("browserName", "cheese", "type", "cheddar"));70 driver.get("http://www.google.com");71 driver.quit();72 }73 @Test74 public void withServers() throws URISyntaxException {75 LocalSessionMap localSessions = new LocalSessionMap();76 Server<?> sessionServer = createServer();77 sessionServer.addRoute(Routes.matching(localSessions).using(localSessions));78 sessionServer.start();79 SessionMap sessions = new RemoteSessionMap(getClient(sessionServer));80 LocalDistributor localDistributor = new LocalDistributor(tracer);81 Server<?> distributorServer = createServer();82 distributorServer.addRoute(Routes.matching(localDistributor).using(localDistributor));83 distributorServer.start();84 Distributor distributor = new RemoteDistributor(tracer, getClient(distributorServer));85 int port = PortProber.findFreePort();86 URI nodeUri = new URI("http://localhost:" + port);87 LocalNode localNode = LocalNode.builder(tracer, nodeUri, sessions)88 .add(driverCaps, createFactory(nodeUri))89 .build();90 Server<?> nodeServer = new BaseServer<>(91 DistributedTracer.builder().build(),92 new BaseServerOptions(93 new MapConfig(ImmutableMap.of("server", ImmutableMap.of("port", port)))));94 nodeServer.addRoute(Routes.matching(localNode).using(localNode));95 nodeServer.start();96 distributor.add(localNode);97 Router router = new Router(sessions, distributor);98 Server<?> routerServer = createServer();99 routerServer.addRoute(Routes.matching(router).using(router));100 routerServer.start();101 exerciseDriver(routerServer);102 }103 private HttpClient getClient(Server<?> server) {104 return HttpClient.Factory.createDefault().createClient(server.getUrl());105 }106 private Server<?> createServer() {107 int port = PortProber.findFreePort();108 return new BaseServer<>(DistributedTracer.builder().build(), new BaseServerOptions(109 new MapConfig(ImmutableMap.of("server", ImmutableMap.of("port", port)))));110 }111 private Function<Capabilities, Session> createFactory(URI serverUri) {112 class SpoofSession extends Session implements CommandHandler {113 private SpoofSession(Capabilities capabilities) {114 super(new SessionId(UUID.randomUUID()), serverUri, capabilities);115 }116 @Override117 public void execute(HttpRequest req, HttpResponse resp) {118 }119 }120 return caps -> new SpoofSession(caps);121 }122}...

Full Screen

Full Screen

Source:DistributorTest.java Github

copy

Full Screen

...47 caps = new ImmutableCapabilities("browserName", "cheese");48 }49 @Test50 public void creatingANewSessionWithoutANodeEndsInFailure() {51 try (NewSessionPayload payload = NewSessionPayload.create(caps)) {52 assertThatExceptionOfType(SessionNotCreatedException.class)53 .isThrownBy(() -> distributor.newSession(payload));54 }55 }56 @Test57 public void shouldBeAbleToAddANodeAndCreateASession() throws URISyntaxException {58 URI nodeUri = new URI("http://example:5678");59 URI routableUri = new URI("http://localhost:1234");60 LocalSessionMap sessions = new LocalSessionMap();61 LocalNode node = LocalNode.builder(tracer, routableUri, sessions)62 .add(caps, c -> new Session(new SessionId(UUID.randomUUID()), nodeUri, c))63 .build();64 Distributor distributor = new LocalDistributor(tracer);65 distributor.add(node);66 MutableCapabilities sessionCaps = new MutableCapabilities(caps);67 sessionCaps.setCapability("sausages", "gravy");68 try (NewSessionPayload payload = NewSessionPayload.create(sessionCaps)) {69 Session session = distributor.newSession(payload);70 assertThat(session.getCapabilities()).isEqualTo(sessionCaps);71 assertThat(session.getUri()).isEqualTo(routableUri);72 }73 }74 @Test75 public void shouldBeAbleToRemoveANode() throws URISyntaxException {76 URI nodeUri = new URI("http://example:5678");77 URI routableUri = new URI("http://localhost:1234");78 LocalSessionMap sessions = new LocalSessionMap();79 LocalNode node = LocalNode.builder(tracer, routableUri, sessions)80 .add(caps, c -> new Session(new SessionId(UUID.randomUUID()), nodeUri, c))81 .build();82 Distributor local = new LocalDistributor(tracer);83 distributor = new RemoteDistributor(tracer, new PassthroughHttpClient<>(local));84 distributor.add(node);85 distributor.remove(node.getId());86 try (NewSessionPayload payload = NewSessionPayload.create(caps)) {87 assertThatExceptionOfType(SessionNotCreatedException.class)88 .isThrownBy(() -> distributor.newSession(payload));89 }90 }91 @Test92 public void registeringTheSameNodeMultipleTimesOnlyCountsTheFirstTime()93 throws URISyntaxException {94 URI nodeUri = new URI("http://example:5678");95 URI routableUri = new URI("http://localhost:1234");96 LocalSessionMap sessions = new LocalSessionMap();97 LocalNode node = LocalNode.builder(tracer, routableUri, sessions)98 .add(caps, c -> new Session(new SessionId(UUID.randomUUID()), nodeUri, c))99 .build();100 local.add(node);...

Full Screen

Full Screen

Source:Hub.java Github

copy

Full Screen

...96 BaseServerOptions serverOptions = new BaseServerOptions(config);97 HttpClient.Factory clientFactory = new RoutableHttpClientFactory(98 serverOptions.getExternalUri().toURL(),99 handler,100 HttpClient.Factory.createDefault());101 Distributor distributor = new LocalDistributor(102 tracer,103 bus,104 clientFactory,105 sessions);106 handler.addHandler(distributor);107 Router router = new Router(tracer, clientFactory, sessions, distributor);108 Server<?> server = new BaseServer<>(109 serverOptions);110 server.addRoute(Routes.matching(router).using(router).decorateWith(W3CCommandHandler::new));111 server.start();112 };113 }114}...

Full Screen

Full Screen

Source:DistributorServer.java Github

copy

Full Screen

...75 LoggingOptions loggingOptions = new LoggingOptions(config);76 loggingOptions.configureLogging();77 DistributedTracer tracer = loggingOptions.getTracer();78 GlobalDistributedTracer.setInstance(tracer);79 Distributor distributor = new LocalDistributor(tracer, HttpClient.Factory.createDefault());80 BaseServerOptions serverOptions = new BaseServerOptions(config);81 Server<?> server = new BaseServer<>(serverOptions);82 server.addRoute(83 Routes.matching(distributor)84 .using(distributor)85 .decorateWith(W3CCommandHandler.class));86 server.start();87 };88 }89}...

Full Screen

Full Screen

Source:GridModelTest.java Github

copy

Full Screen

...25import org.openqa.selenium.remote.http.HttpClient;26import org.openqa.selenium.remote.tracing.DefaultTestTracer;27import org.openqa.selenium.remote.tracing.Tracer;28public class GridModelTest {29 private final Tracer tracer = DefaultTestTracer.createTracer();30 private final EventBus events = new GuavaEventBus();31 private final HttpClient.Factory clientFactory = HttpClient.Factory.createDefault();32 private final SessionMap sessions = new LocalSessionMap(tracer, events);33 private final Secret secret = new Secret("cheese");34 private final Distributor distributor = new LocalDistributor(tracer, events, clientFactory, sessions, secret);35 @Test36 public void shouldNotChangeTheStateOfANodeMarkedAsDownWhenNodeStatusEventFires() {37 }38}...

Full Screen

Full Screen

create

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.MemoizedConfig;4import org.openqa.selenium.grid.distributor.Distributor;5import org.openqa.selenium.grid.distributor.DistributorOptions;6import org.openqa.selenium.remote.http.HttpClient;7public class LocalDistributorExample {8 public static void main(String[] args) {9 Config config = new MemoizedConfig();10 DistributorOptions options = new DistributorOptions(config);11 HttpClient.Factory clientFactory = HttpClient.Factory.createDefault();12 Distributor distributor = LocalDistributor.create(options, clientFactory);13 }14}15import org.openqa.selenium.grid.distributor.local.LocalDistributor;16import org.openqa.selenium.grid.config.Config;17import org.openqa.selenium.grid.config.MemoizedConfig;18import org.openqa.selenium.grid.distributor.Distributor;19import org.openqa.selenium.grid.distributor.DistributorOptions;20import org.openqa.selenium.remote.http.HttpClient;21public class LocalDistributorExample {22 public static void main(String[] args) {23 Config config = new MemoizedConfig();24 DistributorOptions options = new DistributorOptions(config);25 HttpClient.Factory clientFactory = HttpClient.Factory.createDefault();26 Distributor distributor = LocalDistributor.create(options, clientFactory);27 }28}29org.openqa.selenium.grid.distributor.local.LocalDistributor.create(DistributorOptions,HttpClient.Factory)30public static Distributor create(31 HttpClient.Factory clientFactory) {32 return new LocalDistributor(options, clientFactory);33}34public static Distributor create(35 HttpClient.Factory clientFactory) {36 return new LocalDistributor(options, clientFactory);37}38public static Distributor create(39 HttpClient.Factory clientFactory) {40 return new LocalDistributor(options, clientFactory);41}42public static Distributor create(43 HttpClient.Factory clientFactory) {44 return new LocalDistributor(options, clientFactory);45}

Full Screen

Full Screen

create

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.grid.distributor.local.LocalDistributor;2import org.openqa.selenium.grid.distributor.Distributor;3import org.openqa.selenium.grid.config.Config;4Config config = Config.create();5Distributor distributor = LocalDistributor.create(config);6import org.openqa.selenium.grid.distributor.Distributor;7import org.openqa.selenium.grid.sessionmap.config.SessionMapOptions;8import org.openqa.selenium.grid.config.Config;9import org.openqa.selenium.grid.sessionmap.remote.RemoteSessionMap;10import org.openqa.selenium.remote.http.HttpClient;11import org.openqa.selenium.grid.data.Session;12import org.openqa.selenium.grid.data.SessionRequest;13Config config = Config.create();14SessionRequest sessionRequest = new SessionRequest();15Session session = new Session();16Distributor distributor = new Distributor(sessionMap);17distributor.add(sessionRequest, session);18import org.openqa.selenium.grid.distributor.Distributor;19import org.openqa.selenium.grid.sessionmap.config.SessionMapOptions;20import org.openqa.selenium.grid.config.Config;21import org.openqa.selenium.grid.sessionmap.remote.RemoteSessionMap;22import org.openqa.selenium.remote.http.HttpClient;23import org.openqa.selenium.grid.data.Session;24import org.openqa.selenium.grid.data.SessionRequest;25Config config = Config.create();26SessionRequest sessionRequest = new SessionRequest();27Session session = new Session();28Distributor distributor = new Distributor(sessionMap);

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