Beispiel #1
0
        /// <summary>
        /// Starts a session with the driver
        /// </summary>
        /// <param name="desiredCapabilities">Capabilities of the browser</param>
        protected void StartSession(ICapabilities desiredCapabilities)
        {
            Dictionary <string, object> parameters = new Dictionary <string, object>();

            // If the object passed into the RemoteWebDriver constructor is a
            // RemoteSessionSettings object, it is expected that all intermediate
            // and end nodes are compliant with the W3C WebDriver Specification,
            // and therefore will already contain all of the appropriate values
            // for establishing a session.
            RemoteSessionSettings remoteSettings = desiredCapabilities as RemoteSessionSettings;

            if (remoteSettings == null)
            {
                Dictionary <string, object> matchCapabilities = this.GetCapabilitiesDictionary(desiredCapabilities);

                List <object> firstMatchCapabilitiesList = new List <object>();
                firstMatchCapabilitiesList.Add(matchCapabilities);

                Dictionary <string, object> specCompliantCapabilitiesDictionary = new Dictionary <string, object>();
                specCompliantCapabilitiesDictionary["firstMatch"] = firstMatchCapabilitiesList;

                parameters.Add("capabilities", specCompliantCapabilitiesDictionary);
            }
            else
            {
                parameters.Add("capabilities", remoteSettings.ToDictionary());
            }

            Response response = this.Execute(DriverCommand.NewSession, parameters);

            Dictionary <string, object> rawCapabilities = response.Value as Dictionary <string, object>;

            if (rawCapabilities == null)
            {
                string errorMessage = string.Format(CultureInfo.InvariantCulture, "The new session command returned a value ('{0}') that is not a valid JSON object.", response.Value);
                throw new WebDriverException(errorMessage);
            }

            ReturnedCapabilities returnedCapabilities = new ReturnedCapabilities(rawCapabilities);

            this.capabilities = returnedCapabilities;
            this.sessionId    = new SessionId(response.SessionId);
        }