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

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

Source:NodeServer.java Github

copy

Full Screen

...27import org.openqa.selenium.grid.config.CompoundConfig;28import org.openqa.selenium.grid.config.Config;29import org.openqa.selenium.grid.config.MemoizedConfig;30import org.openqa.selenium.grid.config.Role;31import org.openqa.selenium.grid.data.NodeAddedEvent;32import org.openqa.selenium.grid.data.NodeDrainComplete;33import org.openqa.selenium.grid.data.NodeStatusEvent;34import org.openqa.selenium.grid.log.LoggingOptions;35import org.openqa.selenium.grid.node.HealthCheck;36import org.openqa.selenium.grid.node.Node;37import org.openqa.selenium.grid.node.ProxyNodeCdp;38import org.openqa.selenium.grid.node.config.NodeOptions;39import org.openqa.selenium.grid.server.BaseServerOptions;40import org.openqa.selenium.grid.server.EventBusOptions;41import org.openqa.selenium.grid.server.NetworkOptions;42import org.openqa.selenium.grid.server.Server;43import org.openqa.selenium.internal.Require;44import org.openqa.selenium.netty.server.NettyServer;45import org.openqa.selenium.remote.http.Contents;46import org.openqa.selenium.remote.http.HttpClient;47import org.openqa.selenium.remote.http.HttpHandler;48import org.openqa.selenium.remote.http.HttpResponse;49import org.openqa.selenium.remote.http.Route;50import org.openqa.selenium.remote.tracing.Tracer;51import java.time.Duration;52import java.time.temporal.ChronoUnit;53import java.util.Collections;54import java.util.Set;55import java.util.concurrent.Executors;56import java.util.logging.Logger;57import static java.net.HttpURLConnection.HTTP_INTERNAL_ERROR;58import static java.net.HttpURLConnection.HTTP_NO_CONTENT;59import static org.openqa.selenium.grid.config.StandardGridRoles.EVENT_BUS_ROLE;60import static org.openqa.selenium.grid.config.StandardGridRoles.HTTPD_ROLE;61import static org.openqa.selenium.grid.config.StandardGridRoles.NODE_ROLE;62import static org.openqa.selenium.grid.data.Availability.DOWN;63import static org.openqa.selenium.remote.http.Route.get;64@AutoService(CliCommand.class)65public class NodeServer extends TemplateGridServerCommand {66 private static final Logger LOG = Logger.getLogger(NodeServer.class.getName());67 private Node node;68 private EventBus bus;69 @Override70 public String getName() {71 return "node";72 }73 @Override74 public String getDescription() {75 return "Adds this server as a node in the selenium grid.";76 }77 @Override78 public Set<Role> getConfigurableRoles() {79 return ImmutableSet.of(EVENT_BUS_ROLE, HTTPD_ROLE, NODE_ROLE);80 }81 @Override82 public Set<Object> getFlagObjects() {83 return Collections.emptySet();84 }85 @Override86 protected String getSystemPropertiesConfigPrefix() {87 return "node";88 }89 @Override90 protected Config getDefaultConfig() {91 return new DefaultNodeConfig();92 }93 @Override94 protected Handlers createHandlers(Config config) {95 LoggingOptions loggingOptions = new LoggingOptions(config);96 Tracer tracer = loggingOptions.getTracer();97 EventBusOptions events = new EventBusOptions(config);98 this.bus = events.getEventBus();99 NetworkOptions networkOptions = new NetworkOptions(config);100 HttpClient.Factory clientFactory = networkOptions.getHttpClientFactory(tracer);101 BaseServerOptions serverOptions = new BaseServerOptions(config);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:NodeFlags.java Github

copy

Full Screen

...25import java.util.HashSet;26import java.util.List;27import java.util.Set;28import static org.openqa.selenium.grid.config.StandardGridRoles.NODE_ROLE;29import static org.openqa.selenium.grid.node.config.NodeOptions.DEFAULT_DETECT_DRIVERS;30import static org.openqa.selenium.grid.node.config.NodeOptions.DEFAULT_HEARTBEAT_PERIOD;31import static org.openqa.selenium.grid.node.config.NodeOptions.DEFAULT_MAX_SESSIONS;32import static org.openqa.selenium.grid.node.config.NodeOptions.DEFAULT_REGISTER_CYCLE;33import static org.openqa.selenium.grid.node.config.NodeOptions.DEFAULT_REGISTER_PERIOD;34import static org.openqa.selenium.grid.node.config.NodeOptions.DEFAULT_SESSION_TIMEOUT;35import static org.openqa.selenium.grid.node.config.NodeOptions.NODE_SECTION;36import static org.openqa.selenium.grid.node.config.NodeOptions.OVERRIDE_MAX_SESSIONS;37@SuppressWarnings("unused")38@AutoService(HasRoles.class)39public class NodeFlags implements HasRoles {40 @Parameter(41 names = {"--max-sessions"},42 description = "Maximum number of concurrent sessions. Default value is the number "43 + "of available processors.")44 @ConfigValue(section = NODE_SECTION, name = "max-sessions", example = "8")45 public int maxSessions = DEFAULT_MAX_SESSIONS;46 @Parameter(47 names = {"--override-max-sessions"},48 arity = 1,49 description = "The # of available processos is the recommended max sessions value (1 browser "50 + "session per processor). Setting this flag to true allows the recommended max "51 + "value to be overwritten. Session stability and reliability might suffer as "52 + "the host could run out of resources.")53 @ConfigValue(section = NODE_SECTION, name = "override-max-sessions", example = "false")54 public Boolean overrideMaxSessions = OVERRIDE_MAX_SESSIONS;55 @Parameter(56 names = {"--session-timeout"},57 description = "Let X be the session-timeout in seconds. The Node will automatically kill "58 + "a session that has not had any activity in the last X seconds. " +59 "This will release the slot for other tests.")60 @ConfigValue(section = NODE_SECTION, name = "session-timeout", example = "60")61 public int sessionTimeout = DEFAULT_SESSION_TIMEOUT;62 @Parameter(63 names = {"--detect-drivers"}, arity = 1,64 description = "Autodetect which drivers are available on the current system, " +65 "and add them to the Node.")66 @ConfigValue(section = NODE_SECTION, name = "detect-drivers", example = "true")67 public Boolean autoconfigure = DEFAULT_DETECT_DRIVERS;68 @Parameter(69 names = {"-I", "--driver-implementation"},70 description = "Drivers that should be checked. If specified, will skip autoconfiguration. " +71 "Example: -I \"firefox\" -I \"chrome\"")72 @ConfigValue(73 section = NODE_SECTION,74 name = "driver-implementation",75 example = "[\"firefox\", \"chrome\"]")76 public Set<String> driverNames = new HashSet<>();77 @Parameter(78 names = {"--driver-factory"},79 description = "Mapping of fully qualified class name to a browser configuration that this " +80 "matches against. " +81 "--driver-factory org.openqa.selenium.example.LynxDriverFactory " +82 "'{\"browserName\": \"lynx\"}'",83 arity = 2,84 variableArity = true,85 splitter = NonSplittingSplitter.class)86 @ConfigValue(87 section = NODE_SECTION,88 name = "driver-factories",89 example = "[\"org.openqa.selenium.example.LynxDriverFactory '{\"browserName\": \"lynx\"}']")90 public List<String> driverFactory2Config;91 @Parameter(92 names = {"--grid-url"},93 description = "Public URL of the Grid as a whole (typically the address of the Hub " +94 "or the Router)")95 @ConfigValue(section = NODE_SECTION, name = "grid-url", example = "\"https://grid.example.com\"")96 public String gridUri;97 @Parameter(98 names = {"--driver-configuration"},99 description = "List of configured drivers a Node supports. " +100 "It is recommended to provide this type of configuration through a toml config " +101 "file to improve readability. Command line example: " +102 "--drivers-configuration name=\"Firefox Nightly\" max-sessions=2 " +103 "stereotype='{\"browserName\": \"firefox\", \"browserVersion\": \"86\", " +104 "\"moz:firefoxOptions\": " +105 "{\"binary\":\"/Applications/Firefox Nightly.app/Contents/MacOS/firefox-bin\"}}'",106 arity = 3,107 variableArity = true,108 splitter = NonSplittingSplitter.class)109 @ConfigValue(110 section = NODE_SECTION,111 name = "driver-configuration",112 prefixed = true,113 example = "\n" +114 "name = \"Firefox Nightly\"\n" +115 "max-sessions = 2\n" +116 "stereotype = \"{\"browserName\": \"firefox\", \"browserVersion\": \"86\", " +117 "\"moz:firefoxOptions\": " +118 "{\"binary\":\"/Applications/Firefox Nightly.app/Contents/MacOS/firefox-bin\"}}\"")119 public List<String> driverConfiguration;120 @Parameter(121 names = "--register-cycle",122 description = "How often, in seconds, the Node will try to register itself for "123 + "the first time to the Distributor.")124 @ConfigValue(section = NODE_SECTION, name = "register-cycle", example = "10")125 public int registerCycle = DEFAULT_REGISTER_CYCLE;126 @Parameter(127 names = "--register-period",128 description = "How long, in seconds, will the Node try to register to the Distributor for " +129 "the first time. After this period is completed, the Node will not attempt " +130 "to register again.")131 @ConfigValue(section = NODE_SECTION, name = "register-period", example = "120")132 public int registerPeriod = DEFAULT_REGISTER_PERIOD;133 @Parameter(134 names = "--heartbeat-period",135 description = "How often, in seconds, will the Node send heartbeat events to the Distributor " +136 "to inform it that the Node is up.")137 @ConfigValue(section = NODE_SECTION, name = "heartbeat-period", example = "10")138 public int heartbeatPeriod = DEFAULT_HEARTBEAT_PERIOD;139 @Override140 public Set<Role> getRoles() {141 return Collections.singleton(NODE_ROLE);142 }143}...

Full Screen

Full Screen

Source:GraphqlHandlerTest.java Github

copy

Full Screen

...24import org.openqa.selenium.grid.data.CreateSessionRequest;25import org.openqa.selenium.grid.distributor.Distributor;26import org.openqa.selenium.grid.distributor.local.LocalDistributor;27import org.openqa.selenium.grid.node.ActiveSession;28import org.openqa.selenium.grid.node.Node;29import org.openqa.selenium.grid.node.SessionFactory;30import org.openqa.selenium.grid.node.local.LocalNode;31import org.openqa.selenium.grid.security.Secret;32import org.openqa.selenium.grid.sessionmap.SessionMap;33import org.openqa.selenium.grid.sessionmap.local.LocalSessionMap;34import org.openqa.selenium.json.Json;35import org.openqa.selenium.remote.http.Contents;36import org.openqa.selenium.remote.http.HttpClient;37import org.openqa.selenium.remote.http.HttpHandler;38import org.openqa.selenium.remote.http.HttpRequest;39import org.openqa.selenium.remote.http.HttpResponse;40import org.openqa.selenium.remote.tracing.DefaultTestTracer;41import org.openqa.selenium.remote.tracing.Tracer;42import java.net.URI;43import java.net.URISyntaxException;44import java.util.List;45import java.util.Map;46import java.util.Optional;47import static org.assertj.core.api.Assertions.assertThat;48import static org.openqa.selenium.json.Json.MAP_TYPE;49import static org.openqa.selenium.remote.http.HttpMethod.GET;50public class GraphqlHandlerTest {51 private final Secret registrationSecret = new Secret("stilton");52 private final URI publicUri = new URI("http://example.com/grid-o-matic");53 private Distributor distributor;54 private Tracer tracer;55 private EventBus events;56 public GraphqlHandlerTest() throws URISyntaxException {57 }58 @Before59 public void setupGrid() {60 tracer = DefaultTestTracer.createTracer();61 events = new GuavaEventBus();62 HttpClient.Factory clientFactory = HttpClient.Factory.createDefault();63 SessionMap sessions = new LocalSessionMap(tracer, events);64 distributor = new LocalDistributor(tracer, events, clientFactory, sessions, registrationSecret);65 }66 @Test67 public void shouldBeAbleToGetGridUri() {68 GraphqlHandler handler = new GraphqlHandler(distributor, publicUri);69 Map<String, Object> topLevel = executeQuery(handler, "{ grid { uri } }");70 assertThat(topLevel).isEqualTo(Map.of("data", Map.of("grid", Map.of("uri", publicUri.toString()))));71 }72 @Test73 public void shouldReturnAnEmptyListForNodesIfNoneAreRegistered() {74 GraphqlHandler handler = new GraphqlHandler(distributor, publicUri);75 Map<String, Object> topLevel = executeQuery(handler, "{ grid { nodes { uri } } }");76 assertThat(topLevel)77 .describedAs(topLevel.toString())78 .isEqualTo(Map.of("data", Map.of("grid", Map.of("nodes", List.of()))));79 }80 @Test81 public void shouldBeAbleToGetUrlsOfAllNodes() throws URISyntaxException {82 Capabilities stereotype = new ImmutableCapabilities("cheese", "stilton");83 String nodeUri = "http://localhost:5556";84 Node node = LocalNode.builder(tracer, events, new URI(nodeUri), publicUri, registrationSecret)85 .add(stereotype, new SessionFactory() {86 @Override87 public Optional<ActiveSession> apply(CreateSessionRequest createSessionRequest) {88 return Optional.empty();89 }90 @Override91 public boolean test(Capabilities capabilities) {92 return false;93 }94 })95 .build();96 distributor.add(node);97 GraphqlHandler handler = new GraphqlHandler(distributor, publicUri);98 Map<String, Object> topLevel = executeQuery(handler, "{ grid { nodes { uri } } }");...

Full Screen

Full Screen

Source:LocalNodeFactory.java Github

copy

Full Screen

...20import org.openqa.selenium.WebDriverInfo;21import org.openqa.selenium.grid.config.Config;22import org.openqa.selenium.grid.docker.DockerOptions;23import org.openqa.selenium.grid.log.LoggingOptions;24import org.openqa.selenium.grid.node.Node;25import org.openqa.selenium.grid.node.SessionFactory;26import org.openqa.selenium.grid.node.config.DriverServiceSessionFactory;27import org.openqa.selenium.grid.node.config.NodeOptions;28import org.openqa.selenium.grid.server.BaseServerOptions;29import org.openqa.selenium.grid.server.EventBusOptions;30import org.openqa.selenium.grid.server.NetworkOptions;31import org.openqa.selenium.remote.http.HttpClient;32import org.openqa.selenium.remote.service.DriverService;33import org.openqa.selenium.remote.tracing.Tracer;34import java.util.ArrayList;35import java.util.Collection;36import java.util.List;37import java.util.ServiceLoader;38public class LocalNodeFactory {39 public static Node create(Config config) {40 LoggingOptions loggingOptions = new LoggingOptions(config);41 EventBusOptions eventOptions = new EventBusOptions(config);42 BaseServerOptions serverOptions = new BaseServerOptions(config);43 NodeOptions nodeOptions = new NodeOptions(config);44 NetworkOptions networkOptions = new NetworkOptions(config);45 Tracer tracer = loggingOptions.getTracer();46 HttpClient.Factory clientFactory = networkOptions.getHttpClientFactory(tracer);47 LocalNode.Builder builder = LocalNode.builder(48 tracer,49 eventOptions.getEventBus(),50 serverOptions.getExternalUri(),51 nodeOptions.getPublicGridUri().orElseGet(serverOptions::getExternalUri),52 serverOptions.getRegistrationSecret());53 List<DriverService.Builder<?, ?>> builders = new ArrayList<>();54 ServiceLoader.load(DriverService.Builder.class).forEach(builders::add);55 nodeOptions.getSessionFactories(info -> createSessionFactory(tracer, clientFactory, builders, info))56 .forEach((caps, factories) -> factories.forEach(factory -> builder.add(caps, factory)));57 new DockerOptions(config).getDockerSessionFactories(tracer, clientFactory)58 .forEach((caps, factories) -> factories.forEach(factory -> builder.add(caps, factory)));59 return builder.build();60 }61 private static Collection<SessionFactory> createSessionFactory(...

Full Screen

Full Screen

Source:DriverServiceSessionFactory.java Github

copy

Full Screen

1// Licensed to the Software Freedom Conservancy (SFC) under one2// or more contributor license agreements. See the NOTICE file3// distributed with this work for additional information4// regarding copyright ownership. The SFC licenses this file5// to you under the Apache License, Version 2.0 (the6// "License"); you may not use this file except in compliance7// with the License. You may obtain a copy of the License at8//9// http://www.apache.org/licenses/LICENSE-2.010//11// Unless required by applicable law or agreed to in writing,12// software distributed under the License is distributed on an13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY14// KIND, either express or implied. See the License for the15// specific language governing permissions and limitations16// under the License.17package org.openqa.selenium.grid.node.config;18import org.openqa.selenium.Capabilities;19import org.openqa.selenium.ImmutableCapabilities;20import org.openqa.selenium.grid.data.CreateSessionRequest;21import org.openqa.selenium.grid.node.ActiveSession;22import org.openqa.selenium.grid.node.ProtocolConvertingSession;23import org.openqa.selenium.grid.node.SessionFactory;24import org.openqa.selenium.remote.Command;25import org.openqa.selenium.remote.Dialect;26import org.openqa.selenium.remote.DriverCommand;27import org.openqa.selenium.remote.ProtocolHandshake;28import org.openqa.selenium.remote.Response;29import org.openqa.selenium.remote.SessionId;30import org.openqa.selenium.remote.http.HttpClient;31import org.openqa.selenium.remote.service.DriverService;32import java.util.Map;33import java.util.Objects;34import java.util.Optional;35import java.util.Set;36import java.util.function.Predicate;37public class DriverServiceSessionFactory implements SessionFactory {38 private final HttpClient.Factory clientFactory;39 private final Predicate<Capabilities> predicate;40 private final DriverService.Builder builder;41 public DriverServiceSessionFactory(42 HttpClient.Factory clientFactory,43 Predicate<Capabilities> predicate,44 DriverService.Builder builder) {45 this.clientFactory = Objects.requireNonNull(clientFactory);46 this.predicate = Objects.requireNonNull(predicate);47 this.builder = Objects.requireNonNull(builder);48 }49 @Override50 public boolean test(Capabilities capabilities) {51 return predicate.test(capabilities);52 }53 @Override54 public Optional<ActiveSession> apply(CreateSessionRequest sessionRequest) {55 if (sessionRequest.getDownstreamDialects().isEmpty()) {56 return Optional.empty();57 }58 DriverService service = builder.build();59 try {60 service.start();61 HttpClient client = clientFactory.createClient(service.getUrl());62 Command command = new Command(63 null,64 DriverCommand.NEW_SESSION(sessionRequest.getCapabilities()));65 ProtocolHandshake.Result result = new ProtocolHandshake().createSession(client, command);66 Set<Dialect> downstreamDialects = sessionRequest.getDownstreamDialects();67 Dialect upstream = result.getDialect();68 Dialect downstream = downstreamDialects.contains(result.getDialect()) ?69 result.getDialect() :70 downstreamDialects.iterator().next();71 Response response = result.createResponse();72 return Optional.of(73 new ProtocolConvertingSession(74 client,75 new SessionId(response.getSessionId()),76 service.getUrl(),77 downstream,78 upstream,79 new ImmutableCapabilities((Map<?, ?>)response.getValue())) {80 @Override81 public void stop() {82 // no-op83 }84 });85 } catch (Exception e) {86 service.stop();87 return Optional.empty();88 }89 }90}...

Full Screen

Full Screen

Source:SauceNodeFactory.java Github

copy

Full Screen

1package com.saucelabs.grid;2import org.openqa.selenium.grid.config.Config;3import org.openqa.selenium.grid.log.LoggingOptions;4import org.openqa.selenium.grid.node.Node;5import org.openqa.selenium.grid.node.config.NodeOptions;6import org.openqa.selenium.grid.node.relay.RelayOptions;7import org.openqa.selenium.grid.security.SecretOptions;8import org.openqa.selenium.grid.server.BaseServerOptions;9import org.openqa.selenium.grid.server.EventBusOptions;10import org.openqa.selenium.grid.server.NetworkOptions;11import org.openqa.selenium.remote.http.HttpClient;12import org.openqa.selenium.remote.tracing.Tracer;13@SuppressWarnings("unused")14public class SauceNodeFactory {15 public static Node create(Config config) {16 LoggingOptions loggingOptions = new LoggingOptions(config);17 EventBusOptions eventOptions = new EventBusOptions(config);18 BaseServerOptions serverOptions = new BaseServerOptions(config);19 NodeOptions nodeOptions = new NodeOptions(config);20 NetworkOptions networkOptions = new NetworkOptions(config);21 SecretOptions secretOptions = new SecretOptions(config);22 Tracer tracer = loggingOptions.getTracer();23 HttpClient.Factory clientFactory = networkOptions.getHttpClientFactory(tracer);24 SauceDockerOptions sauceDockerOptions = new SauceDockerOptions(config);25 SauceNode.Builder builder = SauceNode.builder(26 tracer,27 eventOptions.getEventBus(),28 serverOptions.getExternalUri(),29 nodeOptions.getPublicGridUri().orElseGet(serverOptions::getExternalUri),30 secretOptions.getRegistrationSecret())31 .maximumConcurrentSessions(nodeOptions.getMaxSessions())32 .sessionTimeout(nodeOptions.getSessionTimeout())33 .heartbeatPeriod(nodeOptions.getHeartbeatPeriod());34 sauceDockerOptions.getDockerSessionFactories(tracer, clientFactory)35 .forEach((caps, factories) -> factories.forEach(factory -> builder.add(caps, factory)));36 if (config.getAll("relay", "configs").isPresent()) {37 new RelayOptions(config).getSessionFactories(tracer, clientFactory)38 .forEach((caps, factories) -> factories.forEach(factory -> builder.add(caps, factory)));39 }...

Full Screen

Full Screen

Node

Using AI Code Generation

copy

Full Screen

1package org.openqa.selenium.grid.node;2import org.openqa.selenium.Capabilities;3import org.openqa.selenium.ImmutableCapabilities;4import org.openqa.selenium.events.EventBus;5import org.openqa.selenium.grid.data.Availability;6import org.openqa.selenium.grid.data.CreateSessionRequest;7import org.openqa.selenium.grid.data.NodeStatusEvent;8import org.openqa.selenium.grid.data.Session;9import org.openqa.selenium.grid.data.SessionId;10import org.openqa.selenium.grid.data.SessionRequest;11import org.openqa.selenium.grid.data.SessionRequestEvent;12import org.openqa.selenium.grid.data.SessionRequestListener;13import org.openqa.selenium.grid.data.SessionRequestTimeEvent;14import org.openqa.selenium.grid.data.SessionStartedEvent;15import org.openqa.selenium.grid.data.SessionTerminatedEvent;16import org.openqa.selenium.grid.data.Slot;17import org.openqa.selenium.grid.data.SlotId;18import org.openqa.selenium.grid.security.Secret;19import org.openqa.selenium.internal.Require;20import org.openqa.selenium.json.Json;21import org.openqa.selenium.remote.http.HttpClient;22import org.openqa.selenium.remote.tracing.Tracer;23import java.net.URI;24import java.time.Duration;25import java.time.Instant;26import java.util.ArrayList;27import java.util.Collection;28import java.util.Collections;29import java.util.HashMap;30import java.util.Map;31import java.util.Objects;32import java.util.Optional;33import java.util.UUID;34import java.util.concurrent.ConcurrentHashMap;35import java.util.concurrent.ConcurrentMap;36import java.util.concurrent.CopyOnWriteArrayList;37import java.util.concurrent.ThreadLocalRandom;38import java.util.concurrent.atomic.AtomicBoolean;39import java.util.concurrent.atomic.AtomicInteger;40import java.util.function.Supplier;41import java.util.logging.Logger;42import java.util.stream.Collectors;43import static java.util.logging.Level.FINE;44import static org.openqa.selenium.grid.data.Availability.DOWN;45import static org.openqa.selenium.grid.data.Availability.UP;46import static org.openqa.selenium.grid.data.Slot.toSlotId;47import static org.openqa.selenium.grid.node.NodeStatusEvent.NODE_DOWN;48import static org.openqa.selenium.grid.node.NodeStatusEvent.NODE_STATUS;49import static org.openqa.selenium.grid.node.NodeStatusEvent.NODE_UP;50import static org.openqa.selenium.remote.http.Contents.asJson;51import static org.openqa.selenium.remote.http.Contents.bytes;52import static org.openqa.selenium.remote.http.Contents.string;53import static org

Full Screen

Full Screen

Node

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.grid.node.Node;2import org.openqa.selenium.grid.node.config.NodeOptions;3import org.openqa.selenium.remote.http.HttpClient;4import java.net.URL;5public class NodeExample {6 public static void main(String[] args) {7 HttpClient client = HttpClient.Factory.createDefault().createClient(nodeUrl);8 NodeOptions nodeOptions = new NodeOptions();9 nodeOptions.setHub(hubUrl);10 nodeOptions.setUrl(nodeUrl);11 nodeOptions.setClient(client);12 Node node = new Node(nodeOptions);13 node.start();14 node.stop();15 }16}17import org.openqa.selenium.grid.node.Node;18import org.openqa.selenium.grid.node.config.NodeOptions;19import org.openqa.selenium.remote.http.HttpClient;20import java.net.URL;21public class NodeExample {22 public static void main(String[] args) {23 HttpClient client = HttpClient.Factory.createDefault().createClient(nodeUrl);24 NodeOptions nodeOptions = new NodeOptions();25 nodeOptions.setHub(hubUrl);26 nodeOptions.setUrl(nodeUrl);27 nodeOptions.setClient(client);28 Node node = new Node(nodeOptions);

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful