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

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

Source:Standalone.java Github

copy

Full Screen

...37import org.openqa.selenium.grid.distributor.local.LocalDistributor;38import org.openqa.selenium.grid.graphql.GraphqlHandler;39import org.openqa.selenium.grid.log.LoggingOptions;40import org.openqa.selenium.grid.node.Node;41import org.openqa.selenium.grid.node.ProxyNodeWebsockets;42import org.openqa.selenium.grid.node.config.NodeOptions;43import org.openqa.selenium.grid.router.Router;44import org.openqa.selenium.grid.security.BasicAuthenticationFilter;45import org.openqa.selenium.grid.security.Secret;46import org.openqa.selenium.grid.security.SecretOptions;47import org.openqa.selenium.grid.server.BaseServerOptions;48import org.openqa.selenium.grid.server.EventBusOptions;49import org.openqa.selenium.grid.server.NetworkOptions;50import org.openqa.selenium.grid.server.Server;51import org.openqa.selenium.grid.sessionmap.SessionMap;52import org.openqa.selenium.grid.sessionmap.local.LocalSessionMap;53import org.openqa.selenium.grid.sessionqueue.NewSessionQueue;54import org.openqa.selenium.grid.sessionqueue.config.NewSessionQueueOptions;55import org.openqa.selenium.grid.sessionqueue.local.LocalNewSessionQueue;56import org.openqa.selenium.grid.web.CombinedHandler;57import org.openqa.selenium.grid.web.GridUiRoute;58import org.openqa.selenium.grid.web.RoutableHttpClientFactory;59import org.openqa.selenium.internal.Require;60import org.openqa.selenium.remote.http.Contents;61import org.openqa.selenium.remote.http.HttpClient;62import org.openqa.selenium.remote.http.HttpHandler;63import org.openqa.selenium.remote.http.HttpResponse;64import org.openqa.selenium.remote.http.Routable;65import org.openqa.selenium.remote.http.Route;66import org.openqa.selenium.remote.tracing.Tracer;67import java.net.MalformedURLException;68import java.net.URI;69import java.net.URL;70import java.util.Collections;71import java.util.Set;72import java.util.logging.Logger;73@AutoService(CliCommand.class)74public class Standalone extends TemplateGridServerCommand {75 private static final Logger LOG = Logger.getLogger("selenium");76 @Override77 public String getName() {78 return "standalone";79 }80 @Override81 public String getDescription() {82 return "The selenium server, running everything in-process.";83 }84 @Override85 public Set<Role> getConfigurableRoles() {86 return ImmutableSet.of(DISTRIBUTOR_ROLE, HTTPD_ROLE, NODE_ROLE, ROUTER_ROLE, SESSION_QUEUE_ROLE);87 }88 @Override89 public Set<Object> getFlagObjects() {90 return Collections.singleton(new StandaloneFlags());91 }92 @Override93 protected String getSystemPropertiesConfigPrefix() {94 return "selenium";95 }96 @Override97 protected Config getDefaultConfig() {98 return new DefaultStandaloneConfig();99 }100 @Override101 protected Handlers createHandlers(Config config) {102 LoggingOptions loggingOptions = new LoggingOptions(config);103 Tracer tracer = loggingOptions.getTracer();104 EventBusOptions events = new EventBusOptions(config);105 EventBus bus = events.getEventBus();106 BaseServerOptions serverOptions = new BaseServerOptions(config);107 SecretOptions secretOptions = new SecretOptions(config);108 Secret registrationSecret = secretOptions.getRegistrationSecret();109 URI localhost = serverOptions.getExternalUri();110 URL localhostUrl;111 try {112 localhostUrl = localhost.toURL();113 } catch (MalformedURLException e) {114 throw new IllegalArgumentException(e);115 }116 NetworkOptions networkOptions = new NetworkOptions(config);117 CombinedHandler combinedHandler = new CombinedHandler();118 HttpClient.Factory clientFactory = new RoutableHttpClientFactory(119 localhostUrl,120 combinedHandler,121 networkOptions.getHttpClientFactory(tracer));122 SessionMap sessions = new LocalSessionMap(tracer, bus);123 combinedHandler.addHandler(sessions);124 DistributorOptions distributorOptions = new DistributorOptions(config);125 NewSessionQueueOptions newSessionRequestOptions = new NewSessionQueueOptions(config);126 NewSessionQueue queue = new LocalNewSessionQueue(127 tracer,128 bus,129 distributorOptions.getSlotMatcher(),130 newSessionRequestOptions.getSessionRequestRetryInterval(),131 newSessionRequestOptions.getSessionRequestTimeout(),132 registrationSecret);133 combinedHandler.addHandler(queue);134 Distributor distributor = new LocalDistributor(135 tracer,136 bus,137 clientFactory,138 sessions,139 queue,140 distributorOptions.getSlotSelector(),141 registrationSecret,142 distributorOptions.getHealthCheckInterval(),143 distributorOptions.shouldRejectUnsupportedCaps(),144 newSessionRequestOptions.getSessionRequestRetryInterval());145 combinedHandler.addHandler(distributor);146 Routable router = new Router(tracer, clientFactory, sessions, queue, distributor)147 .with(networkOptions.getSpecComplianceChecks());148 HttpHandler readinessCheck = req -> {149 boolean ready = sessions.isReady() && distributor.isReady() && bus.isReady();150 return new HttpResponse()151 .setStatus(ready ? HTTP_OK : HTTP_INTERNAL_ERROR)152 .setContent(Contents.utf8String("Standalone is " + ready));153 };154 GraphqlHandler graphqlHandler = new GraphqlHandler(155 tracer,156 distributor,157 queue,158 serverOptions.getExternalUri(),159 getFormattedVersion());160 Routable ui = new GridUiRoute();161 Routable httpHandler = combine(162 ui,163 router,164 Route.prefix("/wd/hub").to(combine(router)),165 Route.options("/graphql").to(() -> graphqlHandler),166 Route.post("/graphql").to(() -> graphqlHandler));167 UsernameAndPassword uap = secretOptions.getServerAuthentication();168 if (uap != null) {169 LOG.info("Requiring authentication to connect");170 httpHandler = httpHandler.with(new BasicAuthenticationFilter(uap.username(), uap.password()));171 }172 // Allow the liveness endpoint to be reached, since k8s doesn't make it easy to authenticate these checks173 httpHandler = combine(httpHandler, Route.get("/readyz").to(() -> readinessCheck));174 Node node = new NodeOptions(config).getNode();175 combinedHandler.addHandler(node);176 distributor.add(node);177 return new Handlers(httpHandler, new ProxyNodeWebsockets(clientFactory, node));178 }179 @Override180 protected void execute(Config config) {181 Require.nonNull("Config", config);182 Server<?> server = asServer(config).start();183 LOG.info(String.format(184 "Started Selenium Standalone %s: %s",185 getFormattedVersion(),186 server.getUrl()));187 }188 private String getFormattedVersion() {189 BuildInfo info = new BuildInfo();190 return String.format("%s (revision %s)", info.getReleaseLabel(), info.getBuildRevision());191 }...

Full Screen

Full Screen

Source:NodeServer.java Github

copy

Full Screen

...41import org.openqa.selenium.grid.data.NodeStatusEvent;42import org.openqa.selenium.grid.log.LoggingOptions;43import org.openqa.selenium.grid.node.HealthCheck;44import org.openqa.selenium.grid.node.Node;45import org.openqa.selenium.grid.node.ProxyNodeWebsockets;46import org.openqa.selenium.grid.node.config.NodeOptions;47import org.openqa.selenium.grid.server.BaseServerOptions;48import org.openqa.selenium.grid.server.EventBusOptions;49import org.openqa.selenium.grid.server.NetworkOptions;50import org.openqa.selenium.grid.server.Server;51import org.openqa.selenium.internal.Require;52import org.openqa.selenium.netty.server.NettyServer;53import org.openqa.selenium.remote.http.Contents;54import org.openqa.selenium.remote.http.HttpClient;55import org.openqa.selenium.remote.http.HttpHandler;56import org.openqa.selenium.remote.http.HttpResponse;57import org.openqa.selenium.remote.http.Route;58import org.openqa.selenium.remote.tracing.Tracer;59import java.util.Collections;60import java.util.Set;61import java.util.concurrent.Executors;62import java.util.concurrent.atomic.AtomicBoolean;63import java.util.logging.Logger;64@AutoService(CliCommand.class)65public class NodeServer extends TemplateGridServerCommand {66 private static final Logger LOG = Logger.getLogger(NodeServer.class.getName());67 private final AtomicBoolean nodeRegistered = new AtomicBoolean(false);68 private Node node;69 private EventBus bus;70 private final Thread shutdownHook =71 new Thread(() -> bus.fire(new NodeRemovedEvent(node.getStatus())));72 @Override73 public String getName() {74 return "node";75 }76 @Override77 public String getDescription() {78 return "Adds this server as a node in the selenium grid.";79 }80 @Override81 public Set<Role> getConfigurableRoles() {82 return ImmutableSet.of(EVENT_BUS_ROLE, HTTPD_ROLE, NODE_ROLE);83 }84 @Override85 public Set<Object> getFlagObjects() {86 return Collections.emptySet();87 }88 @Override89 protected String getSystemPropertiesConfigPrefix() {90 return "node";91 }92 @Override93 protected Config getDefaultConfig() {94 return new DefaultNodeConfig();95 }96 @Override97 protected Handlers createHandlers(Config config) {98 LoggingOptions loggingOptions = new LoggingOptions(config);99 Tracer tracer = loggingOptions.getTracer();100 EventBusOptions events = new EventBusOptions(config);101 this.bus = events.getEventBus();102 NetworkOptions networkOptions = new NetworkOptions(config);103 HttpClient.Factory clientFactory = networkOptions.getHttpClientFactory(tracer);104 BaseServerOptions serverOptions = new BaseServerOptions(config);105 LOG.info("Reporting self as: " + serverOptions.getExternalUri());106 NodeOptions nodeOptions = new NodeOptions(config);107 this.node = nodeOptions.getNode();108 HttpHandler readinessCheck = req -> {109 if (node.getStatus().hasCapacity()) {110 return new HttpResponse()111 .setStatus(HTTP_NO_CONTENT);112 }113 return new HttpResponse()114 .setStatus(HTTP_INTERNAL_ERROR)115 .setHeader("Content-Type", MediaType.PLAIN_TEXT_UTF_8.toString())116 .setContent(Contents.utf8String("No capacity available"));117 };118 bus.addListener(NodeAddedEvent.listener(nodeId -> {119 if (node.getId().equals(nodeId)) {120 nodeRegistered.set(true);121 LOG.info("Node has been added");122 }123 }));124 bus.addListener(NodeDrainComplete.listener(nodeId -> {125 if (!node.getId().equals(nodeId)) {126 return;127 }128 // Wait a beat before shutting down so the final response from the129 // node can escape.130 new Thread(131 () -> {132 try {133 Thread.sleep(1000);134 } catch (InterruptedException e) {135 // Swallow, the next thing we're doing is shutting down136 }137 LOG.info("Shutting down");138 System.exit(0);139 },140 "Node shutdown: " + nodeId)141 .start();142 }));143 Route httpHandler = Route.combine(144 node,145 get("/readyz").to(() -> readinessCheck));146 return new Handlers(httpHandler, new ProxyNodeWebsockets(clientFactory, node));147 }148 @Override149 public Server<?> asServer(Config initialConfig) {150 Require.nonNull("Config", initialConfig);151 Config config = new MemoizedConfig(new CompoundConfig(initialConfig, getDefaultConfig()));152 NodeOptions nodeOptions = new NodeOptions(config);153 Handlers handler = createHandlers(config);154 return new NettyServer(155 new BaseServerOptions(config),156 handler.httpHandler,157 handler.websocketHandler) {158 @Override159 public NettyServer start() {160 super.start();...

Full Screen

Full Screen

Source:ProxyNodeWebsockets.java Github

copy

Full Screen

...39import java.util.function.Consumer;40import java.util.logging.Level;41import java.util.logging.Logger;42import java.util.stream.Stream;43public class ProxyNodeWebsockets implements BiFunction<String, Consumer<Message>,44 Optional<Consumer<Message>>> {45 private static final UrlTemplate CDP_TEMPLATE = new UrlTemplate("/session/{sessionId}/se/cdp");46 private static final UrlTemplate FWD_TEMPLATE = new UrlTemplate("/session/{sessionId}/se/fwd");47 private static final UrlTemplate VNC_TEMPLATE = new UrlTemplate("/session/{sessionId}/se/vnc");48 private static final Logger LOG = Logger.getLogger(ProxyNodeWebsockets.class.getName());49 private static final ImmutableSet<String> CDP_ENDPOINT_CAPS =50 ImmutableSet.of("goog:chromeOptions",51 "moz:debuggerAddress",52 "ms:edgeOptions");53 private final HttpClient.Factory clientFactory;54 private final Node node;55 public ProxyNodeWebsockets(HttpClient.Factory clientFactory, Node node) {56 this.clientFactory = Objects.requireNonNull(clientFactory);57 this.node = Objects.requireNonNull(node);58 }59 @Override60 public Optional<Consumer<Message>> apply(String uri, Consumer<Message> downstream) {61 UrlTemplate.Match fwdMatch = FWD_TEMPLATE.match(uri);62 UrlTemplate.Match cdpMatch = CDP_TEMPLATE.match(uri);63 UrlTemplate.Match vncMatch = VNC_TEMPLATE.match(uri);64 if (cdpMatch == null && vncMatch == null && fwdMatch == null) {65 return Optional.empty();66 }67 String sessionId = Stream.of(fwdMatch, cdpMatch, vncMatch)68 .filter(Objects::nonNull)69 .findFirst()...

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.

Most used methods in ProxyNodeWebsockets

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful