Best Selenium code snippet using org.openqa.selenium.remote.ProtocolHandshake.createSession
Source:AppiumCommandExecutor.java
...139 request.setHeader(IDEMPOTENCY_KEY_HEADER, UUID.randomUUID().toString().toLowerCase());140 return httpClient.execute(request);141 };142 }143 private Response createSession(Command command) throws IOException {144 if (getCommandCodec() != null) {145 throw new SessionNotCreatedException("Session already exists");146 }147 ProtocolHandshake handshake = new ProtocolHandshake() {148 @SuppressWarnings("unchecked")149 public Result createSession(HttpClient client, Command command) throws IOException {150 Capabilities desiredCapabilities = (Capabilities) command.getParameters().get("desiredCapabilities");151 Capabilities desired = desiredCapabilities == null ? new ImmutableCapabilities() : desiredCapabilities;152 //the number of bytes before the stream should switch to buffering to a file153 int threshold = (int) Math.min(Runtime.getRuntime().freeMemory() / 10, Integer.MAX_VALUE);154 FileBackedOutputStream os = new FileBackedOutputStream(threshold);155 try {156 CountingOutputStream counter = new CountingOutputStream(os);157 Writer writer = new OutputStreamWriter(counter, UTF_8);158 NewAppiumSessionPayload payload = NewAppiumSessionPayload.create(desired);159 payload.writeTo(writer);160 try (InputStream rawIn = os.asByteSource().openBufferedStream();161 BufferedInputStream contentStream = new BufferedInputStream(rawIn)) {162 Method createSessionMethod = this.getClass().getSuperclass()163 .getDeclaredMethod("createSession", HttpClient.class, InputStream.class, long.class);164 createSessionMethod.setAccessible(true);165 Optional<Result> result = (Optional<Result>) createSessionMethod.invoke(this,166 withRequestsPatchedByIdempotencyKey(client), contentStream, counter.getCount());167 return result.map(result1 -> {168 Result toReturn = result.get();169 getLogger(ProtocolHandshake.class.getName())170 .info(format("Detected dialect: %s", toReturn.getDialect()));171 return toReturn;172 }).orElseThrow(() -> new SessionNotCreatedException(173 format("Unable to create a new remote session. Desired capabilities = %s", desired)));174 } catch (NoSuchMethodException | IllegalAccessException e) {175 throw new SessionNotCreatedException(format("Unable to create a new remote session. "176 + "Make sure your project dependencies config does not override "177 + "Selenium API version %s used by java-client library.",178 Config.main().getValue("selenium.version", String.class)), e);179 } catch (InvocationTargetException e) {180 String message = "Unable to create a new remote session.";181 if (e.getCause() != null) {182 if (e.getCause() instanceof WebDriverException) {183 message += " Please check the server log for more details.";184 }185 message += format(" Original error: %s", e.getCause().getMessage());186 }187 throw new SessionNotCreatedException(message, e);188 }189 } finally {190 os.reset();191 }192 }193 };194 ProtocolHandshake.Result result = handshake195 .createSession(getClient(), command);196 Dialect dialect = result.getDialect();197 setCommandCodec(dialect.getCommandCodec());198 getAdditionalCommands().forEach(this::defineCommand);199 setResponseCodec(dialect.getResponseCodec());200 return result.createResponse();201 }202 @Override203 public Response execute(Command command) throws WebDriverException {204 if (DriverCommand.NEW_SESSION.equals(command.getName())) {205 serviceOptional.ifPresent(driverService -> {206 try {207 driverService.start();208 } catch (IOException e) {209 throw new WebDriverException(e.getMessage(), e);210 }211 });212 }213 Response response;214 try {215 response = NEW_SESSION.equals(command.getName()) ? createSession(command) : super.execute(command);216 } catch (Throwable t) {217 Throwable rootCause = Throwables.getRootCause(t);218 if (rootCause instanceof ConnectException219 && rootCause.getMessage().contains("Connection refused")) {220 throw serviceOptional.map(service -> {221 if (service.isRunning()) {222 return new WebDriverException("The session is closed!", rootCause);223 }224 return new WebDriverException("The appium server has accidentally died!", rootCause);225 }).orElseGet((Supplier<WebDriverException>) () ->226 new WebDriverException(rootCause.getMessage(), rootCause));227 }228 throwIfUnchecked(t);229 throw new WebDriverException(t);...
Source:ProtocolHandshakeTest.java
...51 response.setStatus(HTTP_OK);52 response.setContent(utf8String(53 "{\"value\": {\"sessionId\": \"23456789\", \"capabilities\": {}}}"));54 RecordingHttpClient client = new RecordingHttpClient(response);55 new ProtocolHandshake().createSession(client, command);56 Map<String, Object> json = getRequestPayloadAsMap(client);57 assertThat(json.get("desiredCapabilities")).isEqualTo(EMPTY_MAP);58 }59 @Test60 public void requestShouldIncludeSpecCompliantW3CCapabilities() throws IOException {61 Map<String, Object> params = singletonMap("desiredCapabilities", new ImmutableCapabilities());62 Command command = new Command(null, DriverCommand.NEW_SESSION, params);63 HttpResponse response = new HttpResponse();64 response.setStatus(HTTP_OK);65 response.setContent(utf8String(66 "{\"value\": {\"sessionId\": \"23456789\", \"capabilities\": {}}}"));67 RecordingHttpClient client = new RecordingHttpClient(response);68 new ProtocolHandshake().createSession(client, command);69 Map<String, Object> json = getRequestPayloadAsMap(client);70 List<Map<String, Object>> caps = mergeW3C(json);71 assertThat(caps).isNotEmpty();72 }73 @Test74 public void shouldParseW3CNewSessionResponse() throws IOException {75 Map<String, Object> params = singletonMap("desiredCapabilities", new ImmutableCapabilities());76 Command command = new Command(null, DriverCommand.NEW_SESSION, params);77 HttpResponse response = new HttpResponse();78 response.setStatus(HTTP_OK);79 response.setContent(utf8String(80 "{\"value\": {\"sessionId\": \"23456789\", \"capabilities\": {}}}"));81 RecordingHttpClient client = new RecordingHttpClient(response);82 ProtocolHandshake.Result result = new ProtocolHandshake().createSession(client, command);83 assertThat(result.getDialect()).isEqualTo(Dialect.W3C);84 }85 @Test86 public void shouldParseWireProtocolNewSessionResponse() throws IOException {87 Map<String, Object> params = singletonMap("desiredCapabilities", new ImmutableCapabilities());88 Command command = new Command(null, DriverCommand.NEW_SESSION, params);89 HttpResponse response = new HttpResponse();90 response.setStatus(HTTP_OK);91 response.setContent(utf8String(92 "{\"sessionId\": \"23456789\", \"status\": 0, \"value\": {}}"));93 RecordingHttpClient client = new RecordingHttpClient(response);94 ProtocolHandshake.Result result = new ProtocolHandshake().createSession(client, command);95 assertThat(result.getDialect()).isEqualTo(Dialect.OSS);96 }97 @Test98 public void shouldNotIncludeNonProtocolExtensionKeys() throws IOException {99 Capabilities caps = new ImmutableCapabilities(100 "se:option", "cheese",101 "option", "I like sausages",102 "browserName", "amazing cake browser");103 Map<String, Object> params = singletonMap("desiredCapabilities", caps);104 Command command = new Command(null, DriverCommand.NEW_SESSION, params);105 HttpResponse response = new HttpResponse();106 response.setStatus(HTTP_OK);107 response.setContent(utf8String(108 "{\"sessionId\": \"23456789\", \"status\": 0, \"value\": {}}"));109 RecordingHttpClient client = new RecordingHttpClient(response);110 new ProtocolHandshake().createSession(client, command);111 Map<String, Object> handshakeRequest = getRequestPayloadAsMap(client);112 Object rawCaps = handshakeRequest.get("capabilities");113 assertThat(rawCaps).isInstanceOf(Map.class);114 Map<?, ?> capabilities = (Map<?, ?>) rawCaps;115 assertThat(capabilities.get("alwaysMatch")).isNull();116 List<Map<?, ?>> first = (List<Map<?, ?>>) capabilities.get("firstMatch");117 // We don't care where they are, but we want to see "se:option" and not "option"118 Set<String> keys = first.stream()119 .map(Map::keySet)120 .flatMap(Collection::stream)121 .map(String::valueOf).collect(Collectors.toSet());122 assertThat(keys)123 .contains("browserName", "se:option")124 .doesNotContain("options");125 }126 @Test127 public void firstMatchSeparatesCapsForDifferentBrowsers() throws IOException {128 Capabilities caps = new ImmutableCapabilities(129 "moz:firefoxOptions", EMPTY_MAP,130 "browserName", "chrome");131 Map<String, Object> params = singletonMap("desiredCapabilities", caps);132 Command command = new Command(null, DriverCommand.NEW_SESSION, params);133 HttpResponse response = new HttpResponse();134 response.setStatus(HTTP_OK);135 response.setContent(utf8String(136 "{\"sessionId\": \"23456789\", \"status\": 0, \"value\": {}}"));137 RecordingHttpClient client = new RecordingHttpClient(response);138 new ProtocolHandshake().createSession(client, command);139 Map<String, Object> handshakeRequest = getRequestPayloadAsMap(client);140 List<Map<String, Object>> capabilities = mergeW3C(handshakeRequest);141 assertThat(capabilities).contains(142 singletonMap("moz:firefoxOptions", EMPTY_MAP),143 singletonMap("browserName", "chrome"));144 }145 @Test146 public void doesNotCreateFirstMatchForNonW3CCaps() throws IOException {147 Capabilities caps = new ImmutableCapabilities(148 "cheese", EMPTY_MAP,149 "moz:firefoxOptions", EMPTY_MAP,150 "browserName", "firefox");151 Map<String, Object> params = singletonMap("desiredCapabilities", caps);152 Command command = new Command(null, DriverCommand.NEW_SESSION, params);153 HttpResponse response = new HttpResponse();154 response.setStatus(HTTP_OK);155 response.setContent(utf8String(156 "{\"sessionId\": \"23456789\", \"status\": 0, \"value\": {}}"));157 RecordingHttpClient client = new RecordingHttpClient(response);158 new ProtocolHandshake().createSession(client, command);159 Map<String, Object> handshakeRequest = getRequestPayloadAsMap(client);160 List<Map<String, Object>> w3c = mergeW3C(handshakeRequest);161 assertThat(w3c).hasSize(1);162 // firstMatch should not contain an object for Chrome-specific capabilities. Because163 // "chromeOptions" is not a W3C capability name, it is stripped from any firstMatch objects.164 // The resulting empty object should be omitted from firstMatch; if it is present, then the165 // Firefox-specific capabilities might be ignored.166 assertThat(w3c.get(0))167 .containsKey("moz:firefoxOptions")168 .containsEntry("browserName", "firefox");169 }170 @Test171 public void shouldLowerCaseProxyTypeForW3CRequest() throws IOException {172 Proxy proxy = new Proxy();173 proxy.setProxyType(AUTODETECT);174 Capabilities caps = new ImmutableCapabilities(CapabilityType.PROXY, proxy);175 Map<String, Object> params = singletonMap("desiredCapabilities", caps);176 Command command = new Command(null, DriverCommand.NEW_SESSION, params);177 HttpResponse response = new HttpResponse();178 response.setStatus(HTTP_OK);179 response.setContent(utf8String(180 "{\"sessionId\": \"23456789\", \"status\": 0, \"value\": {}}"));181 RecordingHttpClient client = new RecordingHttpClient(response);182 new ProtocolHandshake().createSession(client, command);183 Map<String, Object> handshakeRequest = getRequestPayloadAsMap(client);184 mergeW3C(handshakeRequest).forEach(always -> {185 Map<String, ?> seenProxy = (Map<String, ?>) always.get("proxy");186 assertThat(seenProxy.get("proxyType")).isEqualTo("autodetect");187 });188 Map<String, ?> jsonCaps = (Map<String, ?>) handshakeRequest.get("desiredCapabilities");189 Map<String, ?> seenProxy = (Map<String, ?>) jsonCaps.get("proxy");190 assertThat(seenProxy.get("proxyType")).isEqualTo("AUTODETECT");191 }192 @Test193 public void shouldNotIncludeMappingOfANYPlatform() throws IOException {194 Capabilities caps = new ImmutableCapabilities(195 "platform", "ANY",196 "platformName", "ANY",197 "browserName", "cake");198 Map<String, Object> params = singletonMap("desiredCapabilities", caps);199 Command command = new Command(null, DriverCommand.NEW_SESSION, params);200 HttpResponse response = new HttpResponse();201 response.setStatus(HTTP_OK);202 response.setContent(utf8String(203 "{\"sessionId\": \"23456789\", \"status\": 0, \"value\": {}}"));204 RecordingHttpClient client = new RecordingHttpClient(response);205 new ProtocolHandshake().createSession(client, command);206 Map<String, Object> handshakeRequest = getRequestPayloadAsMap(client);207 mergeW3C(handshakeRequest)208 .forEach(capabilities -> {209 assertThat(capabilities.get("browserName")).isEqualTo("cake");210 assertThat(capabilities.get("platformName")).isNull();211 assertThat(capabilities.get("platform")).isNull();212 });213 }214 private List<Map<String, Object>> mergeW3C(Map<String, Object> caps) {215 Map<String, Object> capabilities = (Map<String, Object>) caps.get("capabilities");216 if (capabilities == null) {217 return null;218 }219 Map<String, Object> always = Optional.ofNullable(...
Source:GoogleSmokeTest.java
...220//Starting ChromeDriver 2.35.528161 (5b82f2d2aae0ca24b877009200ced9065a772e73) on port 38216221//Only local connections are allowed.222//Starting ChromeDriver 2.35.528161 (5b82f2d2aae0ca24b877009200ced9065a772e73) on port 29235223//Only local connections are allowed.224//Mar 21, 2018 11:09:08 PM org.openqa.selenium.remote.ProtocolHandshake createSession225//INFO: Detected dialect: OSS226//Mar 21, 2018 11:09:08 PM org.openqa.selenium.remote.ProtocolHandshake createSession227//INFO: Detected dialect: OSS228//Mar 21, 2018 11:09:08 PM org.openqa.selenium.remote.ProtocolHandshake createSession229//INFO: Detected dialect: OSS230//231//Currently executing a test for test data: - seattle storm - in thread#: 15232//searchGoogleSmokeTest before GoogleMainPage instantiation->Search term: - seattle storm - Current thread #: 15233//GoogleMainPage->Search term: - seattle storm - Current thread #: 15234//235//Currently executing a test for test data: - seattle seahawks - in thread#: 13236//searchGoogleSmokeTest before GoogleMainPage instantiation->Search term: - seattle seahawks - Current thread #: 13237//GoogleMainPage->Search term: - seattle seahawks - Current thread #: 13238//239//Currently executing a test for test data: - green bay packers - in thread#: 14240//searchGoogleSmokeTest before GoogleMainPage instantiation->Search term: - green bay packers - Current thread #: 14241//GoogleMainPage->Search term: - green bay packers - Current thread #: 14242//searchGoogleFor->Search term: - seattle storm - Current thread #: 15243//searchGoogleFor->Search term: - green bay packers - Current thread #: 14244//searchGoogleFor->Search term: - seattle seahawks - Current thread #: 13245//searchGoogleSmokeTest after Assert ->Search term: - green bay packers - Current thread #: 14246//@@AfterMethod->releaseWebDriver->Current thread #: 14247//searchGoogleSmokeTest after Assert ->Search term: - seattle seahawks - Current thread #: 13248//@@AfterMethod->releaseWebDriver->Current thread #: 13249//searchGoogleSmokeTest after Assert ->Search term: - seattle storm - Current thread #: 15250//@@AfterMethod->releaseWebDriver->Current thread #: 15251//PASSED: test01("green bay packers")252//PASSED: test01("seattle seahawks")253//PASSED: test01("seattle storm")254//255//===============================================256// Default test257// Tests run: 3, Failures: 0, Skips: 0258//===============================================259//260//261//===============================================262//Default suite263//Total tests run: 3, Failures: 0, Skips: 0264265//OUTPUT parallel = false266//[RemoteTestNG] detected TestNG version 6.14.2267//@BeforeMethod->createWebDriver->Current thread #: 1268//Starting ChromeDriver 2.35.528161 (5b82f2d2aae0ca24b877009200ced9065a772e73) on port 41400269//Only local connections are allowed.270//Mar 21, 2018 11:11:25 PM org.openqa.selenium.remote.ProtocolHandshake createSession271//INFO: Detected dialect: OSS272//273//Currently executing a test for test data: - seattle seahawks - in thread#: 1274//searchGoogleSmokeTest before GoogleMainPage instantiation->Search term: - seattle seahawks - Current thread #: 1275//GoogleMainPage->Search term: - seattle seahawks - Current thread #: 1276//searchGoogleFor->Search term: - seattle seahawks - Current thread #: 1277//searchGoogleSmokeTest after Assert ->Search term: - seattle seahawks - Current thread #: 1278//@@AfterMethod->releaseWebDriver->Current thread #: 1279//@BeforeMethod->createWebDriver->Current thread #: 1280//Starting ChromeDriver 2.35.528161 (5b82f2d2aae0ca24b877009200ced9065a772e73) on port 6970281//Only local connections are allowed.282//Mar 21, 2018 11:11:34 PM org.openqa.selenium.remote.ProtocolHandshake createSession283//INFO: Detected dialect: OSS284//285//Currently executing a test for test data: - green bay packers - in thread#: 1286//searchGoogleSmokeTest before GoogleMainPage instantiation->Search term: - green bay packers - Current thread #: 1287//GoogleMainPage->Search term: - green bay packers - Current thread #: 1288//searchGoogleFor->Search term: - green bay packers - Current thread #: 1289//searchGoogleSmokeTest after Assert ->Search term: - green bay packers - Current thread #: 1290//@@AfterMethod->releaseWebDriver->Current thread #: 1291//@BeforeMethod->createWebDriver->Current thread #: 1292//Starting ChromeDriver 2.35.528161 (5b82f2d2aae0ca24b877009200ced9065a772e73) on port 7289293//Only local connections are allowed.294//Mar 21, 2018 11:11:43 PM org.openqa.selenium.remote.ProtocolHandshake createSession295//INFO: Detected dialect: OSS296//297//Currently executing a test for test data: - seattle storm - in thread#: 1298//searchGoogleSmokeTest before GoogleMainPage instantiation->Search term: - seattle storm - Current thread #: 1299//GoogleMainPage->Search term: - seattle storm - Current thread #: 1300//searchGoogleFor->Search term: - seattle storm - Current thread #: 1301//searchGoogleSmokeTest after Assert ->Search term: - seattle storm - Current thread #: 1302//@@AfterMethod->releaseWebDriver->Current thread #: 1303//PASSED: test01("seattle seahawks")304//PASSED: test01("green bay packers")305//PASSED: test01("seattle storm")306//307//===============================================308// Default test
...
Source:myHttpCommandExecutor.java
...47 if (mycommandCodec != null) {48 throw new SessionNotCreatedException("Session already exists");49 }50 ProtocolHandshake handshake = new ProtocolHandshake();51 ProtocolHandshake.Result result = handshake.createSession(myclient, command);52 Dialect dialect = result.getDialect();53 mycommandCodec = dialect.getCommandCodec();54 myresponseCodec = dialect.getResponseCodec();55 return result.createResponse();56 }57 if (mycommandCodec == null || myresponseCodec == null) {58 throw new WebDriverException("No command or response codec has been defined. Unable to proceed");59 }60 HttpRequest httpRequest = mycommandCodec.encode(command);61 try {62 HttpResponse httpResponse = myclient.execute(httpRequest);63 Response response = myresponseCodec.decode(httpResponse);64 if (response.getSessionId() == null) {65 if (httpResponse.getTargetHost() != null) {...
Source:DriverServiceSessionFactory.java
...61 HttpClient client = clientFactory.createClient(service.getUrl());62 Command command = new Command(63 null,64 DriverCommand.NEW_SESSION(sessionRequest.getCapabilities()));65 ProtocolHandshake.Result result = new ProtocolHandshake().createSession(client, command);66 Set<Dialect> downstreamDialects = sessionRequest.getDownstreamDialects();67 Dialect upstream = result.getDialect();68 Dialect downstream = downstreamDialects.contains(result.getDialect()) ?69 result.getDialect() :70 downstreamDialects.iterator().next();71 Response response = result.createResponse();72 return Optional.of(73 new ProtocolConvertingSession(74 client,75 new SessionId(response.getSessionId()),76 service.getUrl(),77 downstream,78 upstream,79 new ImmutableCapabilities((Map<?, ?>)response.getValue())) {...
createSession
Using AI Code Generation
1import org.openqa.selenium.remote.DesiredCapabilities;2import org.openqa.selenium.remote.ProtocolHandshake;3import org.openqa.selenium.remote.SessionId;4import org.openqa.selenium.remote.http.HttpClient;5import org.openqa.selenium.remote.http.HttpRequest;6import org.openqa.selenium.remote.http.HttpResponse;7import java.net.MalformedURLException;8import java.net.URL;9public class CreateSession {10 public static void main(String[] args) throws MalformedURLException {11 DesiredCapabilities capabilities = DesiredCapabilities.chrome();12 HttpClient.Factory factory = HttpClient.Factory.createDefault();13 HttpClient client = factory.createClient(remoteAddress);14 HttpRequest request = new HttpRequest("POST", "/session");15 request.setContent(DesiredCapabilities.chrome().asMap());16 HttpResponse response = client.execute(request);17 SessionId sessionId = new SessionId(response.getHeader("X-Test-Session-Id"));18 ProtocolHandshake.Result result = new ProtocolHandshake().createSession(client, capabilities, sessionId);19 }20}21[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ CreateSession ---22[INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) @ CreateSession ---23[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ CreateSession ---24[INFO] --- maven-compiler-plugin:3.8.0:testCompile (default-testCompile) @ CreateSession ---
createSession
Using AI Code Generation
1package com.selenium.scripts;2import java.net.MalformedURLException;3import java.net.URL;4import java.util.HashMap;5import java.util.Map;6import org.openqa.selenium.remote.CapabilityType;7import org.openqa.selenium.remote.DesiredCapabilities;8import org.openqa.selenium.remote.ProtocolHandshake;9import org.openqa.selenium.remote.Response;10import org.openqa.selenium.remote.SessionId;11import org.openqa.selenium.remote.http.HttpClient;12import org.openqa.selenium.remote.http.HttpClient.Factory;13import org.openqa.selenium.remote.http.HttpMethod;14import org.openqa.selenium.remote.http.HttpRequest;15import org.openqa.selenium.remote.http.HttpResponse;16public class CreateSession {17 public static void main(String[] args) throws MalformedURLException {18 DesiredCapabilities capabilities = new DesiredCapabilities();19 capabilities.setCapability(CapabilityType.BROWSER_NAME, "chrome");20 capabilities.setCapability(CapabilityType.PLATFORM_NAME, "windows");21 capabilities.setCapability(CapabilityType.VERSION, "87.0");22 capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);23 capabilities.setCapability(CapabilityType.SUPPORTS_JAVASCRIPT, true);24 capabilities.setCapability(CapabilityType.SUPPORTS_FINDING_BY_CSS, true);25 capabilities.setCapability(CapabilityType.SUPPORTS_APPLICATION_CACHE, true);26 capabilities.setCapability(CapabilityType.SUPPORTS_WEB_STORAGE, true);27 capabilities.setCapability(CapabilityType.SUPPORTS_LOCATION_CONTEXT, true);28 capabilities.setCapability(CapabilityType.TAKES_SCREENSHOT, true);29 capabilities.setCapability(CapabilityType.HAS_NATIVE_EVENTS, true);30 capabilities.setCapability(CapabilityType.ENABLE_PROFILING_CAPABILITY, true);31 capabilities.setCapability(CapabilityType.SUPPORTS_NETWORK_CONNECTION, true);32 capabilities.setCapability(CapabilityType.SUPPORTS_ALERTS, true);33 capabilities.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, true);34 capabilities.setCapability(CapabilityType.HAS_TOUCHSCREEN, true);35 capabilities.setCapability(CapabilityType.SUPPORTS_SQL_DATABASE, true);36 capabilities.setCapability(CapabilityType.SUPPORTS_WEB_STORAGE, true);37 capabilities.setCapability(CapabilityType.SUPPORTS_LOCATION_CONTEXT, true);
createSession
Using AI Code Generation
1import org.openqa.selenium.remote.ProtocolHandshake;2import org.openqa.selenium.remote.SessionId;3public class CreateSession {4 public static void main(String[] args) throws Exception {5 DesiredCapabilities capabilities = DesiredCapabilities.chrome();6 SessionId session = new ProtocolHandshake().createSession(capabilities, host);7 System.out.println("Session ID: " + session);8 }9}
createSession
Using AI Code Generation
1public class CreateSession {2 public static void main(String[] args) throws IOException {3 String[] capabilities = {"browserName=firefox"};4 Map<String, Object> parameters = new HashMap<>();5 parameters.put("desiredCapabilities", capabilities);6 Map<String, Object> response = new ProtocolHandshake().createSession(parameters, url);7 System.out.println(response);8 }9}10{sessionId=9d9f0d0f-7b6c-4e7a-ba3a-0d1c6d3e2e7a, status=0, value={acceptInsecureCerts=false, browserVersion=89.0, platformName=windows, browserName=firefox, pageLoadStrategy=normal, moz:accessibilityChecks=false, moz:headless=false, moz:processID=12076, moz:profile=C:\Users\prave\AppData\Local\Temp\rust_mozprofile.7zYjLw1G7v6Z, moz:useNonSpecCompliantPointerOrigin=false, moz:webdriverClick=true, strictFileInteractability=false, timeouts={implicit=0, pageLoad=300000, script=30000}, unhandledPromptBehavior=dismiss and notify, moz:shutdownTimeout=60000, setWindowRect=true, moz:useNonSpecCompliantPointerOrigin=false, moz:webdriverClick=true, strictFileInteractability=false, timeouts={implicit=0, pageLoad=300000, script=30000}, unhandledPromptBehavior=dismiss and notify, moz:shutdownTimeout=60000, setWindowRect=true}}11public class CreateSession {12 public static void main(String[] args) throws IOException {13 String[] capabilities = {"browserName=firefox"};14 Map<String, Object> parameters = new HashMap<>();15 parameters.put("desiredCapabilities", capabilities);16 Map<String, Object> response = new ProtocolHandshake().createSession(parameters, url);
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.
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.
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.
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.
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.
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.
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.
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.
LambdaTest also provides certification for Selenium testing to accelerate your career in Selenium automation testing.
Get 100 minutes of automation test minutes FREE!!