public void AddNewCentreCourse_journey_has_no_accessibility_errors() { // Given Driver.LogUserInAsAdminAndDelegate(BaseUrl); const string startUrl = "/TrackingSystem/CourseSetup/AddCourseNew"; // When Driver.Navigate().GoToUrl(BaseUrl + startUrl); ValidatePageHeading("Add new centre course"); var selectCoursePageResult = new AxeBuilder(Driver).Analyze(); Driver.SelectDropdownItemValue("searchable-elements", "206"); Driver.ClickButtonByText("Next"); ValidatePageHeading("Set course details"); var setCourseDetailsPageResult = new AxeBuilder(Driver).Analyze(); Driver.SubmitForm(); ValidatePageHeading("Set course options"); var setCourseOptionsPageResult = new AxeBuilder(Driver).Analyze(); Driver.SubmitForm(); ValidatePageHeading("Set course content"); var setCourseContentPageResult = new AxeBuilder(Driver).Analyze(); Driver.FindElement(By.Id("ChooseSections")).Click(); Driver.SetCheckboxState("section-671", true); Driver.SubmitForm(); ValidatePageHeading("Set section content"); var setSectionContentPageResult = new AxeBuilder(Driver).Analyze(); Driver.ClickButtonByText("Next"); ValidatePageHeading("Summary"); var summaryPageResult = new AxeBuilder(Driver).Analyze(); selectCoursePageResult.Violations.Should().BeEmpty(); // Expect an axe violation caused by having an aria-expanded attribute on an input // The target inputs are nhs-tested components so ignore these violation setCourseDetailsPageResult.Violations.Should().HaveCount(1); var setCourseDetailsViolation = setCourseDetailsPageResult.Violations[0]; setCourseDetailsViolation.Id.Should().Be("aria-allowed-attr"); setCourseDetailsViolation.Nodes.Should().HaveCount(3); setCourseDetailsViolation.Nodes[0].Target.Should().HaveCount(1); setCourseDetailsViolation.Nodes[0].Target[0].Selector.Should().Be("#PasswordProtected"); setCourseDetailsViolation.Nodes[1].Target.Should().HaveCount(1); setCourseDetailsViolation.Nodes[1].Target[0].Selector.Should().Be("#ReceiveNotificationEmails"); setCourseDetailsViolation.Nodes[2].Target.Should().HaveCount(1); setCourseDetailsViolation.Nodes[2].Target[0].Selector.Should().Be("#OtherCompletionCriteria"); setCourseOptionsPageResult.Violations.Should().BeEmpty(); setCourseContentPageResult.Violations.Should().BeEmpty(); setSectionContentPageResult.Violations.Should().BeEmpty(); summaryPageResult.Violations.Should().BeEmpty(); }
public void ThrowWhenDriverIsNull() { //arrange / act /assert var axeBuilder = new AxeBuilder(null); axeBuilder.Should().NotBeNull(); }
public void LearningPortal_interface_has_no_accessibility_errors() { { // Given Driver.LogUserInAsAdminAndDelegate(BaseUrl); const string startUrl = "/LearningPortal/Current"; const string completedUrl = "/LearningPortal/Completed"; const string availableUrl = "/LearningPortal/Available"; const string completeByUrl = "/LearningPortal/Current/CompleteBy/19262?returnPageQuery=pageNumber%3D1"; // When Driver.Navigate().GoToUrl(BaseUrl + startUrl); ValidatePageHeading("My Current Activities"); var currentActivitiesResult = new AxeBuilder(Driver).Analyze(); Driver.Navigate().GoToUrl(BaseUrl + completedUrl); ValidatePageHeading("My Completed Activities"); var completedActivitiesResult = new AxeBuilder(Driver).Analyze(); Driver.Navigate().GoToUrl(BaseUrl + availableUrl); ValidatePageHeading("Available Activities"); var availableActivitiesResult = new AxeBuilder(Driver).Analyze(); Driver.Navigate().GoToUrl(BaseUrl + completeByUrl); ValidatePageHeading("Enter a complete by date for Excel 2013 for the Workplace - Testing"); var completeByResult = new AxeBuilder(Driver).Analyze(); //Then currentActivitiesResult.Violations.Should().BeEmpty(); completedActivitiesResult.Violations.Should().BeEmpty(); availableActivitiesResult.Violations.Should().BeEmpty(); completeByResult.Violations.Should().BeEmpty(); } }
public void TestAccessibilityOfPageExcludingKnownIssues() { // You can use AxeBuilder.Exclude to exclude individual elements with known issues from a scan. // // Exclude accepts any CSS selector; you could also use ".some-classname" or "div[some-attr='some value']" AxeResult axeResultExcludingExampleViolationsElement = new AxeBuilder(_webDriver) .Exclude("#id-of-example-accessibility-violation-list") .Analyze(); axeResultExcludingExampleViolationsElement.Violations.Should().BeEmpty(); // You can also use AxeBuilder.DisableRules to exclude certain individual rules from a scan. This is particularly // useful if you still want to perform *some* scanning on the elements you exclude from more broad scans. AxeResult axeResultDisablingRulesViolatedByExamples = new AxeBuilder(_webDriver) .Include("#id-of-example-accessibility-violation-list") // Like Exclude(), accepts any CSS selector .DisableRules("color-contrast", "label", "tabindex") .Analyze(); axeResultDisablingRulesViolatedByExamples.Violations.Should().BeEmpty(); // Another option is to assert on the size of the Violations array. This works just fine, but we recommend the // other options above as your first choice instead because when they do find new issues, they will produce error // messages that more clearly identify exactly what the new/unexpected issues are. AxeResult axeResult = new AxeBuilder(_webDriver).Analyze(); axeResult.Violations.Should().HaveCount(3); }
public void TestAccessibilityOfIndividualElements() { // Both of these 2 options work equally well; which one to use is a matter of preference. // Option 1: using Selenium's FindElement to identify the element to test // // This can be simpler if your test already had to find the element for earlier assertions, or if you want to test // an element that is hard to identify using a CSS selector. IWebElement elementUnderTest = _webDriver.FindElement(By.Id("id-of-example-accessible-element")); AxeResult axeResultWithAnalyzeWebElement = new AxeBuilder(_webDriver) .WithTags("wcag2a", "wcag2aa", "wcag21aa") .Analyze(elementUnderTest); axeResultWithAnalyzeWebElement.Violations.Should().BeEmpty(); // Option 2: using AxeBuilder.Include // // This can be simpler if you need to test multiple elements at once or need to deal with <iframe>s. AxeResult axeResultWithInclude = new AxeBuilder(_webDriver) .Include("#id-of-example-accessible-element") .Include(".class-of-example-accessible-element") .Include("#id-of-iframe", "#id-of-element-inside-iframe") .WithTags("wcag2a", "wcag2aa", "wcag21aa") .Analyze(); axeResultWithInclude.Violations.Should().BeEmpty(); }
public void ShouldPassRunOptionsWithTagConfig() { var expectedTags = new List <string> { "tag1", "tag2" }; var expectedOptions = SerializeObject(new AxeRunOptions() { RunOnly = new RunOnlyOptions { Type = "tag", Values = expectedTags }, }); SetupVerifiableAxeInjectionCall(); SetupVerifiableScanCall(null, expectedOptions); var builder = new AxeBuilder(webDriverMock.Object) .WithTags("tag1", "tag2"); var result = builder.Analyze(); VerifyAxeResult(result); webDriverMock.VerifyAll(); targetLocatorMock.VerifyAll(); jsExecutorMock.VerifyAll(); }
public void ShouldPassRunOptions() { var runOptions = new AxeRunOptions() { Iframes = true, Rules = new Dictionary <string, RuleOptions>() { { "rule1", new RuleOptions() { Enabled = false } } } }; var expectedRunOptions = SerializeObject(runOptions); SetupVerifiableAxeInjectionCall(); SetupVerifiableScanCall(null, expectedRunOptions); var builder = new AxeBuilder(webDriverMock.Object) .WithOptions(runOptions); var result = builder.Analyze(); VerifyAxeResult(result); webDriverMock.VerifyAll(); targetLocatorMock.VerifyAll(); jsExecutorMock.VerifyAll(); }
public void SelfAssessment_journey_has_no_accessibility_errors() { // Given Driver.LogUserInAsAdminAndDelegate(BaseUrl); const string startUrl = "/LearningPortal/SelfAssessment/1"; const string firstCapabilityUrl = startUrl + "/1"; const string capabilitiesUrl = startUrl + "/Capabilities"; const string completeByUrl = startUrl + "/CompleteBy?returnPageQuery=pageNumber%3D1"; // When Driver.Navigate().GoToUrl(BaseUrl + startUrl); ValidatePageHeading("Digital Capability Self Assessment"); var startPageResult = new AxeBuilder(Driver).Analyze(); Driver.Navigate().GoToUrl(BaseUrl + firstCapabilityUrl); ValidatePageHeading("Data, Information and Content"); var firstCapabilityResult = new AxeBuilder(Driver).Analyze(); Driver.Navigate().GoToUrl(BaseUrl + capabilitiesUrl); ValidatePageHeading("Digital Capability Self Assessment - Capabilities"); var capabilitiesResult = new AxeBuilder(Driver).Analyze(); Driver.Navigate().GoToUrl(BaseUrl + completeByUrl); ValidatePageHeading("Enter a complete by date for Digital Capability Self Assessment"); var completeByPageResult = new AxeBuilder(Driver).Analyze(); //Then startPageResult.Violations.Should().BeEmpty(); firstCapabilityResult.Violations.Should().BeEmpty(); capabilitiesResult.Violations.Should().BeEmpty(); completeByPageResult.Violations.Should().BeEmpty(); }
public void RunScanOnPage(string browser) { InitDriver(browser); LoadSimpleTestPage(); var timeBeforeScan = DateTime.Now; var builder = new AxeBuilder(_webDriver) .WithOptions(new AxeRunOptions() { XPath = true }) .WithTags("wcag2a", "wcag2aa") .DisableRules("color-contrast") .WithOutputFile(@"./raw-axe-results.json"); var results = builder.Analyze(); results.Violations.FirstOrDefault(v => v.Id == "color-contrast").Should().BeNull(); results.Violations.FirstOrDefault(v => !v.Tags.Contains("wcag2a") && !v.Tags.Contains("wcag2aa")).Should().BeNull(); results.Violations.Should().HaveCount(2); results.Violations.First().Nodes.First().XPath.Should().NotBeNullOrEmpty(); File.GetLastWriteTime(@"./raw-axe-results.json").Should().BeOnOrAfter(timeBeforeScan); }
public void ThenThePageShouldBeAccessibleApartFromAMissingHeader() { var axeResult = new AxeBuilder(_browsers[_c.CurrentUser].Driver) .DisableRules("page-has-heading-one").Analyze(); axeResult.Violations.Should().BeEmpty(); }
public void AddAdminField_journey_has_no_accessibility_errors() { // Given Driver.LogUserInAsAdminAndDelegate(BaseUrl); const string startUrl = "/TrackingSystem/CourseSetup/100/AdminFields/Add/New"; // When Driver.Navigate().GoToUrl(BaseUrl + startUrl); ValidatePageHeading("Add course admin field"); var addPageResult = new AxeBuilder(Driver).Analyze(); Driver.SelectDropdownItemValue("AdminFieldId", "1"); AddAnswer("Answer 1"); AddAnswer("Answer 2"); ValidatePageHeading("Add course admin field"); var addAnswersResult = new AxeBuilder(Driver).Analyze(); Driver.ClickButtonByText("Bulk edit"); ValidatePageHeading("Configure answers in bulk"); var bulkAdditionResult = new AxeBuilder(Driver).Analyze(); Driver.ClickButtonByText("Submit"); ValidatePageHeading("Add course admin field"); addPageResult.Violations.Should().BeEmpty(); bulkAdditionResult.Violations.Should().BeEmpty(); addAnswersResult.Violations.Should().BeEmpty(); }
public void ThenThePageShouldBeAccessible() { _browsers[_c.CurrentUser].Driver.WaitForPageToLoad(); var axeResult = new AxeBuilder(_browsers[_c.CurrentUser].Driver).Analyze(); axeResult.Violations.Should().BeEmpty(); }
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(); }
public void HomePageWithComplexReport() { string reportPath = Path.Combine(LoggingConfig.GetLogDirectory(), "HomePageWithComplexReport.html"); string rawResults = Path.Combine(LoggingConfig.GetLogDirectory(), "HomePageWithComplexReport.json"); // Get to home page LoginPageModel page = new LoginPageModel(this.TestObject); page.OpenLoginPage(); page.LoginWithValidCredentials(Config.GetGeneralValue("User"), Config.GetGeneralValue("Pass")); // Setup custom rules AxeBuilder builder = new AxeBuilder(WebDriver) .Exclude("#HomePage") .WithOutputFile(rawResults) .DisableRules("landmark-one-main", "page-has-heading-one"); // Reprot WebDriver.CreateAxeHtmlReport(builder.Analyze(), reportPath); // Check if there were any violations if (!File.ReadAllText(reportPath).Contains("Violation: 0")) { TestObject.AddAssociatedFile(reportPath); TestObject.AddAssociatedFile(rawResults); Assert.Fail($"Failed violation check see {reportPath} for more details."); } }
public void Edit_course_details_page_has_no_accessibility_errors_except_expected_ones() { // given Driver.LogUserInAsAdminAndDelegate(BaseUrl); const string editCourseDetailsUrl = "/TrackingSystem/CourseSetup/10716/Manage/CourseDetails"; // when Driver.Navigate().GoToUrl(BaseUrl + editCourseDetailsUrl); ValidatePageHeading("Edit course details"); var editResult = new AxeBuilder(Driver).Analyze(); // Expect an axe violation caused by having an aria-expanded attribute on an input // The target inputs are nhs-tested components so ignore these violation editResult.Violations.Should().HaveCount(1); var violation = editResult.Violations[0]; violation.Id.Should().Be("aria-allowed-attr"); violation.Nodes.Should().HaveCount(3); violation.Nodes[0].Target.Should().HaveCount(1); violation.Nodes[0].Target[0].Selector.Should().Be("#PasswordProtected"); violation.Nodes[1].Target.Should().HaveCount(1); violation.Nodes[1].Target[0].Selector.Should().Be("#ReceiveNotificationEmails"); violation.Nodes[2].Target.Should().HaveCount(1); violation.Nodes[2].Target[0].Selector.Should().Be("#OtherCompletionCriteria"); }
public void ThrowWhenOptionsAreNull() { //arrange var driver = new Mock <IWebDriver>(); // act / assert var axeBuilder = new AxeBuilder(driver.Object, null); }
public void TestAnalyzeTarget() { _webDriver.Navigate().GoToUrl(targetTestUrl); AxeBuilder axeBuilder = new AxeBuilder(_webDriver); var results = axeBuilder.Analyze(); results.Should().NotBeNull(nameof(results)); }
public void Should_Pass_Testing_Cat_Semantics_Tag_Only() { AxeResult axeResult = new AxeBuilder(_webDriver) .WithTags("cat.semantics") .Analyze(); axeResult.Violations.Should().BeEmpty(); }
public void Should_Pass_With_Aria_Allowed_Role_Rule_Disabled() { AxeResult axeResult = new AxeBuilder(_webDriver) .DisableRules("aria-allowed-role") .Analyze(); axeResult.Violations.Should().BeEmpty(); }
public void AnalyzePageHeadingAndAccessibility(string pageTitle) { ValidatePageHeading(pageTitle); // then var axeResult = new AxeBuilder(Driver).Analyze(); axeResult.Violations.Should().BeEmpty(); }
internal void AxeScanLevelAAA() { var results = new AxeBuilder(driver) .WithTags("wcag2aaa") .Analyze(); results.Violations.Should().BeEmpty(); Console.WriteLine(results); }
public void Shoud_Pass_Excluding_CSS_Classes_Failing_Nodes() { AxeResult axeResult = new AxeBuilder(_webDriver) .Exclude(".owl-prev") .Exclude(".owl-next") .Analyze(); axeResult.Violations.Should().BeEmpty(); }
/// <summary> /// This method will perform the acceabilty test of the /// web page and generate the report you need to pass the page name for reportinga nd current driver instance to perform accessability tests /// </summary> /// <param name="driver"></param> /// <param name="Name"></param> /// <returns></returns> public static AxeResult AnalyzePage(IWebDriver driver, string PageName) { var result = new AxeBuilder(driver).WithTags("wcag21aa", "wcag2aa").Analyze(); var outPutDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase); outPutDirectory = outPutDirectory.Substring(0, outPutDirectory.IndexOf("bin")); outPutDirectory = outPutDirectory.Substring(outPutDirectory.IndexOf("\\") + 1); String path = Path.Combine(outPutDirectory, "TestResults\\" + PageName + "-AxeReport.html"); driver.CreateAxeHtmlReport(result, path); return(result); }
public void Edit_reports_filters_page_has_no_accessibility_errors() { // given Driver.LogUserInAsAdminAndDelegate(BaseUrl); const string reportsEditFiltersUrl = "/TrackingSystem/Centre/Reports/Courses/EditFilters"; // when Driver.Navigate().GoToUrl(BaseUrl + reportsEditFiltersUrl); var result = new AxeBuilder(Driver).Analyze(); // then CheckAccessibilityResult(result); }
public void ReportRespectRules(string browser) { string path = CreateReportPath(); InitDriver(browser); LoadSimpleTestPage(); _wait.Until(drv => drv.FindElement(By.CssSelector(mainElementSelector))); var builder = new AxeBuilder(_webDriver).DisableRules("color-contrast"); _webDriver.CreateAxeHtmlReport(builder.Analyze(), path); ValidateReport(path, 3, 23, 0, 63); }
public void ShouldThrowIfEmptyParameterPassed() { var values = new string[] { "val1", "" }; SetupVerifiableAxeInjectionCall(); var builder = new AxeBuilder(webDriverMock.Object); VerifyExceptionThrown <ArgumentException>(() => builder.WithRules(values)); VerifyExceptionThrown <ArgumentException>(() => builder.DisableRules(values)); VerifyExceptionThrown <ArgumentException>(() => builder.WithTags(values)); VerifyExceptionThrown <ArgumentException>(() => builder.Include(values)); VerifyExceptionThrown <ArgumentException>(() => builder.Exclude(values)); }
public void ShouldHandleIfOptionsAndContextNotSet() { SetupVerifiableAxeInjectionCall(); SetupVerifiableScanCall(null, "{}"); var builder = new AxeBuilder(webDriverMock.Object); var result = builder.Analyze(); VerifyAxeResult(result); webDriverMock.VerifyAll(); targetLocatorMock.VerifyAll(); jsExecutorMock.VerifyAll(); }
public void ReportRespectsIframeImplicitTrue(string browser) { string path = CreateReportPath(); string filename = new Uri(Path.GetFullPath(IntegrationTestTargetComplexTargetsFile)).AbsoluteUri; InitDriver(browser); WebDriver.Navigate().GoToUrl(filename); Wait.Until(drv => drv.FindElement(By.CssSelector(mainElementSelector))); var builder = new AxeBuilder(WebDriver); WebDriver.CreateAxeHtmlReport(builder.Analyze(), path); ValidateReport(path, 4, 43, 0, 64); }
public void ShouldThrowIfNullParameterPassed() { SetupVerifiableAxeInjectionCall(); VerifyExceptionThrown <ArgumentNullException>(() => new AxeBuilder(webDriverMock.Object, null)); VerifyExceptionThrown <ArgumentNullException>(() => new AxeBuilder(null)); var builder = new AxeBuilder(webDriverMock.Object); VerifyExceptionThrown <ArgumentNullException>(() => builder.WithRules(null)); VerifyExceptionThrown <ArgumentNullException>(() => builder.DisableRules(null)); VerifyExceptionThrown <ArgumentNullException>(() => builder.WithTags(null)); VerifyExceptionThrown <ArgumentNullException>(() => builder.Include(null)); VerifyExceptionThrown <ArgumentNullException>(() => builder.Exclude(null)); VerifyExceptionThrown <ArgumentNullException>(() => builder.WithOptions(null)); }
public void TestAccessibilityOfSingleElement() { IWebElement elementUnderTest = _webDriver.FindElement(By.Id("example-accessible-element")); AxeResult axeResult = new AxeBuilder(_webDriver) .Analyze(elementUnderTest); // This is the simplest way to assert that the axe scan didn't find any violations. However, if it *does* find // some violations, it doesn't give a very useful error message; it just says "expected 0 but found 1". Assert.AreEqual(0, axeResult.Violations.Length); // 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.Violations.Should().BeEmpty(); }