Exemplo n.º 1
0
 public SecurityAdapter(DevToolsSession session)
 {
     m_session = session ?? throw new ArgumentNullException(nameof(session));
     m_session.DevToolsEventReceived   += OnDevToolsEventReceived;
     m_eventMap["certificateError"]     = new DevToolsEventData(typeof(CertificateErrorEventArgs), OnCertificateError);
     m_eventMap["securityStateChanged"] = new DevToolsEventData(typeof(SecurityStateChangedEventArgs), OnSecurityStateChanged);
 }
Exemplo n.º 2
0
        public async Task GoToPage(string url)
        {
            try
            {
                ChromeOptions options = new ChromeOptions();
                options.BinaryLocation = _chromeDriverConfiguration.BrowserPath;
                //Descomenta las siguientes linea para usar el mode HeadLess de Chrome
                //options.AddArgument("--headless");
                //var user_agent = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.50 Safari/537.36";
                //options.AddArgument($"user_agent={user_agent}");
                options.AddArgument("--ignore-certificate-errors");
                options.AddArgument("--disable-blink-features=AutomationControlled");


                // Create an instance of the browser and configure launch options
                using (ChromeDriver driver = new ChromeDriver(_chromeDriverConfiguration.Path, options))
                {
                    DevToolsSession devToolsSession       = driver.GetDevToolsSession();
                    var             fetch                 = devToolsSession.GetVersionSpecificDomains <OpenQA.Selenium.DevTools.V88.DevToolsSessionDomains>().Fetch;
                    var             enableCommandSettings = new OpenQA.Selenium.DevTools.V88.Fetch.EnableCommandSettings();

                    enableCommandSettings.Patterns = new OpenQA.Selenium.DevTools.V88.Fetch.RequestPattern[]
                    {
                        new OpenQA.Selenium.DevTools.V88.Fetch.RequestPattern()
                        {
                            RequestStage = OpenQA.Selenium.DevTools.V88.Fetch.RequestStage.Request,
                            ResourceType = ResourceType.Image,
                        },
                        new OpenQA.Selenium.DevTools.V88.Fetch.RequestPattern()
                        {
                            RequestStage = OpenQA.Selenium.DevTools.V88.Fetch.RequestStage.Request,
                            ResourceType = ResourceType.Stylesheet,
                        }
                    };
                    await fetch.Enable(enableCommandSettings);

                    EventHandler <OpenQA.Selenium.DevTools.V88.Fetch.RequestPausedEventArgs> requestIntercepted = (sender, e) =>
                    {
                        fetch.FailRequest(new OpenQA.Selenium.DevTools.V88.Fetch.FailRequestCommandSettings
                        {
                            RequestId   = e.RequestId,
                            ErrorReason = ErrorReason.BlockedByClient
                        });
                    };

                    fetch.RequestPaused += requestIntercepted;

                    driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(15);
                    driver.Manage().Timeouts().PageLoad     = TimeSpan.FromSeconds(40);


                    driver.Navigate().GoToUrl(String.IsNullOrEmpty(url) ? "https://www.youtube.com/" : url);

                    // Search for input user
                }
            }
            catch (Exception ex)
            {
            }
        }
Exemplo n.º 3
0
 public PageAdapter(DevToolsSession session)
 {
     m_session = session ?? throw new ArgumentNullException(nameof(session));
     m_session.DevToolsEventReceived              += OnDevToolsEventReceived;
     m_eventMap["domContentEventFired"]            = new DevToolsEventData(typeof(DomContentEventFiredEventArgs), OnDomContentEventFired);
     m_eventMap["frameAttached"]                   = new DevToolsEventData(typeof(FrameAttachedEventArgs), OnFrameAttached);
     m_eventMap["frameClearedScheduledNavigation"] = new DevToolsEventData(typeof(FrameClearedScheduledNavigationEventArgs), OnFrameClearedScheduledNavigation);
     m_eventMap["frameDetached"]                   = new DevToolsEventData(typeof(FrameDetachedEventArgs), OnFrameDetached);
     m_eventMap["frameNavigated"]                  = new DevToolsEventData(typeof(FrameNavigatedEventArgs), OnFrameNavigated);
     m_eventMap["frameResized"]                = new DevToolsEventData(typeof(FrameResizedEventArgs), OnFrameResized);
     m_eventMap["frameRequestedNavigation"]    = new DevToolsEventData(typeof(FrameRequestedNavigationEventArgs), OnFrameRequestedNavigation);
     m_eventMap["frameScheduledNavigation"]    = new DevToolsEventData(typeof(FrameScheduledNavigationEventArgs), OnFrameScheduledNavigation);
     m_eventMap["frameStartedLoading"]         = new DevToolsEventData(typeof(FrameStartedLoadingEventArgs), OnFrameStartedLoading);
     m_eventMap["frameStoppedLoading"]         = new DevToolsEventData(typeof(FrameStoppedLoadingEventArgs), OnFrameStoppedLoading);
     m_eventMap["interstitialHidden"]          = new DevToolsEventData(typeof(InterstitialHiddenEventArgs), OnInterstitialHidden);
     m_eventMap["interstitialShown"]           = new DevToolsEventData(typeof(InterstitialShownEventArgs), OnInterstitialShown);
     m_eventMap["javascriptDialogClosed"]      = new DevToolsEventData(typeof(JavascriptDialogClosedEventArgs), OnJavascriptDialogClosed);
     m_eventMap["javascriptDialogOpening"]     = new DevToolsEventData(typeof(JavascriptDialogOpeningEventArgs), OnJavascriptDialogOpening);
     m_eventMap["lifecycleEvent"]              = new DevToolsEventData(typeof(LifecycleEventEventArgs), OnLifecycleEvent);
     m_eventMap["loadEventFired"]              = new DevToolsEventData(typeof(LoadEventFiredEventArgs), OnLoadEventFired);
     m_eventMap["navigatedWithinDocument"]     = new DevToolsEventData(typeof(NavigatedWithinDocumentEventArgs), OnNavigatedWithinDocument);
     m_eventMap["screencastFrame"]             = new DevToolsEventData(typeof(ScreencastFrameEventArgs), OnScreencastFrame);
     m_eventMap["screencastVisibilityChanged"] = new DevToolsEventData(typeof(ScreencastVisibilityChangedEventArgs), OnScreencastVisibilityChanged);
     m_eventMap["windowOpen"] = new DevToolsEventData(typeof(WindowOpenEventArgs), OnWindowOpen);
     m_eventMap["compilationCacheProduced"] = new DevToolsEventData(typeof(CompilationCacheProducedEventArgs), OnCompilationCacheProduced);
 }
Exemplo n.º 4
0
        /// <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);
            }
        }
Exemplo n.º 5
0
 public ProfilerAdapter(DevToolsSession session)
 {
     m_session = session ?? throw new ArgumentNullException(nameof(session));
     m_session.DevToolsEventReceived     += OnDevToolsEventReceived;
     m_eventMap["consoleProfileFinished"] = new DevToolsEventData(typeof(ConsoleProfileFinishedEventArgs), OnConsoleProfileFinished);
     m_eventMap["consoleProfileStarted"]  = new DevToolsEventData(typeof(ConsoleProfileStartedEventArgs), OnConsoleProfileStarted);
 }
Exemplo n.º 6
0
 public DebuggerAdapter(DevToolsSession session)
 {
     m_session = session ?? throw new ArgumentNullException(nameof(session));
     m_session.DevToolsEventReceived  += OnDevToolsEventReceived;
     m_eventMap["breakpointResolved"]  = new DevToolsEventData(typeof(BreakpointResolvedEventArgs), OnBreakpointResolved);
     m_eventMap["paused"]              = new DevToolsEventData(typeof(PausedEventArgs), OnPaused);
     m_eventMap["resumed"]             = new DevToolsEventData(typeof(ResumedEventArgs), OnResumed);
     m_eventMap["scriptFailedToParse"] = new DevToolsEventData(typeof(ScriptFailedToParseEventArgs), OnScriptFailedToParse);
     m_eventMap["scriptParsed"]        = new DevToolsEventData(typeof(ScriptParsedEventArgs), OnScriptParsed);
 }
Exemplo n.º 7
0
 public void Setup()
 {
     _driver = new ChromeDriver();
     _driver.Manage().Window.Maximize();
     _devTools = _driver as IDevTools;
     if (_devTools != null)
     {
         _session = _devTools.CreateDevToolsSession();
     }
 }
Exemplo n.º 8
0
        public void Setup()
        {
            //Set ChromeDriver
            driver = new ChromeDriver();
            //Get DevTools
            IDevTools devTools = driver as IDevTools;

            //DevTools Session
            session = devTools.CreateDevToolsSession();
        }
Exemplo n.º 9
0
 public TargetAdapter(DevToolsSession session)
 {
     m_session = session ?? throw new ArgumentNullException(nameof(session));
     m_session.DevToolsEventReceived        += OnDevToolsEventReceived;
     m_eventMap["attachedToTarget"]          = new DevToolsEventData(typeof(AttachedToTargetEventArgs), OnAttachedToTarget);
     m_eventMap["detachedFromTarget"]        = new DevToolsEventData(typeof(DetachedFromTargetEventArgs), OnDetachedFromTarget);
     m_eventMap["receivedMessageFromTarget"] = new DevToolsEventData(typeof(ReceivedMessageFromTargetEventArgs), OnReceivedMessageFromTarget);
     m_eventMap["targetCreated"]             = new DevToolsEventData(typeof(TargetCreatedEventArgs), OnTargetCreated);
     m_eventMap["targetDestroyed"]           = new DevToolsEventData(typeof(TargetDestroyedEventArgs), OnTargetDestroyed);
     m_eventMap["targetCrashed"]             = new DevToolsEventData(typeof(TargetCrashedEventArgs), OnTargetCrashed);
     m_eventMap["targetInfoChanged"]         = new DevToolsEventData(typeof(TargetInfoChangedEventArgs), OnTargetInfoChanged);
 }
Exemplo n.º 10
0
 public RuntimeAdapter(DevToolsSession session)
 {
     m_session = session ?? throw new ArgumentNullException(nameof(session));
     m_session.DevToolsEventReceived        += OnDevToolsEventReceived;
     m_eventMap["bindingCalled"]             = new DevToolsEventData(typeof(BindingCalledEventArgs), OnBindingCalled);
     m_eventMap["consoleAPICalled"]          = new DevToolsEventData(typeof(ConsoleAPICalledEventArgs), OnConsoleAPICalled);
     m_eventMap["exceptionRevoked"]          = new DevToolsEventData(typeof(ExceptionRevokedEventArgs), OnExceptionRevoked);
     m_eventMap["exceptionThrown"]           = new DevToolsEventData(typeof(ExceptionThrownEventArgs), OnExceptionThrown);
     m_eventMap["executionContextCreated"]   = new DevToolsEventData(typeof(ExecutionContextCreatedEventArgs), OnExecutionContextCreated);
     m_eventMap["executionContextDestroyed"] = new DevToolsEventData(typeof(ExecutionContextDestroyedEventArgs), OnExecutionContextDestroyed);
     m_eventMap["executionContextsCleared"]  = new DevToolsEventData(typeof(ExecutionContextsClearedEventArgs), OnExecutionContextsCleared);
     m_eventMap["inspectRequested"]          = new DevToolsEventData(typeof(InspectRequestedEventArgs), OnInspectRequested);
 }
Exemplo n.º 11
0
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (this.devToolsSession != null)
                {
                    this.devToolsSession.Dispose();
                    this.devToolsSession = null;
                }
            }

            base.Dispose(disposing);
        }
Exemplo n.º 12
0
        public void SetAddionalHeaders()
        {
            IDevTools       devTools    = _driver as IDevTools;
            DevToolsSession session     = devTools.GetDevToolsSession();
            var             extraHeader = new Network.Headers();

            extraHeader.Add("headerName", "executeHacked");
            session.SendCommand(new Network.SetExtraHTTPHeadersCommandSettings()
            {
                Headers = extraHeader
            });

            _driver.Url = "https://www.executeautomation.com";
        }
Exemplo n.º 13
0
        /// <summary>
        /// Ignoring relative locators for a moment - use chrome devtools protocol to interact with the chrome console.
        /// </summary>
        /// <returns></returns>
        public async Task SetupCdpAsync()
        {
            // Cast to role-based interface without throwing exception.
            IDevTools devTools = driver as IDevTools;

            if (devTools == null)
            {
                throw new Exception("Driver instance does not support CDP integration");
            }

            DevToolsSession session = devTools.CreateDevToolsSession();

            string expected = "Hello Selenium";
            string actual   = string.Empty;

            // Two things to note here. First, use a synchronization
            // object allow us to wait for the event to fire. Second,
            // we set up an EventHandler<T> instance so we can properly
            // detach from the event once we're done. "Console" here
            // is "OpenQA.Selenium.DevTools.Console".
            ManualResetEventSlim sync = new ManualResetEventSlim(false);
            EventHandler <MessageAddedEventArgs> messageAddedHandler = (sender, e) =>
            {
                actual = e.Message.Text;
                sync.Set();
            };

            // Attach the event handler
            session.Console.MessageAdded += messageAddedHandler;

            // Enable the Console CDP domain. Note this is an async API.
            await session.Console.Enable();

            // Navigate to a page, and execute JavaScript to write to the console.
            driver.Url = "https://automationbookstore.dev/";
            ((IJavaScriptExecutor)driver).ExecuteScript("console.log('" + expected + "');");

            // Wait up to five seconds for the event to have fired.
            sync.Wait(TimeSpan.FromSeconds(5));

            // Detach the event handler, and disable the Console domain.
            session.Console.MessageAdded -= messageAddedHandler;
            await session.Console.Disable();

            Console.WriteLine("Expected message: {0}", expected);
            Console.WriteLine("Actual message: {0}", actual);
            Console.WriteLine("Messages are equal: {0}", expected == actual);
        }
Exemplo n.º 14
0
 public DOMAdapter(DevToolsSession session)
 {
     m_session = session ?? throw new ArgumentNullException(nameof(session));
     m_session.DevToolsEventReceived      += OnDevToolsEventReceived;
     m_eventMap["attributeModified"]       = new DevToolsEventData(typeof(AttributeModifiedEventArgs), OnAttributeModified);
     m_eventMap["attributeRemoved"]        = new DevToolsEventData(typeof(AttributeRemovedEventArgs), OnAttributeRemoved);
     m_eventMap["characterDataModified"]   = new DevToolsEventData(typeof(CharacterDataModifiedEventArgs), OnCharacterDataModified);
     m_eventMap["childNodeCountUpdated"]   = new DevToolsEventData(typeof(ChildNodeCountUpdatedEventArgs), OnChildNodeCountUpdated);
     m_eventMap["childNodeInserted"]       = new DevToolsEventData(typeof(ChildNodeInsertedEventArgs), OnChildNodeInserted);
     m_eventMap["childNodeRemoved"]        = new DevToolsEventData(typeof(ChildNodeRemovedEventArgs), OnChildNodeRemoved);
     m_eventMap["distributedNodesUpdated"] = new DevToolsEventData(typeof(DistributedNodesUpdatedEventArgs), OnDistributedNodesUpdated);
     m_eventMap["documentUpdated"]         = new DevToolsEventData(typeof(DocumentUpdatedEventArgs), OnDocumentUpdated);
     m_eventMap["inlineStyleInvalidated"]  = new DevToolsEventData(typeof(InlineStyleInvalidatedEventArgs), OnInlineStyleInvalidated);
     m_eventMap["pseudoElementAdded"]      = new DevToolsEventData(typeof(PseudoElementAddedEventArgs), OnPseudoElementAdded);
     m_eventMap["pseudoElementRemoved"]    = new DevToolsEventData(typeof(PseudoElementRemovedEventArgs), OnPseudoElementRemoved);
     m_eventMap["setChildNodes"]           = new DevToolsEventData(typeof(SetChildNodesEventArgs), OnSetChildNodes);
     m_eventMap["shadowRootPopped"]        = new DevToolsEventData(typeof(ShadowRootPoppedEventArgs), OnShadowRootPopped);
     m_eventMap["shadowRootPushed"]        = new DevToolsEventData(typeof(ShadowRootPushedEventArgs), OnShadowRootPushed);
 }
Exemplo n.º 15
0
        public async Task NetworkIntercerptAsync()
        {
            _driver.Navigate().GoToUrl("http://www.google.com?gl=us");
            IDevTools       devTools = _driver as IDevTools;
            DevToolsSession session  = devTools.GetDevToolsSession();
            await session.SendCommand(new EnableCommandSettings());

            var metricsResponse =
                await session.SendCommand <GetMetricsCommandSettings, GetMetricsCommandResponse>(
                    new GetMetricsCommandSettings());

            _driver.Navigate().GoToUrl("http://www.google.com");
            _driver.Quit();

            var metrics = metricsResponse.Metrics;

            foreach (Metric metric in metrics)
            {
                Console.WriteLine("{0} = {1}", metric.Name, metric.Value);
            }
        }
Exemplo n.º 16
0
 public NetworkAdapter(DevToolsSession session)
 {
     m_session = session ?? throw new ArgumentNullException(nameof(session));
     m_session.DevToolsEventReceived                 += OnDevToolsEventReceived;
     m_eventMap["dataReceived"]                       = new DevToolsEventData(typeof(DataReceivedEventArgs), OnDataReceived);
     m_eventMap["eventSourceMessageReceived"]         = new DevToolsEventData(typeof(EventSourceMessageReceivedEventArgs), OnEventSourceMessageReceived);
     m_eventMap["loadingFailed"]                      = new DevToolsEventData(typeof(LoadingFailedEventArgs), OnLoadingFailed);
     m_eventMap["loadingFinished"]                    = new DevToolsEventData(typeof(LoadingFinishedEventArgs), OnLoadingFinished);
     m_eventMap["requestIntercepted"]                 = new DevToolsEventData(typeof(RequestInterceptedEventArgs), OnRequestIntercepted);
     m_eventMap["requestServedFromCache"]             = new DevToolsEventData(typeof(RequestServedFromCacheEventArgs), OnRequestServedFromCache);
     m_eventMap["requestWillBeSent"]                  = new DevToolsEventData(typeof(RequestWillBeSentEventArgs), OnRequestWillBeSent);
     m_eventMap["resourceChangedPriority"]            = new DevToolsEventData(typeof(ResourceChangedPriorityEventArgs), OnResourceChangedPriority);
     m_eventMap["signedExchangeReceived"]             = new DevToolsEventData(typeof(SignedExchangeReceivedEventArgs), OnSignedExchangeReceived);
     m_eventMap["responseReceived"]                   = new DevToolsEventData(typeof(ResponseReceivedEventArgs), OnResponseReceived);
     m_eventMap["webSocketClosed"]                    = new DevToolsEventData(typeof(WebSocketClosedEventArgs), OnWebSocketClosed);
     m_eventMap["webSocketCreated"]                   = new DevToolsEventData(typeof(WebSocketCreatedEventArgs), OnWebSocketCreated);
     m_eventMap["webSocketFrameError"]                = new DevToolsEventData(typeof(WebSocketFrameErrorEventArgs), OnWebSocketFrameError);
     m_eventMap["webSocketFrameReceived"]             = new DevToolsEventData(typeof(WebSocketFrameReceivedEventArgs), OnWebSocketFrameReceived);
     m_eventMap["webSocketFrameSent"]                 = new DevToolsEventData(typeof(WebSocketFrameSentEventArgs), OnWebSocketFrameSent);
     m_eventMap["webSocketHandshakeResponseReceived"] = new DevToolsEventData(typeof(WebSocketHandshakeResponseReceivedEventArgs), OnWebSocketHandshakeResponseReceived);
     m_eventMap["webSocketWillSendHandshakeRequest"]  = new DevToolsEventData(typeof(WebSocketWillSendHandshakeRequestEventArgs), OnWebSocketWillSendHandshakeRequest);
 }
Exemplo n.º 17
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);
        }
Exemplo n.º 18
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);
        }
Exemplo n.º 19
0
 public InputAdapter(DevToolsSession session)
 {
     m_session = session ?? throw new ArgumentNullException(nameof(session));
     m_session.DevToolsEventReceived += OnDevToolsEventReceived;
 }
Exemplo n.º 20
0
 public DevToolsService(IWebDriver wrappedDriver)
     : base(wrappedDriver)
 {
     DevToolsSession        = ((IDevTools)wrappedDriver).GetDevToolsSession();
     DevToolsSessionDomains = DevToolsSession.GetVersionSpecificDomains <DevToolsSessionDomains>();
 }
Exemplo n.º 21
0
 public EmulationAdapter(DevToolsSession session)
 {
     m_session = session ?? throw new ArgumentNullException(nameof(session));
     m_session.DevToolsEventReceived       += OnDevToolsEventReceived;
     m_eventMap["virtualTimeBudgetExpired"] = new DevToolsEventData(typeof(VirtualTimeBudgetExpiredEventArgs), OnVirtualTimeBudgetExpired);
 }
Exemplo n.º 22
0
 public PerformanceAdapter(DevToolsSession session)
 {
     m_session = session ?? throw new ArgumentNullException(nameof(session));
     m_session.DevToolsEventReceived += OnDevToolsEventReceived;
     m_eventMap["metrics"]            = new DevToolsEventData(typeof(MetricsEventArgs), OnMetrics);
 }
Exemplo n.º 23
0
 public LogAdapter(DevToolsSession session)
 {
     m_session = session ?? throw new ArgumentNullException(nameof(session));
     m_session.DevToolsEventReceived += OnDevToolsEventReceived;
     m_eventMap["entryAdded"]         = new DevToolsEventData(typeof(EntryAddedEventArgs), OnEntryAdded);
 }
Exemplo n.º 24
0
 public V89Domains(DevToolsSession session)
 {
     this.domains = new DevToolsSessionDomains(session);
 }
Exemplo n.º 25
0
        /// <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 DevToolsSession CreateDevToolsSession()
        {
            if (!this.Capabilities.HasCapability(ChromiumOptions.DefaultCapability))
            {
                throw new WebDriverException("Cannot find " + ChromiumOptions.DefaultCapability + " capability for driver");
            }

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

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

            if (!options.ContainsKey("debuggerAddress"))
            {
                throw new WebDriverException("Did not find debuggerAddress capability in goog:chromeOptions");
            }

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

            try
            {
                string debuggerUrl     = string.Format(CultureInfo.InvariantCulture, "http://{0}/", debuggerAddress);
                string rawDebuggerInfo = string.Empty;
                using (HttpClient client = new HttpClient())
                {
                    client.BaseAddress = new Uri(debuggerUrl);
                    rawDebuggerInfo    = client.GetStringAsync("/json").ConfigureAwait(false).GetAwaiter().GetResult();
                }

                string webSocketUrl = null;
                string targetId     = null;
                var    sessions     = JsonConvert.DeserializeObject <ICollection <DevToolsSessionInfo> >(rawDebuggerInfo);
                foreach (var target in sessions)
                {
                    if (target.Type == "page")
                    {
                        targetId     = target.Id;
                        webSocketUrl = target.WebSocketDebuggerUrl;
                        break;
                    }
                }

                DevToolsSession session = new DevToolsSession(webSocketUrl);
                var             foo     = session.Target.AttachToTarget(new DevTools.Target.AttachToTargetCommandSettings()
                {
                    TargetId = targetId
                }).ConfigureAwait(false).GetAwaiter().GetResult();
                var t1 = session.Target.SetAutoAttach(new DevTools.Target.SetAutoAttachCommandSettings()
                {
                    AutoAttach = true, WaitForDebuggerOnStart = false
                }).ConfigureAwait(false).GetAwaiter().GetResult();
                var t2 = session.Log.Clear().ConfigureAwait(false).GetAwaiter().GetResult();
                return(session);
            }
            catch (Exception e)
            {
                throw new WebDriverException("Unexpected error creating WebSocket DevTools session.", e);
            }
        }