How to use equals method of org.openqa.selenium.grid.security.Secret class

Best Selenium code snippet using org.openqa.selenium.grid.security.Secret.equals

Source:OneShotNode.java Github

copy

Full Screen

...122 Optional<String> driverName = config.get("k8s", "driver_name").map(String::toLowerCase);123 // Find the webdriver info corresponding to the driver name124 WebDriverInfo driverInfo = StreamSupport.stream(ServiceLoader.load(WebDriverInfo.class).spliterator(), false)125 .filter(info -> info.isSupporting(stereotype))126 .filter(info -> driverName.map(name -> name.equals(info.getDisplayName().toLowerCase())).orElse(true))127 .findFirst()128 .orElseThrow(() -> new ConfigException(129 "Unable to find matching driver for %s and %s", stereotype, driverName.orElse("any driver")));130 LOG.info(String.format("Creating one-shot node for %s with stereotype %s", driverInfo, stereotype));131 LOG.info("Grid URI is: " + nodeOptions.getPublicGridUri());132 return new OneShotNode(133 loggingOptions.getTracer(),134 eventOptions.getEventBus(),135 secretOptions.getRegistrationSecret(),136 nodeOptions.getHeartbeatPeriod(),137 new NodeId(UUID.randomUUID()),138 serverOptions.getExternalUri(),139 nodeOptions.getPublicGridUri().orElseThrow(() -> new ConfigException("Unable to determine public grid address")),140 stereotype,141 driverInfo);142 }143 @Override144 public Either<WebDriverException, CreateSessionResponse> newSession(CreateSessionRequest sessionRequest) {145 if (driver != null) {146 throw new IllegalStateException("Only expected one session at a time");147 }148 Optional<WebDriver> driver = driverInfo.createDriver(sessionRequest.getDesiredCapabilities());149 if (!driver.isPresent()) {150 return Either.left(new WebDriverException("Unable to create a driver instance"));151 }152 if (!(driver.get() instanceof RemoteWebDriver)) {153 driver.get().quit();154 return Either.left(new WebDriverException("Driver is not a RemoteWebDriver instance"));155 }156 this.driver = (RemoteWebDriver) driver.get();157 this.sessionId = this.driver.getSessionId();158 this.client = extractHttpClient(this.driver);159 this.capabilities = rewriteCapabilities(this.driver);160 this.sessionStart = Instant.now();161 LOG.info("Encoded response: " + JSON.toJson(ImmutableMap.of(162 "value", ImmutableMap.of(163 "sessionId", sessionId,164 "capabilities", capabilities))));165 events.fire(new NodeDrainStarted(getId()));166 return Either.right(167 new CreateSessionResponse(168 getSession(sessionId),169 JSON.toJson(ImmutableMap.of(170 "value", ImmutableMap.of(171 "sessionId", sessionId,172 "capabilities", capabilities))).getBytes(UTF_8)));173 }174 private HttpClient extractHttpClient(RemoteWebDriver driver) {175 CommandExecutor executor = driver.getCommandExecutor();176 try {177 Field client = null;178 Class<?> current = executor.getClass();179 while (client == null && (current != null || Object.class.equals(current))) {180 client = findClientField(current);181 current = current.getSuperclass();182 }183 if (client == null) {184 throw new IllegalStateException("Unable to find client field in " + executor.getClass());185 }186 if (!HttpClient.class.isAssignableFrom(client.getType())) {187 throw new IllegalStateException("Client field is not assignable to http client");188 }189 client.setAccessible(true);190 return (HttpClient) client.get(executor);191 } catch (ReflectiveOperationException e) {192 throw new IllegalStateException(e);193 }194 }195 private Field findClientField(Class<?> clazz) {196 try {197 return clazz.getDeclaredField("client");198 } catch (NoSuchFieldException e) {199 return null;200 }201 }202 private Capabilities rewriteCapabilities(RemoteWebDriver driver) {203 // Rewrite the se:options if necessary to add cdp url204 if (driverInfo.isSupportingCdp()) {205 String cdpPath = String.format("/session/%s/se/cdp", driver.getSessionId());206 return new PersistentCapabilities(driver.getCapabilities()).setCapability("se:cdp", rewrite(cdpPath));207 }208 return ImmutableCapabilities.copyOf(driver.getCapabilities());209 }210 private URI rewrite(String path) {211 try {212 return new URI(213 gridUri.getScheme(),214 gridUri.getUserInfo(),215 gridUri.getHost(),216 gridUri.getPort(),217 path,218 null,219 null);220 } catch (URISyntaxException e) {221 throw new RuntimeException(e);222 }223 }224 @Override225 public HttpResponse executeWebDriverCommand(HttpRequest req) {226 LOG.info("Executing " + req);227 HttpResponse res = client.execute(req);228 if (DELETE.equals(req.getMethod()) && req.getUri().equals("/session/" + sessionId)) {229 // Ensure the response is sent before we viciously kill the node230 new Thread(231 () -> {232 try {233 Thread.sleep(500);234 } catch (InterruptedException e) {235 Thread.currentThread().interrupt();236 throw new RuntimeException(e);237 }238 LOG.info("Stopping session: " + sessionId);239 stop(sessionId);240 },241 "Node clean up: " + getId())242 .start();243 }244 return res;245 }246 @Override247 public Session getSession(SessionId id) throws NoSuchSessionException {248 if (!isSessionOwner(id)) {249 throw new NoSuchSessionException("Unable to find session with id: " + id);250 }251 return new Session(252 sessionId,253 getUri(),254 stereotype,255 capabilities,256 sessionStart);257 }258 @Override259 public HttpResponse uploadFile(HttpRequest req, SessionId id) {260 return null;261 }262 @Override263 public void stop(SessionId id) throws NoSuchSessionException {264 LOG.info("Stop has been called: " + id);265 Require.nonNull("Session ID", id);266 if (!isSessionOwner(id)) {267 throw new NoSuchSessionException("Unable to find session " + id);268 }269 LOG.info("Quitting session " + id);270 try {271 driver.quit();272 } catch (Exception e) {273 // It's possible that the driver has already quit.274 }275 events.fire(new SessionClosedEvent(id));276 LOG.info("Firing node drain complete message");277 events.fire(new NodeDrainComplete(getId()));278 }279 @Override280 public boolean isSessionOwner(SessionId id) {281 return driver != null && sessionId.equals(id);282 }283 @Override284 public boolean isSupporting(Capabilities capabilities) {285 return driverInfo.isSupporting(capabilities);286 }287 @Override288 public NodeStatus getStatus() {289 return new NodeStatus(290 getId(),291 getUri(),292 1,293 ImmutableSet.of(294 new Slot(295 new SlotId(getId(), slotId),...

Full Screen

Full Screen

Source:CustomLocatorHandler.java Github

copy

Full Screen

...192 responseCodec = new W3CHttpResponseCodec();193 }194 @Override195 public Response execute(Command command) throws IOException {196 if (DriverCommand.NEW_SESSION.equals(command.getName())) {197 Response response = new Response();198 response.setState("session not created");199 return response;200 }201 if (command.getSessionId() == null) {202 Response response = new Response();203 response.setState("invalid session id");204 return response;205 }206 HttpRequest request = commandCodec.encode(command);207 HttpResponse response = toNode.execute(request);208 Response decoded = responseCodec.decode(response);209 decoded.setSessionId(command.getSessionId().toString());210 return decoded;...

Full Screen

Full Screen

Source:RemoteNode.java Github

copy

Full Screen

...92 @Override93 public boolean isSupporting(Capabilities capabilities) {94 return this.capabilities.stream()95 .anyMatch(caps -> caps.getCapabilityNames().stream()96 .allMatch(name -> Objects.equals(97 caps.getCapability(name),98 capabilities.getCapability(name))));99 }100 @Override101 public Optional<CreateSessionResponse> newSession(CreateSessionRequest sessionRequest) {102 Require.nonNull("Capabilities for session", sessionRequest);103 HttpRequest req = new HttpRequest(POST, "/se/grid/node/session");104 HttpTracing.inject(tracer, tracer.getCurrentContext(), req);105 req.setContent(asJson(sessionRequest));106 HttpResponse res = client.with(addSecret).execute(req);107 return Optional.ofNullable(Values.get(res, CreateSessionResponse.class));108 }109 @Override110 public boolean isSessionOwner(SessionId id) {111 Require.nonNull("Session ID", id);112 HttpRequest req = new HttpRequest(GET, "/se/grid/node/owner/" + id);113 HttpTracing.inject(tracer, tracer.getCurrentContext(), req);114 HttpResponse res = client.with(addSecret).execute(req);115 return Boolean.TRUE.equals(Values.get(res, Boolean.class));116 }117 @Override118 public Session getSession(SessionId id) throws NoSuchSessionException {119 Require.nonNull("Session ID", id);120 HttpRequest req = new HttpRequest(GET, "/se/grid/node/session/" + id);121 HttpTracing.inject(tracer, tracer.getCurrentContext(), req);122 HttpResponse res = client.with(addSecret).execute(req);123 return Values.get(res, Session.class);124 }125 @Override126 public HttpResponse executeWebDriverCommand(HttpRequest req) {127 return client.execute(req);128 }129 @Override130 public HttpResponse uploadFile(HttpRequest req, SessionId id) {131 return client.execute(req);132 }133 @Override134 public void stop(SessionId id) throws NoSuchSessionException {135 Require.nonNull("Session ID", id);136 HttpRequest req = new HttpRequest(DELETE, "/se/grid/node/session/" + id);137 HttpTracing.inject(tracer, tracer.getCurrentContext(), req);138 HttpResponse res = client.with(addSecret).execute(req);139 Values.get(res, Void.class);140 }141 @Override142 public NodeStatus getStatus() {143 HttpRequest req = new HttpRequest(GET, "/status");144 HttpTracing.inject(tracer, tracer.getCurrentContext(), req);145 HttpResponse res = client.execute(req);146 try (Reader reader = reader(res);147 JsonInput in = JSON.newInput(reader)) {148 in.beginObject();149 // Skip everything until we find "value"150 while (in.hasNext()) {151 if ("value".equals(in.nextName())) {152 in.beginObject();153 while (in.hasNext()) {154 if ("node".equals(in.nextName())) {155 return in.read(NodeStatus.class);156 } else {157 in.skipValue();158 }159 }160 in.endObject();161 } else {162 in.skipValue();163 }164 }165 } catch (IOException e) {166 throw new UncheckedIOException(e);167 }168 throw new IllegalStateException("Unable to read status");...

Full Screen

Full Screen

Source:NodeStatus.java Github

copy

Full Screen

...99 public String getRegistrationSecret() {100 return registrationSecret == null ? null : registrationSecret.encode();101 }102 @Override103 public boolean equals(Object o) {104 if (!(o instanceof NodeStatus)) {105 return false;106 }107 NodeStatus that = (NodeStatus) o;108 return Objects.equals(this.nodeId, that.nodeId) &&109 Objects.equals(this.externalUri, that.externalUri) &&110 this.maxSessionCount == that.maxSessionCount &&111 Objects.equals(this.slots, that.slots) &&112 Objects.equals(this.availability, that.availability) &&113 Objects.equals(this.registrationSecret, that.registrationSecret);114 }115 @Override116 public int hashCode() {117 return Objects.hash(nodeId, externalUri, maxSessionCount, slots);118 }119 private Map<String, Object> toJson() {120 return new ImmutableMap.Builder<String, Object>()121 .put("id", nodeId)122 .put("uri", externalUri)123 .put("maxSessions", maxSessionCount)124 .put("slots", slots)125 .put("availability", availability)126 .put("registrationSecret", Optional.ofNullable(registrationSecret))127 .build();...

Full Screen

Full Screen

Source:RequiresSecretFilter.java Github

copy

Full Screen

...53 }54 return true;55 }56 Secret requestSecret = new Secret(header);57 if (!Objects.equals(secret, requestSecret)) {58 LOG.warning("Secrets did not match!");59 return false;60 }61 return true;62 }63}...

Full Screen

Full Screen

Source:Secret.java Github

copy

Full Screen

...25 public String encode() {26 return secret;27 }28 @Override29 public boolean equals(Object o) {30 if (!(o instanceof Secret)) {31 return false;32 }33 Secret that = (Secret) o;34 return Objects.equals(this.secret, that.secret);35 }36 @Override37 public int hashCode() {38 return Objects.hash(secret);39 }40 private String toJson() {41 return secret;42 }43 private static Secret fromJson(String secret) {44 return new Secret(secret);45 }46}...

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 method in Secret

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful