MCPcopy Create free account
hub / github.com/SeleniumHQ/selenium / StartSession

Method StartSession

dotnet/src/webdriver/WebDriver.cs:592–633  ·  view source on GitHub ↗

Starts a session with the driver Capabilities of the browser

(ICapabilities capabilities)

Source from the content-addressed store, hash-verified

590 /// </summary>
591 /// <param name="capabilities">Capabilities of the browser</param>
592 [MemberNotNull(nameof(SessionId))]
593 [MemberNotNull(nameof(Capabilities))]
594 protected void StartSession(ICapabilities capabilities)
595 {
596 Dictionary<string, object?> parameters = new Dictionary<string, object?>();
597
598 // If the object passed into the RemoteWebDriver constructor is a
599 // RemoteSessionSettings object, it is expected that all intermediate
600 // and end nodes are compliant with the W3C WebDriver Specification,
601 // and therefore will already contain all of the appropriate values
602 // for establishing a session.
603 if (capabilities is not RemoteSessionSettings remoteSettings)
604 {
605 Dictionary<string, object> matchCapabilities = this.GetCapabilitiesDictionary(capabilities);
606
607 List<object> firstMatchCapabilitiesList = new List<object>();
608 firstMatchCapabilitiesList.Add(matchCapabilities);
609
610 Dictionary<string, object> specCompliantCapabilitiesDictionary = new Dictionary<string, object>();
611 specCompliantCapabilitiesDictionary["firstMatch"] = firstMatchCapabilitiesList;
612
613 parameters.Add("capabilities", specCompliantCapabilitiesDictionary);
614 }
615 else
616 {
617 parameters.Add("capabilities", remoteSettings.ToDictionary());
618 }
619
620 Response response = this.Execute(DriverCommand.NewSession, parameters);
621
622 response.EnsureValueIsNotNull();
623 if (response.Value is not Dictionary<string, object> rawCapabilities)
624 {
625 string errorMessage = string.Format(CultureInfo.InvariantCulture, "The new session command returned a value ('{0}') that is not a valid JSON object.", response.Value);
626 throw new WebDriverException(errorMessage);
627 }
628
629 this.Capabilities = new ReturnedCapabilities(rawCapabilities);
630
631 string sessionId = response.SessionId ?? throw new WebDriverException($"The remote end did not respond with ID of a session when it was required. {response.Value}");
632 this.SessionId = new SessionId(sessionId);
633 }
634
635 /// <summary>
636 /// Gets the capabilities as a dictionary.

Callers 1

WebDriverMethod · 0.95

Calls 6

ExecuteMethod · 0.95
EnsureValueIsNotNullMethod · 0.80
FormatMethod · 0.80
AddMethod · 0.45
ToDictionaryMethod · 0.45

Tested by

no test coverage detected