|
| 1 | +using Microsoft.VisualStudio.TestTools.UnitTesting; |
| 2 | +using Microsoft.VisualStudio.TestPlatform; |
| 3 | +using OpenQA.Selenium.Appium.Windows; |
| 4 | +using System; |
| 5 | +using System.Linq; |
| 6 | +using System.Text.Json; |
| 7 | +using System.IO; |
| 8 | +using System.Collections.ObjectModel; |
| 9 | +using System.Collections; |
| 10 | +using System.Collections.Generic; |
| 11 | +using System.Xml; |
| 12 | +using System.Reflection; |
| 13 | +using Newtonsoft.Json; |
| 14 | + |
| 15 | +namespace UITests.Tests |
| 16 | +{ |
| 17 | + [TestClass] |
| 18 | + public class AxeScanAll : TestBase |
| 19 | + { |
| 20 | + public static readonly string jsonUri = "ControlInfoData.json"; |
| 21 | + public static new WindowsDriver<WindowsElement> Session => SessionManager.Session; |
| 22 | + |
| 23 | + public static string[] ExclusionList = |
| 24 | + { |
| 25 | + "WebView2", // 46668961: Web contents from WebView2 are throwing null BoundingRectangle errors. |
| 26 | + "Icons" // https://github.com/CommunityToolkit/Windows/issues/240 External toolkit SettingsExpander does not pass Axe testing |
| 27 | + }; |
| 28 | + |
| 29 | + public class ControlInfoData |
| 30 | + { |
| 31 | + public List<Group> Groups { get; set; } |
| 32 | + } |
| 33 | + |
| 34 | + public class Group |
| 35 | + { |
| 36 | + [JsonProperty("UniqueId")] |
| 37 | + public string UniqueId { get; set; } |
| 38 | + |
| 39 | + [JsonProperty("Items")] |
| 40 | + public List<Item> Items { get; set; } |
| 41 | + } |
| 42 | + |
| 43 | + public class Item |
| 44 | + { |
| 45 | + [JsonProperty("UniqueId")] |
| 46 | + public string UniqueId { get; set; } |
| 47 | + } |
| 48 | + |
| 49 | + private static IEnumerable<object[]> TestData() |
| 50 | + { |
| 51 | + var testCases = new List<object[]>(); |
| 52 | + |
| 53 | + string jsonContent = System.IO.File.ReadAllText(jsonUri); |
| 54 | + var controlInfoData = JsonConvert.DeserializeObject<ControlInfoData>(jsonContent); |
| 55 | + |
| 56 | + foreach (var group in controlInfoData.Groups) |
| 57 | + { |
| 58 | + var sectionName = group.UniqueId; |
| 59 | + |
| 60 | + // Select all row names within the current table |
| 61 | + var items = group.Items; |
| 62 | + |
| 63 | + foreach (var item in items) |
| 64 | + { |
| 65 | + var pageName = item.UniqueId; |
| 66 | + |
| 67 | + // Skip pages in the exclusion list. |
| 68 | + if (ExclusionList.Contains(pageName)) |
| 69 | + { |
| 70 | + continue; |
| 71 | + } |
| 72 | + testCases.Add(new object[] { sectionName, pageName }); |
| 73 | + } |
| 74 | + } |
| 75 | + |
| 76 | + return testCases; |
| 77 | + } |
| 78 | + |
| 79 | + [ClassInitialize] |
| 80 | + public static void ClassInitialize(TestContext context) |
| 81 | + { |
| 82 | + } |
| 83 | + |
| 84 | + [TestMethod] |
| 85 | + [DynamicData(nameof(TestData), DynamicDataSourceType.Method, DynamicDataDisplayName = nameof(GetCustomDynamicDataDisplayName))] |
| 86 | + [TestProperty("Description", "Scan pages in the WinUIGallery for accessibility issues.")] |
| 87 | + public void ValidatePageAccessibilityWithAxe(string sectionName, string pageName) |
| 88 | + { |
| 89 | + try |
| 90 | + { |
| 91 | + // Click into page and check for accessibility issues. |
| 92 | + var page = Session.FindElementByAccessibilityId(pageName); |
| 93 | + page.Click(); |
| 94 | + |
| 95 | + AxeHelper.AssertNoAccessibilityErrors(); |
| 96 | + } |
| 97 | + catch |
| 98 | + { |
| 99 | + // If element is not found, expand tree view as it is nested. |
| 100 | + var section = Session.FindElementByAccessibilityId(sectionName); |
| 101 | + section.Click(); |
| 102 | + |
| 103 | + // Click into page and check for accessibility issues. |
| 104 | + var page = Session.FindElementByAccessibilityId(pageName); |
| 105 | + page.Click(); |
| 106 | + |
| 107 | + AxeHelper.AssertNoAccessibilityErrors(); |
| 108 | + } |
| 109 | + } |
| 110 | + |
| 111 | + public static string GetCustomDynamicDataDisplayName(MethodInfo methodInfo, object[] data) |
| 112 | + { |
| 113 | + return string.Format("Validate{0}PageAccessibility", data[1]); |
| 114 | + } |
| 115 | + } |
| 116 | +} |
0 commit comments