diff --git a/UITests/AxeHelper.cs b/UITests/AxeHelper.cs index 089c4c094..2397bb39f 100644 --- a/UITests/AxeHelper.cs +++ b/UITests/AxeHelper.cs @@ -45,7 +45,8 @@ public static void AssertNoAccessibilityErrors() .Where(rule => rule.Rule.ID != RuleId.SiblingUniqueAndFocusable); if (testResult.Any()) { - var mappedResult = testResult.Select(result => "Element " + result.Element.Properties["ControlType"] + " violated rule '" + result.Rule.Description + "'."); + var mappedResult = testResult.Select(result => + "Element " + result.Element.Properties["ControlType"] + " violated rule '" + result.Rule.Description + "'."); Assert.Fail("Failed with the following accessibility errors \r\n" + string.Join("\r\n", mappedResult)); } } diff --git a/UITests/Tests/AxeScanAllTests.cs b/UITests/Tests/AxeScanAllTests.cs new file mode 100644 index 000000000..e642f6913 --- /dev/null +++ b/UITests/Tests/AxeScanAllTests.cs @@ -0,0 +1,116 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.TestPlatform; +using OpenQA.Selenium.Appium.Windows; +using System; +using System.Linq; +using System.Text.Json; +using System.IO; +using System.Collections.ObjectModel; +using System.Collections; +using System.Collections.Generic; +using System.Xml; +using System.Reflection; +using Newtonsoft.Json; + +namespace UITests.Tests +{ + [TestClass] + public class AxeScanAll : TestBase + { + public static readonly string jsonUri = "ControlInfoData.json"; + public static new WindowsDriver Session => SessionManager.Session; + + public static string[] ExclusionList = + { + "WebView2", // 46668961: Web contents from WebView2 are throwing null BoundingRectangle errors. + "Icons" // https://github.com/CommunityToolkit/Windows/issues/240 External toolkit SettingsExpander does not pass Axe testing + }; + + public class ControlInfoData + { + public List Groups { get; set; } + } + + public class Group + { + [JsonProperty("UniqueId")] + public string UniqueId { get; set; } + + [JsonProperty("Items")] + public List Items { get; set; } + } + + public class Item + { + [JsonProperty("UniqueId")] + public string UniqueId { get; set; } + } + + private static IEnumerable TestData() + { + var testCases = new List(); + + string jsonContent = System.IO.File.ReadAllText(jsonUri); + var controlInfoData = JsonConvert.DeserializeObject(jsonContent); + + foreach (var group in controlInfoData.Groups) + { + var sectionName = group.UniqueId; + + // Select all row names within the current table + var items = group.Items; + + foreach (var item in items) + { + var pageName = item.UniqueId; + + // Skip pages in the exclusion list. + if (ExclusionList.Contains(pageName)) + { + continue; + } + testCases.Add(new object[] { sectionName, pageName }); + } + } + + return testCases; + } + + [ClassInitialize] + public static void ClassInitialize(TestContext context) + { + } + + [TestMethod] + [DynamicData(nameof(TestData), DynamicDataSourceType.Method, DynamicDataDisplayName = nameof(GetCustomDynamicDataDisplayName))] + [TestProperty("Description", "Scan pages in the WinUIGallery for accessibility issues.")] + public void ValidatePageAccessibilityWithAxe(string sectionName, string pageName) + { + try + { + // Click into page and check for accessibility issues. + var page = Session.FindElementByAccessibilityId(pageName); + page.Click(); + + AxeHelper.AssertNoAccessibilityErrors(); + } + catch + { + // If element is not found, expand tree view as it is nested. + var section = Session.FindElementByAccessibilityId(sectionName); + section.Click(); + + // Click into page and check for accessibility issues. + var page = Session.FindElementByAccessibilityId(pageName); + page.Click(); + + AxeHelper.AssertNoAccessibilityErrors(); + } + } + + public static string GetCustomDynamicDataDisplayName(MethodInfo methodInfo, object[] data) + { + return string.Format("Validate{0}PageAccessibility", data[1]); + } + } +} diff --git a/UITests/Tests/Button.cs b/UITests/Tests/Button.cs index 1baa850db..09c0993b5 100644 --- a/UITests/Tests/Button.cs +++ b/UITests/Tests/Button.cs @@ -32,12 +32,6 @@ public static void ClassInitialize(TestContext context) Assert.IsNotNull(buttonElement); } - [TestMethod] - public void ValidateAccessibilityWithAxe() - { - AxeHelper.AssertNoAccessibilityErrors(); - } - [TestMethod] public void Button_Click() { diff --git a/UITests/Tests/CheckBox.cs b/UITests/Tests/CheckBox.cs index ad626d57b..06630d9d0 100644 --- a/UITests/Tests/CheckBox.cs +++ b/UITests/Tests/CheckBox.cs @@ -34,12 +34,6 @@ public static void ClassInitialize(TestContext context) Assert.IsNotNull(checkBoxElement2); } - [TestMethod] - public void ValidateAccessibilityWithAxe() - { - AxeHelper.AssertNoAccessibilityErrors(); - } - [TestMethod] public void Click() { diff --git a/UITests/Tests/ComboBox.cs b/UITests/Tests/ComboBox.cs index 3921663b1..0497730b2 100644 --- a/UITests/Tests/ComboBox.cs +++ b/UITests/Tests/ComboBox.cs @@ -36,17 +36,9 @@ public static void ClassInitialize(TestContext context) Assert.IsNotNull(comboBoxElement2); } - [TestMethod] - public void ValidateAccessibilityWithAxe() - { - AxeHelper.AssertNoAccessibilityErrors(); - } - [TestMethod] public void Click() { - - // Click comboBoxElement1 to show the list and simply dismiss it var originalSelectedItem = comboBoxElement1.Text; comboBoxElement1.Click(); diff --git a/UITests/Tests/DatePicker.cs b/UITests/Tests/DatePicker.cs index 11cf6abe6..2f9fce9d2 100644 --- a/UITests/Tests/DatePicker.cs +++ b/UITests/Tests/DatePicker.cs @@ -37,12 +37,6 @@ public static void ClassInitialize(TestContext context) Assert.IsNotNull(datePickerElement2); } - [TestMethod] - public void ValidateAccessibilityWithAxe() - { - AxeHelper.AssertNoAccessibilityErrors(); - } - [TestMethod] public void Click() { diff --git a/UITests/Tests/MediaPlayerElement.cs b/UITests/Tests/MediaPlayerElement.cs index 24d6a4b16..a6203814f 100644 --- a/UITests/Tests/MediaPlayerElement.cs +++ b/UITests/Tests/MediaPlayerElement.cs @@ -35,12 +35,6 @@ public static void ClassInitialize(TestContext context) GetElementByName("MediaPlayerElement").Click(); } - [TestMethod] - public void ValidateAccessibilityWithAxe() - { - AxeHelper.AssertNoAccessibilityErrors(); - } - [TestMethod] public void PlayMedia() { diff --git a/UITests/Tests/PersonPicture.cs b/UITests/Tests/PersonPicture.cs index 22596fd33..83e91390f 100644 --- a/UITests/Tests/PersonPicture.cs +++ b/UITests/Tests/PersonPicture.cs @@ -28,12 +28,6 @@ public static void ClassInitialize(TestContext context) OpenControlPage("PersonPicture"); } - [TestMethod] - public void ValidateAccessibilityWithAxe() - { - AxeHelper.AssertNoAccessibilityErrors(); - } - [TestMethod] public void SwitchOptions() { diff --git a/UITests/Tests/ProgressBar.cs b/UITests/Tests/ProgressBar.cs index 25a01df2d..fc0194aa7 100644 --- a/UITests/Tests/ProgressBar.cs +++ b/UITests/Tests/ProgressBar.cs @@ -37,12 +37,6 @@ public static void ClassInitialize(TestContext context) Assert.IsNotNull(clickAndHoldButton); } - [TestMethod] - public void ValidateAccessibilityWithAxe() - { - AxeHelper.AssertNoAccessibilityErrors(); - } - [TestMethod] public void Displayed() { diff --git a/UITests/Tests/RadioButton.cs b/UITests/Tests/RadioButton.cs index 8f16ae2c7..cc28a8515 100644 --- a/UITests/Tests/RadioButton.cs +++ b/UITests/Tests/RadioButton.cs @@ -36,12 +36,6 @@ public static void ClassInitialize(TestContext context) Assert.IsNotNull(radioButtonElement2); } - [TestMethod] - public void ValidateAccessibilityWithAxe() - { - AxeHelper.AssertNoAccessibilityErrors(); - } - [TestMethod] public void Click() { diff --git a/UITests/Tests/Slider.cs b/UITests/Tests/Slider.cs index 61df44aa4..6579ff7f3 100644 --- a/UITests/Tests/Slider.cs +++ b/UITests/Tests/Slider.cs @@ -36,12 +36,6 @@ public static void ClassInitialize(TestContext context) Assert.IsNotNull(sliderElement2); } - [TestMethod] - public void ValidateAccessibilityWithAxe() - { - AxeHelper.AssertNoAccessibilityErrors(); - } - [TestMethod] public void Click() { diff --git a/UITests/Tests/TextBlock.cs b/UITests/Tests/TextBlock.cs index b597e7af5..f9f35cc8a 100644 --- a/UITests/Tests/TextBlock.cs +++ b/UITests/Tests/TextBlock.cs @@ -37,12 +37,6 @@ public static void ClassInitialize(TestContext context) Assert.IsNotNull(textBlockElement2); } - [TestMethod] - public void ValidateAccessibilityWithAxe() - { - AxeHelper.AssertNoAccessibilityErrors(); - } - [TestMethod] public void Displayed() { diff --git a/UITests/Tests/TextBox.cs b/UITests/Tests/TextBox.cs index 863e572e0..6be2550f6 100644 --- a/UITests/Tests/TextBox.cs +++ b/UITests/Tests/TextBox.cs @@ -38,12 +38,6 @@ public static void ClassInitialize(TestContext context) Assert.IsNotNull(textBoxElement2); } - [TestMethod] - public void ValidateAccessibilityWithAxe() - { - AxeHelper.AssertNoAccessibilityErrors(); - } - [TestMethod] public void Clear() { diff --git a/UITests/Tests/ToggleButton.cs b/UITests/Tests/ToggleButton.cs index 62ed86a66..588544873 100644 --- a/UITests/Tests/ToggleButton.cs +++ b/UITests/Tests/ToggleButton.cs @@ -33,12 +33,6 @@ public static void ClassInitialize(TestContext context) Assert.IsNotNull(toggleButtonElement); } - [TestMethod] - public void ValidateAccessibilityWithAxe() - { - AxeHelper.AssertNoAccessibilityErrors(); - } - [TestMethod] public void Click() { diff --git a/UITests/Tests/ToggleSwitch.cs b/UITests/Tests/ToggleSwitch.cs index da5445c09..db22e3b1c 100644 --- a/UITests/Tests/ToggleSwitch.cs +++ b/UITests/Tests/ToggleSwitch.cs @@ -33,12 +33,6 @@ public static void ClassInitialize(TestContext context) Assert.IsNotNull(toggleSwitchElement); } - [TestMethod] - public void ValidateAccessibilityWithAxe() - { - AxeHelper.AssertNoAccessibilityErrors(); - } - [TestMethod] public void Click() { diff --git a/UITests/UITests.csproj b/UITests/UITests.csproj index 9994eb5a2..7c6e325d3 100644 --- a/UITests/UITests.csproj +++ b/UITests/UITests.csproj @@ -8,6 +8,13 @@ win10-x86;win10-x64;win10-arm64 + + + $(MSBuildThisFileDirectory)..\ + $(MSBuildThisFileDirectory)\bin\ + \$(Platform)\$(Configuration)\$(TargetFramework) + + @@ -15,4 +22,8 @@ + + + + \ No newline at end of file diff --git a/WinUIGallery/ControlPages/DesignGuidance/IconsPage.xaml b/WinUIGallery/ControlPages/DesignGuidance/IconsPage.xaml index 9809cdd7c..3962e5479 100644 --- a/WinUIGallery/ControlPages/DesignGuidance/IconsPage.xaml +++ b/WinUIGallery/ControlPages/DesignGuidance/IconsPage.xaml @@ -110,6 +110,7 @@ + -