Ejemplo n.º 1
0
        public void Run(ConfigurationParameters config, List <SitecoreItem> sitecoreItems)
        {
            string screenShotsFolder = CreateScreenShotDirectory();

            var checker = new WebDriverPageChecker(screenShotsFolder);

            FileStream   outputFile = CreateOutputFile(OutputFilename);
            StreamWriter writer     = new StreamWriter(outputFile);
            int          index      = 0;

            foreach (SitecoreItem sitecoreItem in sitecoreItems)
            {
                if (index == 0)
                {
                    writer.WriteLine("Full URL,Success?,Item path");
                }

                PageCheckResult result = checker.PageResponseValid(config.BaseUrl, sitecoreItem);

                writer.WriteLine($"{config.BaseUrl}{sitecoreItem.ExternalUrl},{result?.Success},{sitecoreItem.ItemPath}");
                index++;
            }

            checker.Close();

            writer.Flush();
            writer.Close();
        }
        public void Web_driver_checker_fails_test_if_page_does_not_contain_body_element()
        {
            // Arrange
            var webDriver  = new Mock <IWebDriver>();
            var navigation = new Mock <INavigation>();
            var options    = new Mock <IOptions>();
            var window     = new Mock <IWindow>();

            options.Setup(x => x.Window).Returns(window.Object);
            navigation.Setup(x => x.GoToUrl(It.IsAny <Uri>()));
            webDriver.Setup(x => x.Navigate()).Returns(navigation.Object);
            webDriver.Setup(x => x.Manage()).Returns(options.Object);
            webDriver.As <ITakesScreenshot>().Setup(x => x.GetScreenshot()).Returns(null as Screenshot);

            var element = new Mock <IWebElement>();

            webDriver.Setup(x => x.FindElement(It.IsAny <By>())).ReturnsInOrder(element.Object, null);

            var pageChecker = new WebDriverPageChecker(webDriver.Object, "folder-name");

            // Act
            var status = pageChecker.PageResponseValid("http://baseurl", new SitecoreItem {
                ExternalUrl = "/test", ItemPath = "/sitecore/test"
            });

            // Assert
            Assert.IsFalse(status.Success);
        }