public void TestAccessibilityOfPage()

in csharp-selenium-webdriver-sample/SamplePageTests.cs [29:56]


        public void TestAccessibilityOfPage()
        {
            AxeResult axeResult = new AxeBuilder(_webDriver)
                // This WithTags directive restricts Axe to only run tests that detect known violations of WCAG 2.1 A and AA rules
                // (similar to what Accessibility Insights reports). If you omit this, Axe will additionally run several "best practice"
                // rules, which are good ideas to check for periodically but may report false positives in certain edge cases.
                //
                // For complete documentation of which rule IDs and tags axe supports, see:
                // * summary of rules with IDs and tags: https://github.com/dequelabs/axe-core/blob/develop/doc/rule-descriptions.md
                // * full reference documentation for each rule: https://dequeuniversity.com/rules/axe
                .WithTags("wcag2a", "wcag2aa", "wcag21aa")
                .Analyze();

            // axeResult.Violations is an array of all the accessibility violations the scan found; the easiest way to assert
            // that a scan came back clean is to assert that the Violations array is empty. You can do this with the built in
            // MSTest assertions like this:
            //
            //     Assert.AreEqual(0, axeResult.Violations.Length);
            //
            // However, we don't recommend using Assert.AreEqual for this because it doesn't give very useful error messages if
            // it does detect a violation; the error message will just say "expected 0 but found 1".
            //
            // We recommend using FluentAssertions instead; its default behavior gives much better error messages that include
            // full descriptions of accessibility issues, including links to detailed guidance at https://dequeuniversity.com
            // and CSS selector paths that exactly identify the element on the page with the issue.
            axeResult.Error.Should().BeNull();
            axeResult.Violations.Should().BeEmpty();
        }