Skip to content

Commit 9a2c60b

Browse files
authored
Add Test to Scan All Pages for Axe Issues (#1361)
<!--- Provide a general summary of your changes in the Title above --> ## Description <!--- Describe your changes in detail --> - Add a test that physically navigates to each page via NavView and check for Axe issues. - Utilizes DynamicData attribute to create grouped tests based on section category (ie. TreeView parent) - This also tests for run-time crashes with each page. - Miscellaneous Axe fixes. ## Types of changes <!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: --> - [ ] Bug fix (non-breaking change which fixes an issue) - [x] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change)
1 parent 1d23724 commit 9a2c60b

23 files changed

Lines changed: 192 additions & 119 deletions

UITests/AxeHelper.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ public static void AssertNoAccessibilityErrors()
4545
.Where(rule => rule.Rule.ID != RuleId.SiblingUniqueAndFocusable);
4646
if (testResult.Any())
4747
{
48-
var mappedResult = testResult.Select(result => "Element " + result.Element.Properties["ControlType"] + " violated rule '" + result.Rule.Description + "'.");
48+
var mappedResult = testResult.Select(result =>
49+
"Element " + result.Element.Properties["ControlType"] + " violated rule '" + result.Rule.Description + "'.");
4950
Assert.Fail("Failed with the following accessibility errors \r\n" + string.Join("\r\n", mappedResult));
5051
}
5152
}

UITests/Tests/AxeScanAllTests.cs

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
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+
}

UITests/Tests/Button.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,6 @@ public static void ClassInitialize(TestContext context)
3232
Assert.IsNotNull(buttonElement);
3333
}
3434

35-
[TestMethod]
36-
public void ValidateAccessibilityWithAxe()
37-
{
38-
AxeHelper.AssertNoAccessibilityErrors();
39-
}
40-
4135
[TestMethod]
4236
public void Button_Click()
4337
{

UITests/Tests/CheckBox.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,6 @@ public static void ClassInitialize(TestContext context)
3434
Assert.IsNotNull(checkBoxElement2);
3535
}
3636

37-
[TestMethod]
38-
public void ValidateAccessibilityWithAxe()
39-
{
40-
AxeHelper.AssertNoAccessibilityErrors();
41-
}
42-
4337
[TestMethod]
4438
public void Click()
4539
{

UITests/Tests/ComboBox.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,9 @@ public static void ClassInitialize(TestContext context)
3636
Assert.IsNotNull(comboBoxElement2);
3737
}
3838

39-
[TestMethod]
40-
public void ValidateAccessibilityWithAxe()
41-
{
42-
AxeHelper.AssertNoAccessibilityErrors();
43-
}
44-
4539
[TestMethod]
4640
public void Click()
4741
{
48-
49-
5042
// Click comboBoxElement1 to show the list and simply dismiss it
5143
var originalSelectedItem = comboBoxElement1.Text;
5244
comboBoxElement1.Click();

UITests/Tests/DatePicker.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,6 @@ public static void ClassInitialize(TestContext context)
3737
Assert.IsNotNull(datePickerElement2);
3838
}
3939

40-
[TestMethod]
41-
public void ValidateAccessibilityWithAxe()
42-
{
43-
AxeHelper.AssertNoAccessibilityErrors();
44-
}
45-
4640
[TestMethod]
4741
public void Click()
4842
{

UITests/Tests/MediaPlayerElement.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,6 @@ public static void ClassInitialize(TestContext context)
3535
GetElementByName("MediaPlayerElement").Click();
3636
}
3737

38-
[TestMethod]
39-
public void ValidateAccessibilityWithAxe()
40-
{
41-
AxeHelper.AssertNoAccessibilityErrors();
42-
}
43-
4438
[TestMethod]
4539
public void PlayMedia()
4640
{

UITests/Tests/PersonPicture.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,6 @@ public static void ClassInitialize(TestContext context)
2828
OpenControlPage("PersonPicture");
2929
}
3030

31-
[TestMethod]
32-
public void ValidateAccessibilityWithAxe()
33-
{
34-
AxeHelper.AssertNoAccessibilityErrors();
35-
}
36-
3731
[TestMethod]
3832
public void SwitchOptions()
3933
{

UITests/Tests/ProgressBar.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,6 @@ public static void ClassInitialize(TestContext context)
3737
Assert.IsNotNull(clickAndHoldButton);
3838
}
3939

40-
[TestMethod]
41-
public void ValidateAccessibilityWithAxe()
42-
{
43-
AxeHelper.AssertNoAccessibilityErrors();
44-
}
45-
4640
[TestMethod]
4741
public void Displayed()
4842
{

UITests/Tests/RadioButton.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,6 @@ public static void ClassInitialize(TestContext context)
3636
Assert.IsNotNull(radioButtonElement2);
3737
}
3838

39-
[TestMethod]
40-
public void ValidateAccessibilityWithAxe()
41-
{
42-
AxeHelper.AssertNoAccessibilityErrors();
43-
}
44-
4539
[TestMethod]
4640
public void Click()
4741
{

0 commit comments

Comments
 (0)