How to use Route class of org.openqa.selenium.remote.http package

Best Selenium code snippet using org.openqa.selenium.remote.http.Route

Source:Node.java Github

copy

Full Screen

...27import org.openqa.selenium.remote.http.HttpHandler;28import org.openqa.selenium.remote.http.HttpRequest;29import org.openqa.selenium.remote.http.HttpResponse;30import org.openqa.selenium.remote.http.Routable;31import org.openqa.selenium.remote.http.Route;32import org.openqa.selenium.remote.tracing.DistributedTracer;33import java.net.URI;34import java.util.Objects;35import java.util.Optional;36import java.util.UUID;37import static org.openqa.selenium.remote.HttpSessionId.getSessionId;38import static org.openqa.selenium.remote.http.Contents.utf8String;39import static org.openqa.selenium.remote.http.Route.combine;40import static org.openqa.selenium.remote.http.Route.delete;41import static org.openqa.selenium.remote.http.Route.get;42import static org.openqa.selenium.remote.http.Route.matching;43import static org.openqa.selenium.remote.http.Route.post;44/**45 * A place where individual webdriver sessions are running. Those sessions may be in-memory, or46 * only reachable via localhost and a network. Or they could be something else entirely.47 * <p>48 * This class responds to the following URLs:49 * <table summary="HTTP commands the Node understands">50 * <tr>51 * <th>Verb</th>52 * <th>URL Template</th>53 * <th>Meaning</th>54 * </tr>55 * <tr>56 * <td>POST</td>57 * <td>/se/grid/node/session</td>58 * <td>Attempts to start a new session for the given node. The posted data should be a59 * json-serialized {@link Capabilities} instance. Returns a serialized {@link Session}.60 * Subclasses of {@code Node} are expected to register the session with the61 * {@link org.openqa.selenium.grid.sessionmap.SessionMap}.</td>62 * </tr>63 * <tr>64 * <td>GET</td>65 * <td>/se/grid/node/session/{sessionId}</td>66 * <td>Finds the {@link Session} identified by {@code sessionId} and returns the JSON-serialized67 * form.</td>68 * </tr>69 * <tr>70 * <td>DELETE</td>71 * <td>/se/grid/node/session/{sessionId}</td>72 * <td>Stops the {@link Session} identified by {@code sessionId}. It is expected that this will73 * also cause the session to removed from the74 * {@link org.openqa.selenium.grid.sessionmap.SessionMap}.</td>75 * </tr>76 * <tr>77 * <td>GET</td>78 * <td>/se/grid/node/owner/{sessionId}</td>79 * <td>Allows the node to be queried about whether or not it owns the {@link Session} identified80 * by {@code sessionId}. This returns a boolean.</td>81 * </tr>82 * <tr>83 * <td>*</td>84 * <td>/session/{sessionId}/*</td>85 * <td>The request is forwarded to the {@link Session} identified by {@code sessionId}. When the86 * Quit command is called, the {@link Session} should remove itself from the87 * {@link org.openqa.selenium.grid.sessionmap.SessionMap}.</td>88 * </tr>89 * </table>90 */91public abstract class Node implements Routable, HttpHandler {92 protected final DistributedTracer tracer;93 private final UUID id;94 private final URI uri;95 private final Route routes;96 protected Node(DistributedTracer tracer, UUID id, URI uri) {97 this.tracer = Objects.requireNonNull(tracer);98 this.id = Objects.requireNonNull(id);99 this.uri = Objects.requireNonNull(uri);100 Json json = new Json();101 routes = combine(102 // "getSessionId" is aggressive about finding session ids, so this needs to be the last103 // route the is checked.104 matching(req -> getSessionId(req.getUri()).map(SessionId::new).map(this::isSessionOwner).orElse(false))105 .to(() -> new ForwardWebDriverCommand(this)),106 get("/se/grid/node/owner/{sessionId}")107 .to((params) -> new IsSessionOwner(this, json, new SessionId(params.get("sessionId")))),108 delete("/se/grid/node/session/{sessionId}")109 .to((params) -> new StopNodeSession(this, new SessionId(params.get("sessionId")))),...

Full Screen

Full Screen

Source:JreAppServer.java Github

copy

Full Screen

...29import org.openqa.selenium.remote.http.HttpHandler;30import org.openqa.selenium.remote.http.HttpMethod;31import org.openqa.selenium.remote.http.HttpRequest;32import org.openqa.selenium.remote.http.HttpResponse;33import org.openqa.selenium.remote.http.Route;34import java.io.IOException;35import java.io.UncheckedIOException;36import java.net.MalformedURLException;37import java.net.URL;38import java.nio.file.Path;39import static com.google.common.net.HttpHeaders.CONTENT_TYPE;40import static com.google.common.net.MediaType.JSON_UTF_8;41import static java.nio.charset.StandardCharsets.UTF_8;42import static java.util.Collections.singletonMap;43import static org.openqa.selenium.build.InProject.locate;44import static org.openqa.selenium.remote.http.Contents.bytes;45import static org.openqa.selenium.remote.http.Contents.string;46import static org.openqa.selenium.remote.http.Route.get;47import static org.openqa.selenium.remote.http.Route.matching;48import static org.openqa.selenium.remote.http.Route.post;49public class JreAppServer implements AppServer {50 private final Server<?> server;51 public JreAppServer() {52 this(emulateJettyAppServer());53 }54 public JreAppServer(HttpHandler handler) {55 Require.nonNull("Handler", handler);56 int port = PortProber.findFreePort();57 server = new JreServer(58 new BaseServerOptions(new MapConfig(singletonMap("server", singletonMap("port", port)))),59 handler);60 }61 private static Route emulateJettyAppServer() {62 Path common = locate("common/src/web").toAbsolutePath();63 return Route.combine(64 new ResourceHandler(new PathResource(common)),65 get("/encoding").to(EncodingHandler::new),66 matching(req -> req.getUri().startsWith("/page/")).to(PageHandler::new),67 get("/redirect").to(() -> new RedirectHandler()),68 get("/sleep").to(SleepingHandler::new),69 post("/upload").to(UploadHandler::new));70 }71 @Override72 public void start() {73 server.start();74 }75 @Override76 public void stop() {77 server.stop();...

Full Screen

Full Screen

Source:NewSessionQueue.java Github

copy

Full Screen

...27import org.openqa.selenium.internal.Require;28import org.openqa.selenium.remote.http.HttpRequest;29import org.openqa.selenium.remote.http.HttpResponse;30import org.openqa.selenium.remote.http.Routable;31import org.openqa.selenium.remote.http.Route;32import org.openqa.selenium.remote.tracing.Tracer;33import org.openqa.selenium.status.HasReadyState;34import java.time.Instant;35import java.util.List;36import java.util.Map;37import java.util.Optional;38import java.util.Set;39import java.util.UUID;40import static org.openqa.selenium.remote.http.Route.combine;41import static org.openqa.selenium.remote.http.Route.delete;42import static org.openqa.selenium.remote.http.Route.get;43import static org.openqa.selenium.remote.http.Route.post;44public abstract class NewSessionQueue implements HasReadyState, Routable {45 protected final Tracer tracer;46 private final Route routes;47 protected NewSessionQueue(Tracer tracer, Secret registrationSecret) {48 this.tracer = Require.nonNull("Tracer", tracer);49 Require.nonNull("Registration secret", registrationSecret);50 RequiresSecretFilter requiresSecret = new RequiresSecretFilter(registrationSecret);51 routes = combine(52 post("/session")53 .to(() -> req -> {54 SessionRequest sessionRequest = new SessionRequest(55 new RequestId(UUID.randomUUID()),56 req,57 Instant.now()58 );59 return addToQueue(sessionRequest);60 }),...

Full Screen

Full Screen

Source:Distributor.java Github

copy

Full Screen

...26import org.openqa.selenium.remote.http.HttpHandler;27import org.openqa.selenium.remote.http.HttpRequest;28import org.openqa.selenium.remote.http.HttpResponse;29import org.openqa.selenium.remote.http.Routable;30import org.openqa.selenium.remote.http.Route;31import org.openqa.selenium.remote.tracing.SpanDecorator;32import java.io.UncheckedIOException;33import java.util.Objects;34import java.util.UUID;35import java.util.function.Predicate;36import static org.openqa.selenium.remote.http.Contents.bytes;37import static org.openqa.selenium.remote.http.Route.delete;38import static org.openqa.selenium.remote.http.Route.get;39import static org.openqa.selenium.remote.http.Route.post;40/**41 * Responsible for being the central place where the {@link Node}s on which {@link Session}s run42 * are determined.43 * <p>44 * This class responds to the following URLs:45 * <table summary="HTTP commands the Distributor understands">46 * <tr>47 * <th>Verb</th>48 * <th>URL Template</th>49 * <th>Meaning</th>50 * </tr>51 * <tr>52 * <td>POST</td>53 * <td>/session</td>54 * <td>This is exactly the same as the New Session command from the WebDriver spec.</td>55 * </tr>56 * <tr>57 * <td>POST</td>58 * <td>/se/grid/distributor/node</td>59 * <td>Adds a new {@link Node} to this distributor. Please read the javadocs for {@link Node} for60 * how the Node should be serialized.</td>61 * </tr>62 * <tr>63 * <td>DELETE</td>64 * <td>/se/grid/distributor/node/{nodeId}</td>65 * <td>Remove the {@link Node} identified by {@code nodeId} from this distributor. It is expected66 * that any sessions running on the Node are allowed to complete: this simply means that no new67 * sessions will be scheduled on this Node.</td>68 * </tr>69 * </table>70 */71public abstract class Distributor implements Predicate<HttpRequest>, Routable, HttpHandler {72 private final Route routes;73 protected final Tracer tracer;74 protected Distributor(Tracer tracer, HttpClient.Factory httpClientFactory) {75 this.tracer = Objects.requireNonNull(tracer, "Tracer to use must be set.");76 Objects.requireNonNull(httpClientFactory);77 Json json = new Json();78 routes = Route.combine(79 post("/session").to(() -> req -> {80 CreateSessionResponse sessionResponse = newSession(req);81 return new HttpResponse().setContent(bytes(sessionResponse.getDownstreamEncodedResponse()));82 }),83 post("/se/grid/distributor/session")84 .to(() -> new CreateSession(this)),85 post("/se/grid/distributor/node")86 .to(() -> new AddNode(tracer, this, json, httpClientFactory)),87 delete("/se/grid/distributor/node/{nodeId}")88 .to(params -> new RemoveNode(this, UUID.fromString(params.get("nodeId")))),89 get("/se/grid/distributor/status")90 .to(() -> new GetDistributorStatus(this))91 .with(new SpanDecorator(tracer, req -> "distributor.status")));92 }...

Full Screen

Full Screen

Source:SessionMap.java Github

copy

Full Screen

...23import org.openqa.selenium.remote.http.HttpHandler;24import org.openqa.selenium.remote.http.HttpRequest;25import org.openqa.selenium.remote.http.HttpResponse;26import org.openqa.selenium.remote.http.Routable;27import org.openqa.selenium.remote.http.Route;28import org.openqa.selenium.remote.tracing.Tracer;29import org.openqa.selenium.status.HasReadyState;30import java.net.URI;31import java.util.Map;32import static org.openqa.selenium.remote.http.Route.combine;33import static org.openqa.selenium.remote.http.Route.delete;34import static org.openqa.selenium.remote.http.Route.post;35/**36 * Provides a stable API for looking up where on the Grid a particular webdriver instance is37 * running.38 * <p>39 * This class responds to the following URLs:40 * <table summary="HTTP commands the SessionMap understands">41 * <tr>42 * <th>Verb</th>43 * <th>URL Template</th>44 * <th>Meaning</th>45 * </tr>46 * <tr>47 * <td>DELETE</td>48 * <td>/se/grid/session/{sessionId}</td>49 * <td>Removes a {@link URI} from the session map. Calling this method more than once for the same50 * {@link SessionId} will not throw an error.</td>51 * </tr>52 * <tr>53 * <td>GET</td>54 * <td>/se/grid/session/{sessionId}</td>55 * <td>Retrieves the {@link URI} associated the {@link SessionId}, or throws a56 * {@link org.openqa.selenium.NoSuchSessionException} should the session not be present.</td>57 * </tr>58 * <tr>59 * <td>POST</td>60 * <td>/se/grid/session/{sessionId}</td>61 * <td>Registers the session with session map. In theory, the session map never expires a session62 * from its mappings, but realistically, sessions may end up being removed for many reasons.63 * </td>64 * </tr>65 * </table>66 */67public abstract class SessionMap implements HasReadyState, Routable {68 protected final Tracer tracer;69 private final Route routes;70 public abstract boolean add(Session session);71 public abstract Session get(SessionId id) throws NoSuchSessionException;72 public abstract void remove(SessionId id);73 public URI getUri(SessionId id) throws NoSuchSessionException {74 return get(id).getUri();75 }76 public SessionMap(Tracer tracer) {77 this.tracer = Require.nonNull("Tracer", tracer);78 Json json = new Json();79 routes = combine(80 Route.get("/se/grid/session/{sessionId}/uri")81 .to(params -> new GetSessionUri(this, sessionIdFrom(params))),82 post("/se/grid/session")83 .to(() -> new AddToSessionMap(tracer, json, this)),84 Route.get("/se/grid/session/{sessionId}")85 .to(params -> new GetFromSessionMap(tracer, this, sessionIdFrom(params))),86 delete("/se/grid/session/{sessionId}")87 .to(params -> new RemoveFromSession(tracer, this, sessionIdFrom(params))));88 }89 private SessionId sessionIdFrom(Map<String, String> params) {90 return new SessionId(params.get("sessionId"));91 }92 @Override93 public boolean matches(HttpRequest req) {94 return routes.matches(req);95 }96 @Override97 public HttpResponse execute(HttpRequest req) {98 return routes.execute(req);...

Full Screen

Full Screen

Source:HandlersForTests.java Github

copy

Full Screen

...23import org.openqa.selenium.remote.http.Contents;24import org.openqa.selenium.remote.http.HttpRequest;25import org.openqa.selenium.remote.http.HttpResponse;26import org.openqa.selenium.remote.http.Routable;27import org.openqa.selenium.remote.http.Route;28import java.io.UncheckedIOException;29import java.nio.file.Path;30import static java.nio.charset.StandardCharsets.UTF_8;31import static org.openqa.selenium.remote.http.HttpMethod.GET;32public class HandlersForTests implements Routable {33 private static final String TEMP_SRC_CONTEXT_PATH = "/temp";34 private final Route delegate;35 public HandlersForTests(String hostname, int port, Path tempPageDir) {36 CreatePageHandler createPageHandler = new CreatePageHandler(37 tempPageDir,38 hostname,39 port,40 TEMP_SRC_CONTEXT_PATH);41 Routable generatedPages = new ResourceHandler(new PathResource(tempPageDir));42 Path webSrc = InProject.locate("common/src/web");43 Route route = Route.combine(44 Route.get("/basicAuth").to(() -> req ->45 new HttpResponse()46 .addHeader("Content-Type", MediaType.HTML_UTF_8.toString())47 .setContent(Contents.string("<h1>authorized</h1>", UTF_8)))48 .with(new BasicAuthenticationFilter("test", "test")),49 Route.get("/echo").to(EchoHandler::new),50 Route.get("/cookie").to(CookieHandler::new),51 Route.get("/encoding").to(EncodingHandler::new),52 Route.matching(req -> req.getUri().startsWith("/generated/")).to(() -> new GeneratedJsTestHandler("/generated")),53 Route.matching(req -> req.getUri().startsWith("/page/") && req.getMethod() == GET).to(PageHandler::new),54 Route.post("/createPage").to(() -> createPageHandler),55 Route.get("/redirect").to(RedirectHandler::new),56 Route.get("/sleep").to(SleepingHandler::new),57 Route.post("/upload").to(UploadHandler::new),58 Route.matching(req -> req.getUri().startsWith("/utf8/")).to(() -> new Utf8Handler(webSrc, "/utf8/")),59 Route.prefix(TEMP_SRC_CONTEXT_PATH).to(Route.combine(generatedPages)),60 new CommonWebResources());61 delegate = Route.combine(62 route,63 Route.prefix("/common").to(route));64 }65 @Override66 public boolean matches(HttpRequest req) {67 return delegate.matches(req);68 }69 @Override70 public HttpResponse execute(HttpRequest req) throws UncheckedIOException {71 return delegate.execute(req);72 }73}...

Full Screen

Full Screen

Source:GridUiRoute.java Github

copy

Full Screen

...18import org.openqa.selenium.json.Json;19import org.openqa.selenium.remote.http.HttpRequest;20import org.openqa.selenium.remote.http.HttpResponse;21import org.openqa.selenium.remote.http.Routable;22import org.openqa.selenium.remote.http.Route;23import java.net.URL;24import java.util.logging.Logger;25import static java.net.HttpURLConnection.HTTP_MOVED_TEMP;26import static org.openqa.selenium.remote.http.Route.get;27public class GridUiRoute implements Routable {28 private static final Logger LOG = Logger.getLogger("selenium");29 private static final String GRID_RESOURCE = "javascript/grid-ui/build";30 private static final String GRID_RESOURCE_WITH_PREFIX = String.format("/%s", GRID_RESOURCE);31 private final Route routes;32 public GridUiRoute() {33 URL uiRoot = GridUiRoute.class.getResource(GRID_RESOURCE_WITH_PREFIX);34 if (uiRoot != null) {35 ResourceHandler uiHandler = new ResourceHandler(new ClassPathResource(uiRoot, GRID_RESOURCE));36 HttpResponse uiRedirect = new HttpResponse()37 .setStatus(HTTP_MOVED_TEMP)38 .addHeader("Location", "/ui/index.html");39 routes = Route.combine(40 get("/").to(() -> req -> uiRedirect),41 get("/grid/console").to(() -> req -> uiRedirect),42 Route.prefix("/ui").to(Route.matching(req -> true).to(() -> uiHandler)));43 } else {44 LOG.warning("It was not possible to load the Grid UI.");45 Json json = new Json();46 routes = Route.matching(req -> false).to(() -> new NoHandler(json));47 }48 }49 @Override50 public boolean matches(HttpRequest req) {51 return routes.matches(req);52 }53 @Override54 public HttpResponse execute(HttpRequest req) {55 return routes.execute(req);56 }57}...

Full Screen

Full Screen

Source:Router.java Github

copy

Full Screen

...22import org.openqa.selenium.remote.http.HttpHandler;23import org.openqa.selenium.remote.http.HttpRequest;24import org.openqa.selenium.remote.http.HttpResponse;25import org.openqa.selenium.remote.http.Routable;26import org.openqa.selenium.remote.http.Route;27import org.openqa.selenium.remote.tracing.DistributedTracer;28import static org.openqa.selenium.remote.http.Route.combine;29import static org.openqa.selenium.remote.http.Route.get;30import static org.openqa.selenium.remote.http.Route.matching;31/**32 * A simple router that is aware of the selenium-protocol.33 */34public class Router implements Routable, HttpHandler {35 private final Route routes;36 public Router(37 DistributedTracer tracer,38 HttpClient.Factory clientFactory,39 SessionMap sessions,40 Distributor distributor) {41 routes = combine(42 get("/status")43 .to(() -> new GridStatusHandler(new Json(), clientFactory, distributor)),44 sessions,45 distributor,46 matching(req -> req.getUri().startsWith("/session/"))47 .to(() -> new HandleSession(tracer, clientFactory, sessions)));48 }49 @Override50 public boolean matches(HttpRequest req) {...

Full Screen

Full Screen

Route

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.remote.http.Route;2import org.openqa.selenium.remote.http.HttpMethod;3import org.openqa.selenium.remote.http.HttpRequest;4import org.openqa.selenium.remote.http.HttpResponse;5import java.util.function.Function;6public class RouteExample {7 public static void main(String[] args) {8 Route route = Route.matching(req -> req.getMethod() == HttpMethod.GET)9 .to((req, res) -> res.setStatus(200).setContent("Hello, World!"));10 HttpRequest request = new HttpRequest(HttpMethod.GET, "/foo");11 HttpResponse response = route.execute(request, new HttpResponse());12 System.out.println(response.getStatus());13 System.out.println(response.getContentString());14 }15}

Full Screen

Full Screen

Route

Using AI Code Generation

copy

Full Screen

1Route myRoute = Route.get("/foo/bar/baz").to(() -> new HttpResponse().setStatus(200));2Route myRoute = Route.get("/foo/bar/baz").to(() -> new HttpResponse().setStatus(200));3Route myRoute = Route.get("/foo/bar/baz").to(() -> new HttpResponse().setStatus(200));4Route myRoute = Route.get("/foo/bar/baz").to(() -> new HttpResponse().setStatus(200));5Route myRoute = Route.get("/foo/bar/baz").to(() -> new HttpResponse().setStatus(200));6Route myRoute = Route.get("/foo/bar/baz").to(() -> new HttpResponse().setStatus(200));7Route myRoute = Route.get("/foo/bar/baz").to(() -> new HttpResponse().setStatus(200));8Route myRoute = Route.get("/foo/bar/baz").to(() -> new HttpResponse().setStatus(200));9Route myRoute = Route.get("/foo/bar/baz").to(() -> new HttpResponse().setStatus(200));10Route myRoute = Route.get("/foo/bar/baz").to(() -> new HttpResponse().setStatus(200));11Route myRoute = Route.get("/foo/bar/baz").to(() -> new HttpResponse().setStatus(200));

Full Screen

Full Screen
copy
1ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);2MemoryInfo mi = new MemoryInfo();3activityManager.getMemoryInfo(mi);4Log.i("memory free", "" + mi.availMem);5
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 popular Stackoverflow questions on Route

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