コード例 #1
0
        public void FontRequestsNotMade_When_FontRequestSetToBeBlocked_DevTools()
        {
            var devToolssession    = _driver.CreateDevToolsSession();
            var blockedUrlSettings = new SetBlockedURLsCommandSettings();

            blockedUrlSettings.Urls = new string[] { "http://demos.bellatrix.solutions/wp-content/themes/storefront/assets/fonts/fontawesome-webfont.woff2?v=4.7.0" };
            devToolssession.Network.SetBlockedURLs(blockedUrlSettings);

            _driver.Navigate().GoToUrl("http://demos.bellatrix.solutions/");
            IWebElement imageTitle        = _driver.FindElement(By.XPath("//h2[text()='Falcon 9']"));
            IWebElement falconSalesButton = _driver.FindElement(RelativeBy.WithTagName("span").Below(imageTitle));

            falconSalesButton.Click();
        }
コード例 #2
0
        public void GetBookByRelativeLocator()
        {
            driver.Navigate().GoToUrl(homeURL);
            driver.Manage().Window.Maximize();
            WebDriverWait wait = new WebDriverWait(driver,
                                                   System.TimeSpan.FromSeconds(15));

            wait.Until(driver =>
                       driver.FindElement(By.CssSelector("#demo-page")));

            var javaForTestersBook =
                driver.FindElement(
                    RelativeBy.WithTagName("li")
                    // To the left of "Advanced Selenium in Java"
                    .LeftOf(By.Id("pid6"))
                    // And Below "Test Automation in the Real World"
                    .Below(By.Id("pid1")))
                .GetAttribute("id");

            Assert.AreEqual(javaForTestersBook, "pid5");
        }
コード例 #3
0
        public void TestMethod1()
        {
            Assert.AreEqual("My Store", Driver.Title);

            var searchInput  = Driver.FindElement(By.Name("search_query"));
            var searchButton = Driver.FindElement(By.Name("submit_search"));

            searchInput.SendKeys("demo");
            searchButton.Click();

            searchInput = Driver.FindElement(By.Name("search_query"));
            searchInput.SendKeys(" demo 2");

            Driver.FindElement(RelativeBy.WithTagName("button").Above(By.Id("block_top_menu"))).Click();
            searchInput = Driver.FindElement(By.Name("search_query"));
            searchInput.SendKeys(" xxx");

            var session = Driver.CreateDevToolsSession();

            var blockedUrlSettings = new SetBlockedURLsCommandSettings();

            blockedUrlSettings.Urls = new string[] { "http://demos.bellatrix.solutions/wp-content/uploads/2018/04/440px-Launch_Vehicle__Verticalization__Proton-M-324x324.jpg" };
            //  session..SetBlockedURLs(blockedUrlSettings);
        }
コード例 #4
0
        public void ExperimentWithDevTools()
        {
            _driver.Navigate().GoToUrl("http://demos.bellatrix.solutions/");

            var devToolssession = _driver.CreateDevToolsSession();

            var setCacheDisabledCommandSettings = new SetCacheDisabledCommandSettings();

            setCacheDisabledCommandSettings.CacheDisabled = true;
            devToolssession.Network.SetCacheDisabled(setCacheDisabledCommandSettings);
            devToolssession.Network.ClearBrowserCache();

            var setExtraHTTPHeadersCommandSettings = new SetExtraHTTPHeadersCommandSettings();

            setExtraHTTPHeadersCommandSettings.Headers.Add("Accept-Encoding", "gzip, deflate");
            devToolssession.Network.SetExtraHTTPHeaders(setExtraHTTPHeadersCommandSettings);

            var captureScreenshotCommandSettings = new CaptureScreenshotCommandSettings();

            devToolssession.Page.CaptureScreenshot(captureScreenshotCommandSettings);

            EventHandler <LoadingFailedEventArgs> loadingFailed = (sender, e) =>
            {
                Assert.AreEqual(BlockedReason.Inspector, e.BlockedReason);
            };

            EventHandler <RequestInterceptedEventArgs> requestIntercepted = (sender, e) =>
            {
                Assert.IsTrue(e.Request.Url.EndsWith("jpg"));
            };

            RequestPattern requestPattern = new RequestPattern();

            requestPattern.InterceptionStage = InterceptionStage.HeadersReceived;
            requestPattern.ResourceType      = ResourceType.Image;
            requestPattern.UrlPattern        = "*.jpg";
            var setRequestInterceptionCommandSettings = new SetRequestInterceptionCommandSettings();

            setRequestInterceptionCommandSettings.Patterns = new RequestPattern[] { requestPattern };
            devToolssession.Network.SetRequestInterception(setRequestInterceptionCommandSettings);
            devToolssession.Network.RequestIntercepted += requestIntercepted;

            var setUserAgentOverrideCommandSettings = new SetUserAgentOverrideCommandSettings();

            setUserAgentOverrideCommandSettings.UserAgent = "Mozilla/5.0 CK={} (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko";
            devToolssession.Network.SetUserAgentOverride(setUserAgentOverrideCommandSettings);

            var blockedUrlSettings = new SetBlockedURLsCommandSettings();

            blockedUrlSettings.Urls = new string[] { "http://demos.bellatrix.solutions/wp-content/uploads/2018/04/440px-Launch_Vehicle__Verticalization__Proton-M-324x324.jpg" };
            devToolssession.Network.SetBlockedURLs(blockedUrlSettings);

            devToolssession.Performance.Enable();

            IWebElement imageTitle        = _driver.FindElement(By.XPath("//h2[text()='Falcon 9']"));
            IWebElement falconSalesButton = _driver.FindElement(RelativeBy.WithTagName("span").Below(imageTitle));

            falconSalesButton.Click();

            var setIgnoreCertificateErrorsCommandSettings = new SetIgnoreCertificateErrorsCommandSettings();

            setIgnoreCertificateErrorsCommandSettings.Ignore = true;
            devToolssession.Security.SetIgnoreCertificateErrors(setIgnoreCertificateErrorsCommandSettings);

            EventHandler <MessageAddedEventArgs> messageAdded = (sender, e) =>
            {
                Assert.AreEqual("BELLATRIX is cool", e.Message);
            };

            devToolssession.Console.Enable();
            devToolssession.Console.ClearMessages();
            devToolssession.Console.MessageAdded += messageAdded;

            _driver.ExecuteScript("console.log('BELLATRIX is cool');");

            var emulationSettings = new EmulateNetworkConditionsCommandSettings();

            emulationSettings.ConnectionType     = ConnectionType.Cellular3g;
            emulationSettings.DownloadThroughput = 20;
            emulationSettings.Latency            = 1.2;
            emulationSettings.UploadThroughput   = 50;
            devToolssession.Network.EmulateNetworkConditions(emulationSettings);

            var metrics = devToolssession.Performance.GetMetrics();

            foreach (var metric in metrics.Result.Metrics)
            {
                Console.WriteLine($"{metric.Name} = {metric.Value}");
            }
        }