private void DriverDevTools()
 {
     devTools        = WebDriver as IDevTools;
     session         = devTools.GetDevToolsSession();
     devToolsSession = session.GetVersionSpecificDomains <DevToolsSessionDomains>();
     devToolsSession.Network.Enable(new Network.EnableCommandSettings());
 }
Exemplo n.º 2
0
 public void Setup()
 {
     driver   = EnvironmentManager.Instance.CreateFreshDriver();
     devTools = driver as IDevTools;
     if (devTools != null)
     {
         session = devTools.CreateDevToolsSession();
     }
 }
Exemplo n.º 3
0
        public void Setup()
        {
            //Set ChromeDriver
            driver = new ChromeDriver();
            //Get DevTools
            IDevTools devTools = driver as IDevTools;

            //DevTools Session
            session = devTools.CreateDevToolsSession();
        }
Exemplo n.º 4
0
        public void Setup()
        {
            driver   = EnvironmentManager.Instance.GetCurrentDriver();
            devTools = driver as IDevTools;
            if (devTools == null)
            {
                Assert.Ignore("{0} does not support Chrome DevTools Protocol", EnvironmentManager.Instance.Browser);
                return;
            }

            session = devTools.CreateDevToolsSession();
        }
Exemplo n.º 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RemoteJavaScriptEngine"/> class.
        /// </summary>
        /// <param name="driver">The <see cref="IWebDriver"/> instance in which the JavaScript engine is executing.</param>
        public RemoteJavaScriptEngine(IWebDriver driver)
        {
            this.session = new Lazy <DevToolsSession>(() =>
            {
                IDevTools devToolsDriver = driver as IDevTools;
                if (session == null)
                {
                    throw new WebDriverException("Driver must implement IDevTools to use these features");
                }

                return(devToolsDriver.GetDevToolsSession());
            });
        }
Exemplo n.º 6
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.º 7
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.º 8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RemoteNetwork"/> class.
        /// </summary>
        /// <param name="driver">The <see cref="IWebDriver"/> instance on which the network should be monitored.</param>
        public RemoteNetwork(IWebDriver driver)
        {
            // Use of Lazy<T> means this exception won't be thrown until the user first
            // attempts to access the DevTools session, probably on the first call to
            // StartMonitoring().
            this.session = new Lazy <DevToolsSession>(() =>
            {
                IDevTools devToolsDriver = driver as IDevTools;
                if (session == null)
                {
                    throw new WebDriverException("Driver must implement IDevTools to use these features");
                }

                return(devToolsDriver.GetDevToolsSession());
            });
        }
Exemplo n.º 9
0
        public void Setup()
        {
            new DriverManager().SetUpDriver(new ChromeConfig());
            ChromeOptions chromeOptions = new ChromeOptions();

            chromeOptions.AddArguments("--headless");
            //Set ChromeDriver
            driver = new ChromeDriver();
            //Get DevTools
            IDevTools devTools = driver as IDevTools;

            //DevTools Session
            session = devTools.GetDevToolsSession();

            devToolsSession = session.GetVersionSpecificDomains <DevToolsSessionDomains>();
            devToolsSession.Network.Enable(new Network.EnableCommandSettings());
        }
Exemplo n.º 10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="JavaScriptEngine"/> class.
        /// </summary>
        /// <param name="driver">The <see cref="IWebDriver"/> instance in which the JavaScript engine is executing.</param>
        public JavaScriptEngine(IWebDriver driver)
        {
            // Use of Lazy<T> means this exception won't be thrown until the user first
            // attempts to access the DevTools session, probably on the first call to
            // StartEventMonitoring() or in adding scripts to the instance.
            this.driver  = driver;
            this.session = new Lazy <DevToolsSession>(() =>
            {
                IDevTools devToolsDriver = driver as IDevTools;
                if (devToolsDriver == null)
                {
                    throw new WebDriverException("Driver must implement IDevTools to use these features");
                }

                return(devToolsDriver.GetDevToolsSession());
            });
        }
Exemplo n.º 11
0
        static void Main(string[] args)
        {
            var       driver  = new ChromeDriver();
            IDevTools devTool = driver;
            var       session = devTool.GetDevToolsSession();
            var       domains = session.GetVersionSpecificDomains <DevToolsSessionDomains>();

            domains.Page.Enable(new EnableCommandSettings());
            domains.Page.AddScriptToEvaluateOnNewDocument(new AddScriptToEvaluateOnNewDocumentCommandSettings()
            {
                Source = "Object.defineProperty(navigator, 'webdriver', { get: () => undefined });" +
                         @"Object.defineProperty(navigator, 'platform', { get: () => 'MacOS'}); " +
                         ""
            });
            driver.Navigate().GoToUrl("https://selenium.dev");
            driver.Quit();
        }
Exemplo n.º 12
0
        public DevSession(IWebDriver driver)
        {
            this.driver = driver;

            devTools = driver as IDevTools;
            session  = devTools.CreateDevToolsSession();
            session.Network.Enable(new OpenQA.Selenium.DevTools.Network.EnableCommandSettings());

            session.Network.SetBlockedURLs(new OpenQA.Selenium.DevTools.Network.SetBlockedURLsCommandSettings()
            {
                Urls = new string[] {
                    "https://metrika.mos.ru",
                    "https://mc.yandex.ru/webvisor/",
                    "https://www.mos.ru/etp/SioprRest/getPeriod"
                }
            });
            blockUrls = new List <string>();
        }
        public void Setup()
        {
            driver = new ChromeDriver();
            IDevTools devTools = driver as IDevTools;
            var       session  = devTools.CreateDevToolsSession();

            var blockedUrlSettings = new SetBlockedURLsCommandSettings();

            blockedUrlSettings.Urls = new string[]
            {
                "*://*.jpg",
                "*://automationpractice.com/modules/blockbanner/img/sale70.png",
            };

            session.Network.Enable(new EnableCommandSettings());
            session.Network.SetBlockedURLs(blockedUrlSettings);
            driver.Manage().Window.Maximize();
            driver.Navigate().GoToUrl("http://automationpractice.com/");
            Thread.Sleep(10000);
        }
Exemplo n.º 14
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);
            }
        }