Example #1
0
        /// <summary>
        /// Run axe accessibility and log the results
        /// </summary>
        /// <param name="webDriver">The web driver that is on the page you want to run the accessibility check on</param>
        /// <param name="logger">Where you want the check logged to</param>
        /// <param name="throwOnViolation">Should violations cause and exception to be thrown</param>
        public static void CheckAccessibility(this IWebDriver webDriver, Logger logger, bool throwOnViolation = false)
        {
            MessageType type = logger.GetLoggingLevel();

            // Look at passed
            if (type == MessageType.VERBOSE && GetReadableAxeResults("Passes", webDriver, webDriver.Analyze().Passes, out string axeText))
            {
                logger.LogMessage(MessageType.VERBOSE, axeText);
            }

            // Look at inapplicable
            if (type == MessageType.VERBOSE && GetReadableAxeResults("Inapplicable", webDriver, webDriver.Analyze().Inapplicable, out axeText))
            {
                logger.LogMessage(MessageType.VERBOSE, axeText);
            }

            // Look at incomplete
            if (type > MessageType.SUCCESS && GetReadableAxeResults("Incomplete", webDriver, webDriver.Analyze().Incomplete, out axeText))
            {
                logger.LogMessage(MessageType.INFORMATION, axeText);
            }

            // Look at violations
            if (GetReadableAxeResults("Violations", webDriver, webDriver.Analyze().Violations, out axeText))
            {
                if (throwOnViolation)
                {
                    throw new ApplicationException(axeText);
                }
                else
                {
                    logger.LogMessage(MessageType.WARNING, axeText);
                }
            }
        }
        public void TestAnalyzeTarget()
        {
            _webDriver.Navigate().GoToUrl(TargetTestUrl);
            AxeResult results = _webDriver.Analyze();

            results.Should().NotBeNull(nameof(results));
        }
Example #3
0
        //[DataRow("Firefox")]
        public void TestAnalyzeTarget(string browser)
        {
            this.InitDriver(browser);
            _webDriver.Navigate().GoToUrl(TargetTestUrl);
            // wait for email input box is found
            _wait.Until(drv => drv.FindElement(By.XPath("//input[@title='Search']")));
            AxeResult results = _webDriver.Analyze();

            results.Should().NotBeNull(nameof(results));
        }
        public void RunScanOnGivenElement(string browser)
        {
            InitDriver(browser);
            LoadSimpleTestPage();

            var mainElement = _wait.Until(drv => drv.FindElement(By.TagName(mainElementSelector)));

            AxeResult results = _webDriver.Analyze(mainElement);

            results.Violations.Should().HaveCount(3);
        }
Example #5
0
        /// <summary>
        /// Create a HTML accessibility report for a specific web element and all of it's children
        /// </summary>
        /// <param name="webDriver">The WebDriver</param>
        /// <param name="testObject">The TestObject to associate the report with</param>
        /// <param name="element">The WebElement you want to use as the root for your accessibility scan</param>
        /// <param name="throwOnViolation">Should violations cause and exception to be thrown</param>
        public static void CreateAccessibilityHtmlReport(this IWebDriver webDriver, SeleniumTestObject testObject, IWebElement element, bool throwOnViolation = false)
        {
            // If we are using a lazy element go get the raw element instead
            LazyElement raw = element as LazyElement;

            if (raw != null)
            {
                element = ((LazyElement)element).GetRawExistingElement();
            }

            CreateAccessibilityHtmlReport(element, testObject, () => webDriver.Analyze(element), throwOnViolation);
        }
        public void AxeAnalyzer(IWebDriver webDriver, string axeFile)
        {
            using (StreamWriter sw = new StreamWriter(axeFile, append: true))
            {
                AxeResult results = _webDriver.Analyze();

                if (results.Passes.Length > 0)
                {
                    sw.WriteLine("Service: " + _webDriver.Title);
                    while (_i < (_webDriver.Title.Length + 9))
                    {
                        sw.Write("=");
                        _i++;
                    }
                    sw.WriteLine("\n");
                    sw.WriteLine("URL: " + _webDriver.Url.ToLower());

                    if (results.Violations.Length > 0)
                    {
                        foreach (var violation in results.Violations)
                        {
                            sw.WriteLine("Id: " + violation.Id);
                            sw.WriteLine("Description: " + violation.Description);
                            sw.WriteLine("Impact: " + violation.Impact);
                            sw.WriteLine("Help: " + violation.Help);
                            sw.WriteLine("HelpURL: " + violation.HelpUrl);
                            foreach (var node in violation.Nodes)
                            {
                                sw.WriteLine(node.Html);
                                sw.WriteLine("\n");
                            }
                        }
                    }
                }
            }
        }
Example #7
0
 /// <summary>
 /// Run axe accessibility and log the results
 /// </summary>
 /// <param name="webDriver">The web driver that is on the page you want to run the accessibility check on</param>
 /// <param name="logger">Where you want the check logged to</param>
 /// <param name="loggingLevel">What level should logging the check take, this gets used if the check doesn't throw an exception</param>
 /// <param name="throwOnViolation">Should violations cause and exception to be thrown</param>
 public static void CheckAccessibilityViolations(this IWebDriver webDriver, Logger logger, MessageType loggingLevel, bool throwOnViolation = false)
 {
     CheckAccessibility(webDriver, logger, AccessibilityCheckType.Violations.ToString(), () => webDriver.Analyze().Violations, loggingLevel, throwOnViolation);
 }
Example #8
0
 ///AccessibilityCheckType
 ///
 /// <summary>
 /// Run axe accessibility and log the results
 /// </summary>
 /// <param name="webDriver">The web driver that is on the page you want to run the accessibility check on</param>
 /// <param name="logger">Where you want the check logged to</param>
 /// <param name="loggingLevel">What level should logging the check take, this gets used if the check doesn't throw an exception</param>
 /// <param name="throwOnIncomplete">Should incomplete cause and exception to be thrown</param>
 public static void CheckAccessibilityIncomplete(this IWebDriver webDriver, Logger logger, MessageType loggingLevel, bool throwOnIncomplete = false)
 {
     CheckAccessibility(webDriver, logger, AccessibilityCheckType.Incomplete.ToString(), () => webDriver.Analyze().Incomplete, loggingLevel, throwOnIncomplete);
 }
Example #9
0
 /// <summary>
 /// Run axe accessibility and log the results
 /// </summary>
 /// <param name="webDriver">The web driver that is on the page you want to run the accessibility check on</param>
 /// <param name="logger">Where you want the check logged to</param>
 /// <param name="loggingLevel">What level should logging the check take, this gets used if the check doesn't throw an exception</param>
 /// <param name="throwOnViolation">Should violations cause and exception to be thrown</param>
 public static void CheckAccessibilityPasses(this IWebDriver webDriver, Logger logger, MessageType loggingLevel)
 {
     // Look at passed
     CheckAccessibility(webDriver, logger, AccessibilityCheckType.Passes.ToString(), () => webDriver.Analyze().Passes, loggingLevel);
 }
Example #10
0
 /// <summary>
 /// Create a HTML accessibility report for a specific web element and all of it's children
 /// </summary>
 /// <param name="webDriver">The WebDriver</param>
 /// <param name="testObject">The TestObject to associate the report with</param>
 /// <param name="element">The WebElement you want to use as the root for your accessibility scan</param>
 /// <param name="throwOnViolation">Should violations cause and exception to be thrown</param>
 /// <param name="reportTypes">What type of results do you want in the report</param>
 /// <returns>Path to the HTML report</returns>
 public static string CreateAccessibilityHtmlReport(this IWebDriver webDriver, ISeleniumTestObject testObject, IWebElement element, bool throwOnViolation = false, ReportTypes reportTypes = ReportTypes.All)
 {
     return(CreateAccessibilityHtmlReport(element, testObject, () => webDriver.Analyze(element), throwOnViolation, reportTypes));
 }
Example #11
0
 /// <summary>
 /// Create a HTML accessibility report for an entire web page
 /// </summary>
 /// <param name="webDriver">The WebDriver</param>
 /// <param name="testObject">The TestObject to associate the report with</param>
 /// <param name="throwOnViolation">Should violations cause and exception to be thrown</param>
 public static void CreateAccessibilityHtmlReport(this IWebDriver webDriver, SeleniumTestObject testObject, bool throwOnViolation = false)
 {
     CreateAccessibilityHtmlReport(webDriver, testObject, () => webDriver.Analyze(), throwOnViolation);
 }