How to use NewSessionPayload class of org.openqa.selenium.remote package

Best Selenium code snippet using org.openqa.selenium.remote.NewSessionPayload

Source:DistributorTest.java Github

copy

Full Screen

...48import org.openqa.selenium.grid.web.CombinedHandler;49import org.openqa.selenium.grid.web.CommandHandler;50import org.openqa.selenium.net.PortProber;51import org.openqa.selenium.remote.Dialect;52import org.openqa.selenium.remote.NewSessionPayload;53import org.openqa.selenium.remote.SessionId;54import org.openqa.selenium.remote.http.HttpClient;55import org.openqa.selenium.remote.http.HttpRequest;56import org.openqa.selenium.remote.http.HttpResponse;57import org.openqa.selenium.remote.tracing.DistributedTracer;58import org.openqa.selenium.support.ui.FluentWait;59import org.openqa.selenium.support.ui.Wait;60import java.io.IOException;61import java.io.UncheckedIOException;62import java.net.MalformedURLException;63import java.net.URI;64import java.net.URISyntaxException;65import java.net.URL;66import java.time.Duration;67import java.util.Map;68import java.util.UUID;69import java.util.concurrent.atomic.AtomicBoolean;70public class DistributorTest {71 private DistributedTracer tracer;72 private EventBus bus;73 private HttpClient.Factory clientFactory;74 private Distributor local;75 private Distributor distributor;76 private ImmutableCapabilities caps;77 @Before78 public void setUp() throws MalformedURLException {79 tracer = DistributedTracer.builder().build();80 bus = new GuavaEventBus();81 clientFactory = HttpClient.Factory.createDefault();82 LocalSessionMap sessions = new LocalSessionMap(tracer, bus);83 local = new LocalDistributor(tracer, bus, HttpClient.Factory.createDefault(), sessions);84 distributor = new RemoteDistributor(85 tracer,86 new PassthroughHttpClient.Factory<>(local),87 new URL("http://does.not.exist/"));88 caps = new ImmutableCapabilities("browserName", "cheese");89 }90 @Test91 public void creatingANewSessionWithoutANodeEndsInFailure() {92 try (NewSessionPayload payload = NewSessionPayload.create(caps)) {93 assertThatExceptionOfType(SessionNotCreatedException.class)94 .isThrownBy(() -> distributor.newSession(createRequest(payload)));95 }96 }97 @Test98 public void shouldBeAbleToAddANodeAndCreateASession() throws URISyntaxException {99 URI nodeUri = new URI("http://example:5678");100 URI routableUri = new URI("http://localhost:1234");101 LocalSessionMap sessions = new LocalSessionMap(tracer, bus);102 LocalNode node = LocalNode.builder(tracer, bus, clientFactory, routableUri)103 .add(caps, new TestSessionFactory((id, c) -> new Session(id, nodeUri, c)))104 .build();105 Distributor distributor = new LocalDistributor(106 tracer,107 bus,108 new PassthroughHttpClient.Factory<>(node),109 sessions);110 distributor.add(node);111 MutableCapabilities sessionCaps = new MutableCapabilities(caps);112 sessionCaps.setCapability("sausages", "gravy");113 try (NewSessionPayload payload = NewSessionPayload.create(sessionCaps)) {114 Session session = distributor.newSession(createRequest(payload)).getSession();115 assertThat(session.getCapabilities()).isEqualTo(sessionCaps);116 assertThat(session.getUri()).isEqualTo(routableUri);117 }118 }119 @Test120 public void creatingASessionAddsItToTheSessionMap() throws URISyntaxException {121 URI nodeUri = new URI("http://example:5678");122 URI routableUri = new URI("http://localhost:1234");123 LocalSessionMap sessions = new LocalSessionMap(tracer, bus);124 LocalNode node = LocalNode.builder(tracer, bus, clientFactory, routableUri)125 .add(caps, new TestSessionFactory((id, c) -> new Session(id, nodeUri, c)))126 .build();127 Distributor distributor = new LocalDistributor(128 tracer,129 bus,130 new PassthroughHttpClient.Factory<>(node),131 sessions);132 distributor.add(node);133 MutableCapabilities sessionCaps = new MutableCapabilities(caps);134 sessionCaps.setCapability("sausages", "gravy");135 try (NewSessionPayload payload = NewSessionPayload.create(sessionCaps)) {136 Session returned = distributor.newSession(createRequest(payload)).getSession();137 Session session = sessions.get(returned.getId());138 assertThat(session.getCapabilities()).isEqualTo(sessionCaps);139 assertThat(session.getUri()).isEqualTo(routableUri);140 }141 }142 @Test143 public void shouldBeAbleToRemoveANode() throws URISyntaxException, MalformedURLException {144 URI nodeUri = new URI("http://example:5678");145 URI routableUri = new URI("http://localhost:1234");146 LocalSessionMap sessions = new LocalSessionMap(tracer, bus);147 LocalNode node = LocalNode.builder(tracer, bus, clientFactory, routableUri)148 .add(caps, new TestSessionFactory((id, c) -> new Session(id, nodeUri, c)))149 .build();150 Distributor local = new LocalDistributor(151 tracer,152 bus,153 new PassthroughHttpClient.Factory<>(node),154 sessions);155 distributor = new RemoteDistributor(156 tracer,157 new PassthroughHttpClient.Factory<>(local),158 new URL("http://does.not.exist"));159 distributor.add(node);160 distributor.remove(node.getId());161 try (NewSessionPayload payload = NewSessionPayload.create(caps)) {162 assertThatExceptionOfType(SessionNotCreatedException.class)163 .isThrownBy(() -> distributor.newSession(createRequest(payload)));164 }165 }166 @Test167 public void registeringTheSameNodeMultipleTimesOnlyCountsTheFirstTime()168 throws URISyntaxException {169 URI nodeUri = new URI("http://example:5678");170 URI routableUri = new URI("http://localhost:1234");171 LocalNode node = LocalNode.builder(tracer, bus, clientFactory, routableUri)172 .add(caps, new TestSessionFactory((id, c) -> new Session(id, nodeUri, c)))173 .build();174 local.add(node);175 local.add(node);176 DistributorStatus status = local.getStatus();177 assertThat(status.getNodes().size()).isEqualTo(1);178 }179 @Test180 public void theMostLightlyLoadedNodeIsSelectedFirst() {181 // Create enough hosts so that we avoid the scheduler returning hosts in:182 // * insertion order183 // * reverse insertion order184 // * sorted with most heavily used first185 SessionMap sessions = new LocalSessionMap(tracer, bus);186 Node lightest = createNode(caps, 10, 0);187 Node medium = createNode(caps, 10, 4);188 Node heavy = createNode(caps, 10, 6);189 Node massive = createNode(caps, 10, 8);190 CombinedHandler handler = new CombinedHandler();191 handler.addHandler(lightest);192 handler.addHandler(medium);193 handler.addHandler(heavy);194 handler.addHandler(massive);195 Distributor distributor = new LocalDistributor(196 tracer,197 bus,198 new PassthroughHttpClient.Factory<>(handler),199 sessions)200 .add(heavy)201 .add(medium)202 .add(lightest)203 .add(massive);204 try (NewSessionPayload payload = NewSessionPayload.create(caps)) {205 Session session = distributor.newSession(createRequest(payload)).getSession();206 assertThat(session.getUri()).isEqualTo(lightest.getStatus().getUri());207 }208 }209 @Test210 public void shouldUseLastSessionCreatedTimeAsTieBreaker() {211 SessionMap sessions = new LocalSessionMap(tracer, bus);212 Node leastRecent = createNode(caps, 5, 0);213 CombinedHandler handler = new CombinedHandler();214 handler.addHandler(sessions);215 handler.addHandler(leastRecent);216 Distributor distributor = new LocalDistributor(217 tracer,218 bus,219 new PassthroughHttpClient.Factory<>(handler),220 sessions)221 .add(leastRecent);222 try (NewSessionPayload payload = NewSessionPayload.create(caps)) {223 distributor.newSession(createRequest(payload));224 // Will be "leastRecent" by default225 }226 Node middle = createNode(caps, 5, 0);227 handler.addHandler(middle);228 distributor.add(middle);229 try (NewSessionPayload payload = NewSessionPayload.create(caps)) {230 Session session = distributor.newSession(createRequest(payload)).getSession();231 // Least lightly loaded is middle232 assertThat(session.getUri()).isEqualTo(middle.getStatus().getUri());233 }234 Node mostRecent = createNode(caps, 5, 0);235 handler.addHandler(mostRecent);236 distributor.add(mostRecent);237 try (NewSessionPayload payload = NewSessionPayload.create(caps)) {238 Session session = distributor.newSession(createRequest(payload)).getSession();239 // Least lightly loaded is most recent240 assertThat(session.getUri()).isEqualTo(mostRecent.getStatus().getUri());241 }242 // All the nodes should be equally loaded.243 Map<Capabilities, Integer> expected = mostRecent.getStatus().getStereotypes();244 assertThat(leastRecent.getStatus().getStereotypes()).isEqualTo(expected);245 assertThat(middle.getStatus().getStereotypes()).isEqualTo(expected);246 // All nodes are now equally loaded. We should be going in time order now247 try (NewSessionPayload payload = NewSessionPayload.create(caps)) {248 Session session = distributor.newSession(createRequest(payload)).getSession();249 assertThat(session.getUri()).isEqualTo(leastRecent.getStatus().getUri());250 }251 }252 @Test253 public void shouldIncludeHostsThatAreUpInHostList() {254 CombinedHandler handler = new CombinedHandler();255 SessionMap sessions = new LocalSessionMap(tracer, bus);256 handler.addHandler(sessions);257 URI uri = createUri();258 Node alwaysDown = LocalNode.builder(tracer, bus, clientFactory, uri)259 .add(caps, new TestSessionFactory((id, c) -> new Session(id, uri, c)))260 .advanced()261 .healthCheck(() -> new HealthCheck.Result(false, "Boo!"))262 .build();263 handler.addHandler(alwaysDown);264 Node alwaysUp = LocalNode.builder(tracer, bus, clientFactory, uri)265 .add(caps, new TestSessionFactory((id, c) -> new Session(id, uri, c)))266 .advanced()267 .healthCheck(() -> new HealthCheck.Result(true, "Yay!"))268 .build();269 handler.addHandler(alwaysUp);270 LocalDistributor distributor = new LocalDistributor(271 tracer,272 bus,273 new PassthroughHttpClient.Factory<>(handler),274 sessions);275 handler.addHandler(distributor);276 distributor.add(alwaysDown);277 // Should be unable to create a session because the node is down.278 try (NewSessionPayload payload = NewSessionPayload.create(caps)) {279 assertThatExceptionOfType(SessionNotCreatedException.class)280 .isThrownBy(() -> distributor.newSession(createRequest(payload)));281 }282 distributor.add(alwaysUp);283 try (NewSessionPayload payload = NewSessionPayload.create(caps)) {284 distributor.newSession(createRequest(payload));285 }286 }287 @Test288 public void shouldNotScheduleAJobIfAllSlotsAreBeingUsed() {289 SessionMap sessions = new LocalSessionMap(tracer, bus);290 CombinedHandler handler = new CombinedHandler();291 Distributor distributor = new LocalDistributor(292 tracer,293 bus,294 new PassthroughHttpClient.Factory<>(handler),295 sessions);296 handler.addHandler(distributor);297 Node node = createNode(caps, 1, 0);298 handler.addHandler(node);299 distributor.add(node);300 // Use up the one slot available301 try (NewSessionPayload payload = NewSessionPayload.create(caps)) {302 distributor.newSession(createRequest(payload));303 }304 // Now try and create a session.305 try (NewSessionPayload payload = NewSessionPayload.create(caps)) {306 assertThatExceptionOfType(SessionNotCreatedException.class)307 .isThrownBy(() -> distributor.newSession(createRequest(payload)));308 }309 }310 @Test311 public void shouldReleaseSlotOnceSessionEnds() {312 SessionMap sessions = new LocalSessionMap(tracer, bus);313 CombinedHandler handler = new CombinedHandler();314 Distributor distributor = new LocalDistributor(315 tracer,316 bus,317 new PassthroughHttpClient.Factory<>(handler),318 sessions);319 handler.addHandler(distributor);320 Node node = createNode(caps, 1, 0);321 handler.addHandler(node);322 distributor.add(node);323 // Use up the one slot available324 Session session;325 try (NewSessionPayload payload = NewSessionPayload.create(caps)) {326 session = distributor.newSession(createRequest(payload)).getSession();327 }328 // Make sure the session map has the session329 sessions.get(session.getId());330 node.stop(session.getId());331 // Now wait for the session map to say the session is gone.332 Wait<Object> wait = new FluentWait<>(new Object()).withTimeout(Duration.ofSeconds(2));333 wait.until(obj -> {334 try {335 sessions.get(session.getId());336 return false;337 } catch (NoSuchSessionException e) {338 return true;339 }340 });341 wait.until(obj -> distributor.getStatus().hasCapacity());342 // And we should now be able to create another session.343 try (NewSessionPayload payload = NewSessionPayload.create(caps)) {344 distributor.newSession(createRequest(payload));345 }346 }347 @Test348 public void shouldNotStartASessionIfTheCapabilitiesAreNotSupported() {349 CombinedHandler handler = new CombinedHandler();350 LocalSessionMap sessions = new LocalSessionMap(tracer, bus);351 handler.addHandler(handler);352 Distributor distributor = new LocalDistributor(353 tracer,354 bus,355 new PassthroughHttpClient.Factory<>(handler),356 sessions);357 handler.addHandler(distributor);358 Node node = createNode(caps, 1, 0);359 handler.addHandler(node);360 distributor.add(node);361 ImmutableCapabilities unmatched = new ImmutableCapabilities("browserName", "transit of venus");362 try (NewSessionPayload payload = NewSessionPayload.create(unmatched)) {363 assertThatExceptionOfType(SessionNotCreatedException.class)364 .isThrownBy(() -> distributor.newSession(createRequest(payload)));365 }366 }367 @Test368 public void attemptingToStartASessionWhichFailsMarksAsTheSlotAsAvailable() {369 CombinedHandler handler = new CombinedHandler();370 SessionMap sessions = new LocalSessionMap(tracer, bus);371 handler.addHandler(sessions);372 URI uri = createUri();373 Node node = LocalNode.builder(tracer, bus, clientFactory, uri)374 .add(caps, new TestSessionFactory((id, caps) -> {375 throw new SessionNotCreatedException("OMG");376 }))377 .build();378 handler.addHandler(node);379 Distributor distributor = new LocalDistributor(380 tracer,381 bus,382 new PassthroughHttpClient.Factory<>(handler),383 sessions);384 handler.addHandler(distributor);385 distributor.add(node);386 try (NewSessionPayload payload = NewSessionPayload.create(caps)) {387 assertThatExceptionOfType(SessionNotCreatedException.class)388 .isThrownBy(() -> distributor.newSession(createRequest(payload)));389 }390 assertThat(distributor.getStatus().hasCapacity()).isTrue();391 }392 @Test393 public void shouldReturnNodesThatWereDownToPoolOfNodesOnceTheyMarkTheirHealthCheckPasses() {394 CombinedHandler handler = new CombinedHandler();395 SessionMap sessions = new LocalSessionMap(tracer, bus);396 handler.addHandler(sessions);397 AtomicBoolean isUp = new AtomicBoolean(false);398 URI uri = createUri();399 Node node = LocalNode.builder(tracer, bus, clientFactory, uri)400 .add(caps, new TestSessionFactory((id, caps) -> new Session(id, uri, caps)))401 .advanced()402 .healthCheck(() -> new HealthCheck.Result(isUp.get(), "TL;DR"))403 .build();404 handler.addHandler(node);405 LocalDistributor distributor = new LocalDistributor(406 tracer,407 bus,408 new PassthroughHttpClient.Factory<>(handler),409 sessions);410 handler.addHandler(distributor);411 distributor.add(node);412 // Should be unable to create a session because the node is down.413 try (NewSessionPayload payload = NewSessionPayload.create(caps)) {414 assertThatExceptionOfType(SessionNotCreatedException.class)415 .isThrownBy(() -> distributor.newSession(createRequest(payload)));416 }417 // Mark the node as being up418 isUp.set(true);419 // Kick the machinery to ensure that everything is fine.420 distributor.refresh();421 // Because the node is now up and running, we should now be able to create a session422 try (NewSessionPayload payload = NewSessionPayload.create(caps)) {423 distributor.newSession(createRequest(payload));424 }425 }426 @Test427 @Ignore428 public void shouldPriotizeHostsWithTheMostSlotsAvailableForASessionType() {429 // Consider the case where you have 1 Windows machine and 5 linux machines. All of these hosts430 // can run Chrome and Firefox sessions, but only one can run Edge sessions. Ideally, the machine431 // able to run Edge would be sorted last.432 fail("Write me");433 }434 private Node createNode(Capabilities stereotype, int count, int currentLoad) {435 URI uri = createUri();436 LocalNode.Builder builder = LocalNode.builder(tracer, bus, clientFactory, uri);437 for (int i = 0; i < count; i++) {438 builder.add(stereotype, new TestSessionFactory((id, caps) -> new HandledSession(uri, caps)));439 }440 LocalNode node = builder.build();441 for (int i = 0; i < currentLoad; i++) {442 // Ignore the session. We're just creating load.443 node.newSession(new CreateSessionRequest(444 ImmutableSet.copyOf(Dialect.values()),445 stereotype,446 ImmutableMap.of()));447 }448 return node;449 }450 @Test451 @Ignore452 public void shouldCorrectlySetSessionCountsWhenStartedAfterNodeWithSession() {453 fail("write me");454 }455 @Test456 public void statusShouldIndicateThatDistributorIsNotAvailableIfNodesAreDown()457 throws URISyntaxException {458 Capabilities capabilities = new ImmutableCapabilities("cheese", "peas");459 URI uri = new URI("http://exmaple.com");460 Node node = LocalNode.builder(tracer, bus, clientFactory, uri)461 .add(capabilities, new TestSessionFactory((id, caps) -> new Session(id, uri, caps)))462 .advanced()463 .healthCheck(() -> new HealthCheck.Result(false, "TL;DR"))464 .build();465 local.add(node);466 DistributorStatus status = local.getStatus();467 assertFalse(status.hasCapacity());468 }469 private HttpRequest createRequest(NewSessionPayload payload) {470 StringBuilder builder = new StringBuilder();471 try {472 payload.writeTo(builder);473 } catch (IOException e) {474 throw new UncheckedIOException(e);475 }476 HttpRequest request = new HttpRequest(POST, "/se/grid/distributor/session");477 request.setContent(utf8String(builder.toString()));478 return request;479 }480 private URI createUri() {481 try {482 return new URI("http://localhost:" + PortProber.findFreePort());483 } catch (URISyntaxException e) {...

Full Screen

Full Screen

Source:NewSessionPayload.java Github

copy

Full Screen

...68import java.util.TreeMap;69import java.util.function.Predicate;70import java.util.stream.Collectors;71import java.util.stream.Stream;72public class NewSessionPayload implements Closeable {73 private final Set<CapabilitiesFilter> adapters;74 private final Set<CapabilityTransform> transforms;75 private static final Dialect DEFAULT_DIALECT = Dialect.OSS;76 private final static Predicate<String> ACCEPTED_W3C_PATTERNS = new AcceptedW3CCapabilityKeys();77 private final Json json = new Json();78 private final FileBackedOutputStream backingStore;79 private final ImmutableSet<Dialect> dialects;80 public static NewSessionPayload create(Capabilities caps) {81 // We need to convert the capabilities into a new session payload. At this point we're dealing82 // with references, so I'm Just Sure This Will Be Fine.83 return create(ImmutableMap.of("desiredCapabilities", caps.asMap()));84 }85 public static NewSessionPayload create(Map<String, ?> source) {86 Objects.requireNonNull(source, "Payload must be set");87 String json = new Json().toJson(source);88 return new NewSessionPayload(new StringReader(json));89 }90 public static NewSessionPayload create(Reader source) {91 return new NewSessionPayload(source);92 }93 private NewSessionPayload(Reader source) {94 // Dedicate up to 10% of all RAM or 20% of available RAM (whichever is smaller) to storing this95 // payload.96 int threshold = (int) Math.min(97 Integer.MAX_VALUE,98 Math.min(99 Runtime.getRuntime().freeMemory() / 5,100 Runtime.getRuntime().maxMemory() / 10));101 backingStore = new FileBackedOutputStream(threshold);102 try (Writer writer = new OutputStreamWriter(backingStore, UTF_8)) {103 CharStreams.copy(source, writer);104 } catch (IOException e) {105 throw new UncheckedIOException(e);106 }107 ImmutableSet.Builder<CapabilitiesFilter> adapters = ImmutableSet.builder();...

Full Screen

Full Screen

Source:LocalNewSessionQueueTest.java Github

copy

Full Screen

...23import org.openqa.selenium.events.local.GuavaEventBus;24import org.openqa.selenium.grid.data.NewSessionRequestEvent;25import org.openqa.selenium.grid.data.RequestId;26import org.openqa.selenium.grid.sessionqueue.NewSessionQueue;27import org.openqa.selenium.remote.NewSessionPayload;28import org.openqa.selenium.remote.http.HttpMethod;29import org.openqa.selenium.remote.http.HttpRequest;30import org.openqa.selenium.remote.tracing.DefaultTestTracer;31import org.openqa.selenium.remote.tracing.Tracer;32import java.io.IOException;33import java.io.UncheckedIOException;34import java.time.Duration;35import java.time.Instant;36import java.util.Optional;37import java.util.UUID;38import java.util.concurrent.CountDownLatch;39import java.util.concurrent.TimeUnit;40import java.util.concurrent.atomic.AtomicBoolean;41import static org.assertj.core.api.Assertions.assertThat;42import static org.junit.Assert.assertEquals;43import static org.junit.Assert.assertTrue;44import static org.openqa.selenium.grid.sessionqueue.NewSessionQueue.SESSIONREQUEST_TIMESTAMP_HEADER;45import static org.openqa.selenium.remote.http.Contents.utf8String;46import static org.openqa.selenium.remote.http.HttpMethod.POST;47public class LocalNewSessionQueueTest {48 private EventBus bus;49 private Capabilities caps;50 private NewSessionQueue sessionQueue;51 private HttpRequest expectedSessionRequest;52 private RequestId requestId;53 @Before54 public void setUp() {55 Tracer tracer = DefaultTestTracer.createTracer();56 caps = new ImmutableCapabilities("browserName", "chrome");57 bus = new GuavaEventBus();58 requestId = new RequestId(UUID.randomUUID());59 sessionQueue = new LocalNewSessionQueue(60 tracer,61 bus,62 Duration.ofSeconds(1),63 Duration.ofSeconds(30));64 NewSessionPayload payload = NewSessionPayload.create(caps);65 expectedSessionRequest = createRequest(payload, POST, "/session");66 }67 @Test68 public void shouldBeAbleToAddToEndOfQueue() throws InterruptedException {69 AtomicBoolean result = new AtomicBoolean(false);70 CountDownLatch latch = new CountDownLatch(1);71 bus.addListener(NewSessionRequestEvent.listener(reqId -> {72 result.set(reqId.equals(requestId));73 latch.countDown();74 }));75 boolean added = sessionQueue.offerLast(expectedSessionRequest, requestId);76 assertTrue(added);77 78 latch.await(5, TimeUnit.SECONDS);79 assertThat(latch.getCount()).isEqualTo(0);80 assertTrue(result.get());81 }82 @Test83 public void shouldBeAbleToRemoveFromFrontOfQueue() {84 boolean added = sessionQueue.offerLast(expectedSessionRequest, requestId);85 assertTrue(added);86 Optional<HttpRequest> receivedRequest = sessionQueue.poll();87 assertTrue(receivedRequest.isPresent());88 assertEquals(expectedSessionRequest, receivedRequest.get());89 }90 @Test91 public void shouldAddTimestampHeader() {92 boolean added = sessionQueue.offerLast(expectedSessionRequest, requestId);93 assertTrue(added);94 Optional<HttpRequest> receivedRequest = sessionQueue.poll();95 assertTrue(receivedRequest.isPresent());96 HttpRequest request = receivedRequest.get();97 assertEquals(expectedSessionRequest, request);98 assertTrue(request.getHeader(NewSessionQueue.SESSIONREQUEST_TIMESTAMP_HEADER) != null);99 }100 @Test101 public void shouldAddRequestIdHeader() {102 boolean added = sessionQueue.offerLast(expectedSessionRequest, requestId);103 assertTrue(added);104 Optional<HttpRequest> receivedRequest = sessionQueue.poll();105 assertTrue(receivedRequest.isPresent());106 HttpRequest request = receivedRequest.get();107 assertEquals(expectedSessionRequest, request);108 String polledRequestId = request.getHeader(NewSessionQueue.SESSIONREQUEST_ID_HEADER);109 assertTrue(polledRequestId != null);110 assertEquals(requestId, new RequestId(UUID.fromString(polledRequestId)));111 }112 @Test113 public void shouldBeAbleToAddToFrontOfQueue() {114 long timestamp = Instant.now().getEpochSecond();115 ImmutableCapabilities chromeCaps = new ImmutableCapabilities("browserName", "chrome");116 NewSessionPayload chromePayload = NewSessionPayload.create(chromeCaps);117 HttpRequest chromeRequest = createRequest(chromePayload, POST, "/session");118 chromeRequest.addHeader(SESSIONREQUEST_TIMESTAMP_HEADER, Long.toString(timestamp));119 RequestId chromeRequestId = new RequestId(UUID.randomUUID());120 ImmutableCapabilities firefoxCaps = new ImmutableCapabilities("browserName", "firefox");121 NewSessionPayload firefoxpayload = NewSessionPayload.create(firefoxCaps);122 HttpRequest firefoxRequest = createRequest(firefoxpayload, POST, "/session");123 firefoxRequest.addHeader(SESSIONREQUEST_TIMESTAMP_HEADER, Long.toString(timestamp));124 RequestId firefoxRequestId = new RequestId(UUID.randomUUID());125 boolean addedChromeRequest = sessionQueue.offerFirst(chromeRequest, chromeRequestId);126 assertTrue(addedChromeRequest);127 boolean addFirefoxRequest = sessionQueue.offerFirst(firefoxRequest, firefoxRequestId);128 assertTrue(addFirefoxRequest);129 Optional<HttpRequest> polledFirefoxRequest = sessionQueue.poll();130 assertTrue(polledFirefoxRequest.isPresent());131 assertEquals(firefoxRequest, polledFirefoxRequest.get());132 Optional<HttpRequest> polledChromeRequest = sessionQueue.poll();133 assertTrue(polledChromeRequest.isPresent());134 assertEquals(chromeRequest, polledChromeRequest.get());135 }136 @Test137 public void shouldBeClearAPopulatedQueue() {138 sessionQueue.offerLast(expectedSessionRequest, requestId);139 sessionQueue.offerLast(expectedSessionRequest, requestId);140 int count = sessionQueue.clear();141 assertEquals(count, 2);142 }143 @Test144 public void shouldBeClearAEmptyQueue() {145 int count = sessionQueue.clear();146 assertEquals(count, 0);147 }148 private HttpRequest createRequest(NewSessionPayload payload, HttpMethod httpMethod, String uri) {149 StringBuilder builder = new StringBuilder();150 try {151 payload.writeTo(builder);152 } catch (IOException e) {153 throw new UncheckedIOException(e);154 }155 HttpRequest request = new HttpRequest(httpMethod, uri);156 request.setContent(utf8String(builder.toString()));157 return request;158 }159}...

Full Screen

Full Screen

Source:ProtocolHandshake.java Github

copy

Full Screen

...46 FileBackedOutputStream os = new FileBackedOutputStream(threshold);47 try (48 CountingOutputStream counter = new CountingOutputStream(os);49 Writer writer = new OutputStreamWriter(counter, UTF_8);50 NewSessionPayload payload = NewSessionPayload.create(desired)) {51 payload.writeTo(writer);52 try (InputStream rawIn = os.asByteSource().openBufferedStream();53 BufferedInputStream contentStream = new BufferedInputStream(rawIn)) {54 Optional<Result> result = createSession(client, contentStream, counter.getCount());55 if (result.isPresent()) {56 Result toReturn = result.get();57 LOG.info(String.format("Detected dialect: %s", toReturn.dialect));58 return toReturn;59 }60 }61 } finally {62 os.reset();63 }64 throw new SessionNotCreatedException(...

Full Screen

Full Screen

Source:AppiumProtocolHandshake.java Github

copy

Full Screen

...23import org.openqa.selenium.internal.Either;24import org.openqa.selenium.json.Json;25import org.openqa.selenium.json.JsonOutput;26import org.openqa.selenium.remote.Command;27import org.openqa.selenium.remote.NewSessionPayload;28import org.openqa.selenium.remote.ProtocolHandshake;29import org.openqa.selenium.remote.http.HttpHandler;30import java.io.BufferedInputStream;31import java.io.IOException;32import java.io.InputStream;33import java.io.OutputStreamWriter;34import java.io.Writer;35import java.lang.reflect.InvocationTargetException;36import java.lang.reflect.Method;37import java.util.Map;38import java.util.Set;39import java.util.stream.Stream;40import static java.nio.charset.StandardCharsets.UTF_8;41@SuppressWarnings("UnstableApiUsage")42public class AppiumProtocolHandshake extends ProtocolHandshake {43 private static void writeJsonPayload(NewSessionPayload srcPayload, Appendable destination) {44 try (JsonOutput json = new Json().newOutput(destination)) {45 json.beginObject();46 json.name("capabilities");47 json.beginObject();48 json.name("firstMatch");49 json.beginArray();50 json.beginObject();51 json.endObject();52 json.endArray();53 json.name("alwaysMatch");54 try {55 Method getW3CMethod = NewSessionPayload.class.getDeclaredMethod("getW3C");56 getW3CMethod.setAccessible(true);57 //noinspection unchecked58 ((Stream<Map<String, Object>>) getW3CMethod.invoke(srcPayload))59 .findFirst()60 .map(json::write)61 .orElseGet(() -> {62 json.beginObject();63 json.endObject();64 return null;65 });66 } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {67 throw new WebDriverException(e);68 }69 json.endObject(); // Close "capabilities" object70 try {71 Method writeMetaDataMethod = NewSessionPayload.class.getDeclaredMethod(72 "writeMetaData", JsonOutput.class);73 writeMetaDataMethod.setAccessible(true);74 writeMetaDataMethod.invoke(srcPayload, json);75 } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {76 throw new WebDriverException(e);77 }78 json.endObject();79 }80 }81 @Override82 public Result createSession(HttpHandler client, Command command) throws IOException {83 //noinspection unchecked84 Capabilities desired = ((Set<Map<String, Object>>) command.getParameters().get("capabilities"))85 .stream()86 .findAny()87 .map(ImmutableCapabilities::new)88 .orElseGet(ImmutableCapabilities::new);89 try (NewSessionPayload payload = NewSessionPayload.create(desired)) {90 Either<SessionNotCreatedException, Result> result = createSession(client, payload);91 if (result.isRight()) {92 return result.right();93 }94 throw result.left();95 }96 }97 @Override98 public Either<SessionNotCreatedException, Result> createSession(99 HttpHandler client, NewSessionPayload payload) throws IOException {100 int threshold = (int) Math.min(Runtime.getRuntime().freeMemory() / 10, Integer.MAX_VALUE);101 FileBackedOutputStream os = new FileBackedOutputStream(threshold);102 try (CountingOutputStream counter = new CountingOutputStream(os);103 Writer writer = new OutputStreamWriter(counter, UTF_8)) {104 writeJsonPayload(payload, writer);105 try (InputStream rawIn = os.asByteSource().openBufferedStream();106 BufferedInputStream contentStream = new BufferedInputStream(rawIn)) {107 Method createSessionMethod = ProtocolHandshake.class.getDeclaredMethod("createSession",108 HttpHandler.class, InputStream.class, long.class);109 createSessionMethod.setAccessible(true);110 //noinspection unchecked111 return (Either<SessionNotCreatedException, Result>) createSessionMethod.invoke(112 this, client, contentStream, counter.getCount()113 );...

Full Screen

Full Screen

Source:NewSessionQueuer.java Github

copy

Full Screen

...23import org.openqa.selenium.Capabilities;24import org.openqa.selenium.SessionNotCreatedException;25import org.openqa.selenium.grid.data.RequestId;26import org.openqa.selenium.internal.Require;27import org.openqa.selenium.remote.NewSessionPayload;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.AttributeKey;33import org.openqa.selenium.remote.tracing.EventAttribute;34import org.openqa.selenium.remote.tracing.EventAttributeValue;35import org.openqa.selenium.remote.tracing.Span;36import org.openqa.selenium.remote.tracing.Tracer;37import org.openqa.selenium.status.HasReadyState;38import java.io.IOException;39import java.io.Reader;40import java.util.HashMap;41import java.util.Iterator;42import java.util.Map;43import java.util.Objects;44import java.util.Optional;45import java.util.UUID;46import java.util.logging.Logger;47public abstract class NewSessionQueuer implements HasReadyState, Routable {48 private static final Logger LOG = Logger.getLogger(NewSessionQueuer.class.getName());49 private final Route routes;50 protected final Tracer tracer;51 protected NewSessionQueuer(Tracer tracer) {52 this.tracer = Require.nonNull("Tracer", tracer);53 routes = combine(54 post("/session")55 .to(() -> this::addToQueue),56 post("/se/grid/newsessionqueuer/session")57 .to(() -> new AddToSessionQueue(tracer, this)),58 post("/se/grid/newsessionqueuer/session/retry/{requestId}")59 .to(params -> new AddBackToSessionQueue(tracer, this,60 new RequestId(61 UUID.fromString(params.get("requestId"))))),62 Route.get("/se/grid/newsessionqueuer/session")63 .to(() -> new RemoveFromSessionQueue(tracer, this)),64 delete("/se/grid/newsessionqueuer/queue")65 .to(() -> new ClearSessionQueue(tracer, this)));66 }67 public void validateSessionRequest(HttpRequest request) {68 try (Span span = tracer.getCurrentContext().createSpan("newsession_queuer.validate")) {69 Map<String, EventAttributeValue> attributeMap = new HashMap<>();70 try (71 Reader reader = reader(request);72 NewSessionPayload payload = NewSessionPayload.create(reader)) {73 Objects.requireNonNull(payload, "Requests to process must be set.");74 attributeMap.put("request.payload", EventAttribute.setValue(payload.toString()));75 Iterator<Capabilities> iterator = payload.stream().iterator();76 if (!iterator.hasNext()) {77 SessionNotCreatedException78 exception =79 new SessionNotCreatedException("No capabilities found");80 EXCEPTION.accept(attributeMap, exception);81 attributeMap.put(AttributeKey.EXCEPTION_MESSAGE.getKey(),82 EventAttribute.setValue(exception.getMessage()));83 span.addEvent(AttributeKey.EXCEPTION_EVENT.getKey(), attributeMap);84 throw exception;85 }86 } catch (IOException e) {...

Full Screen

Full Screen

Source:ActiveSessionFactory.java Github

copy

Full Screen

...67 StreamSupport.stream(ServiceLoader.load(DriverProvider.class).spliterator(), false)68 .forEach(p -> builder.put(p.getProvidedCapabilities().getBrowserName(), new InMemorySession.Factory(p)));69 this.factories = ImmutableMap.copyOf(builder);70 }71 public ActiveSession createSession(NewSessionPayload newSessionPayload) throws IOException {72 return newSessionPayload.stream()73 .map(this::determineBrowser)74 .filter(Objects::nonNull)75 .map(factory -> factory.apply(newSessionPayload))76 .filter(Objects::nonNull)77 .findFirst()78 .orElseThrow(() -> new SessionNotCreatedException(79 "Unable to create a new session because of no configuration."));80 }81 private SessionFactory determineBrowser(Capabilities caps) {82 return caps.asMap().entrySet().stream()83 .map(entry -> guessBrowserName(entry.getKey(), entry.getValue()))84 .filter(factories.keySet()::contains)85 .map(factories::get)...

Full Screen

Full Screen

Source:BeginSession.java Github

copy

Full Screen

...23import org.openqa.selenium.json.Json;24import org.openqa.selenium.logging.LogType;25import org.openqa.selenium.logging.LoggingPreferences;26import org.openqa.selenium.remote.CapabilityType;27import org.openqa.selenium.remote.NewSessionPayload;28import org.openqa.selenium.remote.http.HttpRequest;29import org.openqa.selenium.remote.http.HttpResponse;30import org.openqa.selenium.remote.server.ActiveSession;31import org.openqa.selenium.remote.server.ActiveSessions;32import org.openqa.selenium.remote.server.CommandHandler;33import org.openqa.selenium.remote.server.NewSessionPipeline;34import org.openqa.selenium.remote.server.log.LoggingManager;35import java.io.IOException;36import java.io.InputStreamReader;37import java.io.Reader;38import java.util.Map;39import java.util.logging.Level;40public class BeginSession implements CommandHandler {41 private final NewSessionPipeline pipeline;42 private final ActiveSessions allSessions;43 private final Json json;44 public BeginSession(NewSessionPipeline pipeline, ActiveSessions allSessions, Json json) {45 this.pipeline = pipeline;46 this.allSessions = allSessions;47 this.json = json;48 }49 @Override50 public void execute(HttpRequest req, HttpResponse resp) throws IOException {51 ActiveSession session;52 try (Reader reader = new InputStreamReader(53 req.consumeContentStream(),54 req.getContentEncoding());55 NewSessionPayload payload = NewSessionPayload.create(reader)) {56 session = pipeline.createNewSession(payload);57 allSessions.put(session);58 }59 // Force capture of server-side logs since we don't have easy access to the request from the60 // local end.61 LoggingPreferences loggingPrefs = new LoggingPreferences();62 loggingPrefs.enable(LogType.SERVER, Level.INFO);63 Object raw = session.getCapabilities().get(CapabilityType.LOGGING_PREFS);64 if (raw instanceof LoggingPreferences) {65 loggingPrefs.addPreferences((LoggingPreferences) raw);66 }67 LoggingManager.perSessionLogHandler().configureLogging(loggingPrefs);68 LoggingManager.perSessionLogHandler().attachToCurrentThread(session.getId());69 // Only servers implementing the server-side webdriver-backed selenium need to return this...

Full Screen

Full Screen

NewSessionPayload

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.remote.NewSessionPayload;2import org.openqa.selenium.remote.DesiredCapabilities;3import org.openqa.selenium.remote.RemoteWebDriver;4import org.openqa.selenium.firefox.FirefoxOptions;5import org.openqa.selenium.firefox.FirefoxDriver;6import java.io.IOException;7import java.util.concurrent.TimeUnit;8public class FirefoxDriverTest {9 public static void main(String[] args) throws IOException {10 FirefoxOptions options = new FirefoxOptions();11 options.setCapability("marionette", true);12 FirefoxDriver driver = new FirefoxDriver(options);13 System.out.println("Title: " + driver.getTitle());14 driver.close();15 }16}17package com.selenium4beginners.java.webdriver.basics;18import org.openqa.selenium.remote.NewSessionPayload;19import org.openqa.selenium.remote.DesiredCapabilities;20import org.openqa.selenium.remote.RemoteWebDriver;21import org.openqa.selenium.firefox.FirefoxOptions;22import org.openqa.selenium.firefox.FirefoxDriver;23import java.io.IOException;24import java.util.concurrent.TimeUnit;25public class FirefoxDriverTest {26 public static void main(String[] args) throws IOException {27 FirefoxOptions options = new FirefoxOptions();28 options.setCapability("marionette", true);29 RemoteWebDriver driver = new RemoteWebDriver(options);30 System.out.println("Title: " + driver.getTitle());

Full Screen

Full Screen

NewSessionPayload

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.remote.NewSessionPayload;2import org.openqa.selenium.remote.DesiredCapabilities;3import org.openqa.selenium.remote.CapabilityType;4import org.openqa.selenium.remote.http.HttpClient;5import org.openqa.selenium.remote.http.HttpMethod;6import org.openqa.selenium.remote.http.HttpRequest;7import org.openqa.selenium.remote.http.HttpResponse;8import org.openqa.selenium.remote.http.W3CHttpCommandCodec;9import org.openqa.selenium.remote.http.W3CHttpResponseCodec;10import org.openqa.selenium.remote.http.Route;11import org.openqa.selenium.remote.http.WebSocket;12import org.openqa.selenium.remote.http.WebSocketListener;13import org.openqa.selenium.remote.http.WebSocketMessage;14import org.openqa.selenium.remote.http.WebSocketOpen;15import org.openqa.selenium.remote.http.WebSocketPing;16import org.openqa.selenium.remote.http.WebSocketPong;17import org.openqa.selenium.remote.http.WebSocketClose;18import org.openqa.selenium.remote.http.WebSocketFrame;19import org.openqa.selenium.remote.http.WebSocketTextMessage;20import org.openqa.selenium.remote.http.WebSocketBinaryMessage;21import org.openqa.selenium.remote.http.WebSocketFrameHeader;22import org.openqa.selenium.remote.http.WebSocketFrameType;23import org.openqa.selenium.remote.http.WebSocketFrameHeaderParser;24import org.openqa.selenium.remote.http.WebSocketFrameHeaderReader;25import org.openqa.selenium.remote.http.WebSocketFrameHeaderWriter;26import org.openqa.selenium.remote.http.WebSocketFrameHeaderEncoder;27import org.openqa.selenium.remote.http.WebSocketFrameHeaderDecoder;28import org.openqa.selenium.remote.http.WebSocketFrameHeaderEncoder;29import org.openqa.selenium.remote.http.WebSocketFrameHeaderDecoder;30import org.openqa.selenium.remote.http.WebSocketFrameHeaderParser;31import org.openqa.selenium.remote.http.WebSocketFrameHeaderReader;32import org.openqa.selenium.remote.http.WebSocketFrameHeaderWriter;33import org.openqa.selenium.remote.http.WebSocketFrameHeaderEncoder;34import org.openqa.selenium.remote.http.WebSocketFrameHeaderDecoder;35import org.openqa.selenium.remote.http.WebSocketFrameHeaderEncoder;36import org.openqa.selenium.remote.http.WebSocketFrameHeaderDecoder;37import org.openqa.selenium.remote.http.WebSocketFrameHeaderParser;38import org.openqa.selenium.remote.http.WebSocketFrameHeaderReader;39import org.openqa.selenium.remote.http.WebSocketFrameHeaderWriter;40import org.openqa.selenium.remote.http.WebSocketFrameHeaderEncoder;41import org.openqa.selenium.remote.http.WebSocketFrameHeaderDecoder;42import org.openqa.selenium.remote.http.WebSocketFrameHeaderEncoder;43import org.openqa.selenium.remote.http.WebSocketFrameHeaderDecoder;44import org.openqa.selenium.remote.http.WebSocketFrameHeaderParser;45import org.openqa.selenium.remote.http.WebSocketFrameHeaderReader;46import

Full Screen

Full Screen

NewSessionPayload

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.remote.NewSessionPayload;2import org.openqa.selenium.remote.DesiredCapabilities;3import org.openqa.selenium.BrowserType;4import org.openqa.selenium.remote.RemoteWebDriver;5import org.openqa.selenium.WebDriverException;6import java.net.URL;7import java.util.concurrent.TimeUnit;8import java.lang.System;9import org.openqa.selenium.By;10import org.openqa.selenium.WebElement;11import java.util.List;12import org.openqa.selenium.support.ui.ExpectedConditions;13import org.openqa.selenium.support.ui.WebDriverWait;14import org.openqa.selenium.JavascriptExecutor;15import java.util.concurrent.TimeoutException;16import java.lang.Thread;17import org.openqa.selenium.remote.NewSessionPayload;18import org.openqa.selenium.remote.DesiredCapabilities;19import org.openqa.selenium.BrowserType;20import org.openqa.selenium.remote.RemoteWebDriver;21import org.openqa.selenium.WebDriverException;22import java.net.URL;23import java.util.concurrent.TimeUnit;24import java.lang.System;25import org.openqa.selenium.By;26import org.openqa.selenium.WebElement;27import java.util.List;28import org.openqa.selenium.support.ui.ExpectedConditions;29import org.openqa.selenium.support.ui.WebDriverWait;30import org.openqa.selenium.JavascriptExecutor;31import java.util.concurrent.TimeoutException;32import java.lang.Thread;33import org.openqa.selenium.remote.NewSessionPayload;34import org.openqa.selenium.remote.DesiredCapabilities;35import org.openqa.selenium.BrowserType;36import org.openqa.selenium.remote.RemoteWebDriver;37import org.openqa.selenium.WebDriverException;38import java.net.URL;39import java.util.concurrent.TimeUnit;40import java.lang.System;41import org.openqa.selenium.By;42import org.openqa.selenium.WebElement;43import java.util.List;44import org.openqa.selenium.support.ui.ExpectedConditions

Full Screen

Full Screen

NewSessionPayload

Using AI Code Generation

copy

Full Screen

1package org.openqa.selenium.remote;2import org.openqa.selenium.Capabilities;3import org.openqa.selenium.ImmutableCapabilities;4import java.util.Map;5public class NewSessionPayload {6 private final Capabilities capabilities;7 private NewSessionPayload(Capabilities capabilities) {8 this.capabilities = capabilities;9 }10 public static NewSessionPayload create(Capabilities capabilities) {11 return new NewSessionPayload(capabilities);12 }13 public Capabilities getDownstreamEncodedCapabilities() {14 return capabilities;15 }16 public Map<String, ?> getDownstreamDialectEncodedCapabilities() {17 return new ImmutableCapabilities(capabilities).asMap();18 }19 public Capabilities getCapabilities() {20 return capabilities;21 }22}23package org.openqa.selenium.remote;24import org.openqa.selenium.Capabilities;25import org.openqa.selenium.ImmutableCapabilities;26import org.openqa.selenium.json.Json;27import org.openqa.selenium.json.JsonInput;28import java.util.Map;29public class NewSessionPayload {30 private final Capabilities capabilities;31 private NewSessionPayload(Capabilities capabilities) {32 this.capabilities = capabilities;33 }34 public static NewSessionPayload create(Capabilities capabilities) {35 return new NewSessionPayload(capabilities);36 }37 public Capabilities getDownstreamEncodedCapabilities() {38 return capabilities;39 }40 public Map<String, ?> getDownstreamDialectEncodedCapabilities() {41 return new ImmutableCapabilities(capabilities).asMap();42 }43 public Capabilities getCapabilities() {44 return capabilities;45 }46 public static NewSessionPayload createFrom(JsonInput input) {47 return new NewSessionPayload(new ImmutableCapabilities(input.read(Json.MAP_TYPE)));48 }49}50package org.openqa.selenium.remote;51import org.openqa.selenium.Capabilities;52import org.openqa.selenium.ImmutableCapabilities;53import org.openqa.selenium.json.Json;54import org.openqa.selenium.json.JsonInput;55import org.openqa.selenium.json.JsonOutput;56import java.util.Map;57public class NewSessionPayload {58 private final Capabilities capabilities;59 private NewSessionPayload(Capabilities capabilities) {60 this.capabilities = capabilities;61 }62 public static NewSessionPayload create(Capabilities capabilities) {63 return new NewSessionPayload(capabilities);64 }65 public Capabilities getDownstreamEncodedCapabilities() {66 return capabilities;67 }68 public Map<String, ?> getDownstreamDialectEncodedCapabilities() {

Full Screen

Full Screen

NewSessionPayload

Using AI Code Generation

copy

Full Screen

1NewSessionPayload payload = new NewSessionPayload();2payload.setCapabilities(Capabilities);3DesiredCapabilities capabilities = new DesiredCapabilities();4capabilities.setBrowserName(BrowserType.CHROME);5capabilities.setPlatform(Platform.WIN10);6ImmutableMap<String, String> chromeOptions = ImmutableMap.of("args", Arrays.asList("--headless"));7ImmutableMap<String, Object> prefs = ImmutableMap.of("profile.managed_default_content_settings.images", 2);8ImmutableMap<String, Object> chromeOptions = ImmutableMap.of("prefs", prefs, "args", Arrays.asList("--headless"));9ChromeOptions options = new ChromeOptions();10options.setExperimentalOption("prefs", chromeOptions);11options.setExperimentalOption("prefs", prefs);12options.setExperimentalOption("prefs", ImmutableMap.of("profile.managed_default_content_settings.images", 2));13options.setExperimentalOption("prefs", ImmutableMap.of("profile.managed_default_content_settings.images", 2, "profile.managed_default_content_settings.javascript", 2));14options.setExperimentalOption("prefs", ImmutableMap.of("profile.managed_default_content_settings.images", 2, "profile.managed_default_content_settings.javascript", 2, "profile.managed_default_content_settings.plugins", 2));15options.setExperimentalOption("prefs", ImmutableMap.of("profile.managed_default_content_settings.images", 2, "profile.managed_default_content_settings.javascript", 2, "profile.managed_default_content_settings.plugins", 2, "profile.managed_default_content_settings.popups", 2));

Full Screen

Full Screen

NewSessionPayload

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.remote.NewSessionPayload;2import com.google.common.net.MediaType;3import com.google.common.io.Files;4import com.google.common.collect.ImmutableMap;5import com.google.common.base.Charsets;6import org.json.JSONObject;7import java.util.Map;8import java.io.File;9import java.nio.file.Path;10import java.nio.charset.Charset;11import java.net.URL;12import java.lang.String;13import java.io.IOException;14import java.io.InputStream;15import java.io.ByteArrayInputStream;16import java.io.ByteArrayOutputStream;17import java.io.OutputStream;18import java.io.InputStreamReader;19import java.io.BufferedReader;20import java.io.BufferedInputStream;21import java.io.BufferedOutputStream;22import java.io.FileInputStream;23import java.io.FileOutputStream;24import java.io.InputStream;25import java.io.OutputStream;26import java.io.Reader;

Full Screen

Full Screen
copy
1 A) if (data[c] >= 128)2 /\3 / \4 / \5 true / \ false6 / \7 / \8 / \9 / \10 B) sum += data[c]; C) for loop or print().11
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 NewSessionPayload

Most used methods in NewSessionPayload

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