/// <summary>
        /// Creates a session to communicate with a browser using the Chromium Developer Tools debugging protocol.
        /// </summary>
        /// <returns>The active session to use to communicate with the Chromium Developer Tools debugging protocol.</returns>
        public IDevToolsSession CreateDevToolsSession()
        {
            if (!this.Capabilities.HasCapability(this.optionsCapabilityName))
            {
                throw new WebDriverException("Cannot find " + this.optionsCapabilityName + " capability for driver");
            }

            Dictionary <string, object> options = this.Capabilities.GetCapability(this.optionsCapabilityName) as Dictionary <string, object>;

            if (options == null)
            {
                throw new WebDriverException("Found " + this.optionsCapabilityName + " capability, but is not an object");
            }

            if (!options.ContainsKey("debuggerAddress"))
            {
                throw new WebDriverException("Did not find debuggerAddress capability in " + this.optionsCapabilityName);
            }

            string debuggerAddress = options["debuggerAddress"].ToString();

            try
            {
                DevToolsSession session = new DevToolsSession(debuggerAddress);
                session.Start().ConfigureAwait(false).GetAwaiter().GetResult();
                return(session);
            }
            catch (Exception e)
            {
                throw new WebDriverException("Unexpected error creating WebSocket DevTools session.", e);
            }
        }
Exemple #2
0
        public DevToolsSession GetDevToolsSession(int protocolVersion)
        {
            if (this.devToolsSession == null)
            {
                if (!this.Capabilities.HasCapability(RemoteDevToolsEndPointCapabilityName))
                {
                    throw new WebDriverException("Cannot find " + RemoteDevToolsEndPointCapabilityName + " capability for driver");
                }

                if (!this.Capabilities.HasCapability(RemoteDevToolsVersionCapabilityName))
                {
                    throw new WebDriverException("Cannot find " + RemoteDevToolsVersionCapabilityName + " capability for driver");
                }

                string debuggerAddress = this.Capabilities.GetCapability(RemoteDevToolsEndPointCapabilityName).ToString();
                string version         = this.Capabilities.GetCapability(RemoteDevToolsVersionCapabilityName).ToString();

                bool versionParsed = int.TryParse(version.Substring(0, version.IndexOf(".")), out int devToolsProtocolVersion);
                if (!versionParsed)
                {
                    throw new WebDriverException("Cannot parse protocol version from reported version string: " + version);
                }

                try
                {
                    DevToolsSession session = new DevToolsSession(debuggerAddress);
                    session.Start(devToolsProtocolVersion).ConfigureAwait(false).GetAwaiter().GetResult();
                    this.devToolsSession = session;
                }
                catch (Exception e)
                {
                    throw new WebDriverException("Unexpected error creating WebSocket DevTools session.", e);
                }
            }

            return(this.devToolsSession);
        }
Exemple #3
0
        /// <summary>
        /// Creates a session to communicate with a browser using the Chromium Developer Tools debugging protocol.
        /// </summary>
        /// <param name="devToolsProtocolVersion">The version of the Chromium Developer Tools protocol to use. Defaults to autodetect the protocol version.</param>
        /// <returns>The active session to use to communicate with the Chromium Developer Tools debugging protocol.</returns>
        public DevToolsSession GetDevToolsSession(int devToolsProtocolVersion)
        {
            if (this.devToolsSession == null)
            {
                if (!this.Capabilities.HasCapability(FirefoxDevToolsCapabilityName))
                {
                    throw new WebDriverException("Cannot find " + FirefoxDevToolsCapabilityName + " capability for driver");
                }

                string debuggerAddress = this.Capabilities.GetCapability(FirefoxDevToolsCapabilityName).ToString();
                try
                {
                    DevToolsSession session = new DevToolsSession(debuggerAddress);
                    session.Start(devToolsProtocolVersion).ConfigureAwait(false).GetAwaiter().GetResult();
                    this.devToolsSession = session;
                }
                catch (Exception e)
                {
                    throw new WebDriverException("Unexpected error creating WebSocket DevTools session.", e);
                }
            }

            return(this.devToolsSession);
        }