public void Setup()
 {
     driver   = EnvironmentManager.Instance.CreateFreshDriver();
     devTools = driver as IDevTools;
     if (devTools != null)
     {
         session = devTools.CreateDevToolsSession();
     }
 }
Example #2
0
        public void Setup()
        {
            //Set ChromeDriver
            driver = new ChromeDriver();
            //Get DevTools
            IDevTools devTools = driver as IDevTools;

            //DevTools Session
            session = devTools.CreateDevToolsSession();
        }
        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();
        }
Example #4
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);
        }
Example #5
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);
        }