Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions tests/Files.InteractionTests/Helper/AxeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,17 @@ internal static void InitializeAxe()
AccessibilityScanner = ScannerFactory.CreateScanner(config);
}

public static void AssertNoAccessibilityErrors()
public static void AssertNoAccessibilityErrors(Func<ScanResult, bool>? ignoredIssueFilter = null)
{
var testResult = AccessibilityScanner.Scan(null).WindowScanOutputs.SelectMany(output => output.Errors).Where(error => error.Rule.ID != RuleId.BoundingRectangleNotNull);
var testResult = AccessibilityScanner
.Scan(null)
.WindowScanOutputs
.SelectMany(output => output.Errors)
.Where(error => error.Rule.ID != RuleId.BoundingRectangleNotNull);

if (ignoredIssueFilter is not null)
testResult = testResult.Where(error => !ignoredIssueFilter(error));

if (testResult.Any())
{
StringBuilder sb = new();
Expand All @@ -40,6 +48,17 @@ public static void AssertNoAccessibilityErrors()
}
}

public static bool IsCommunityToolkitWindowsIssue430(ScanResult result)
{
// CommunityToolkit/Windows#430: SettingsExpander internal controls can report
// duplicate Name + LocalizedControlType until the toolkit fix lands.
var description = result.Rule.Description;
return !string.IsNullOrWhiteSpace(description)
&& description.Contains("LocalizedControlType", StringComparison.OrdinalIgnoreCase)
&& description.Contains("Name", StringComparison.OrdinalIgnoreCase)
&& description.Contains("same", StringComparison.OrdinalIgnoreCase);
}

private static string BuildAssertMessage(ScanResult result)
{
// e.g., "Element Button(50000) violated rule 'The Name property of a focusable element must not be null.'."
Expand Down
77 changes: 38 additions & 39 deletions tests/Files.InteractionTests/Tests/SettingsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,48 +19,47 @@ public void Cleanup()
[TestMethod]
public void VerifySettingsAreAccessible()
{
// TODO uncomment after https://github.com/CommunityToolkit/Windows/issues/430 is resolved
//TestHelper.InvokeButtonById("SettingsButton");
//AxeHelper.AssertNoAccessibilityErrors();
TestHelper.InvokeButtonById("SettingsButton");
AxeHelper.AssertNoAccessibilityErrors(AxeHelper.IsCommunityToolkitWindowsIssue430);

//var settingsItems = new string[]
//{
// "SettingsItemGeneral",
// "SettingsItemAppearance",
// //"SettingsItemLayout", TODO find workaround for the "Group by" setting block issue
// "SettingsItemFolders",
// "SettingsItemActions",
// "SettingsItemTags",
// "SettingsItemDevTools",
// "SettingsItemAdvanced",
// "SettingsItemAbout"
//};
var settingsItems = new string[]
{
"SettingsItemGeneral",
"SettingsItemAppearance",
"SettingsItemLayout",
"SettingsItemFolders",
"SettingsItemActions",
"SettingsItemTags",
"SettingsItemDevTools",
"SettingsItemAdvanced",
"SettingsItemAbout"
};

//foreach (var item in settingsItems)
//{
// for (int i = 0; i < 5; i++)
// {
// try
// {
// Console.WriteLine("Invoking button:" + item);
// Thread.Sleep(3000);
// TestHelper.InvokeButtonById(item);
// i = 1000;
// }
// catch (Exception exc)
// {
// Console.WriteLine("Failed to invoke the button:" + item + " with exception" + exc.Message);
// }
foreach (var item in settingsItems)
{
for (int i = 0; i < 5; i++)
{
try
{
System.Console.WriteLine("Invoking button:" + item);
System.Threading.Thread.Sleep(3000);
TestHelper.InvokeButtonById(item);
i = 1000;
}
catch (System.Exception exc)
{
System.Console.WriteLine("Failed to invoke the button:" + item + " with exception" + exc.Message);
}

// }
// try
// {
// // First run can be flaky due to external components
// AxeHelper.AssertNoAccessibilityErrors();
// }
// catch (System.Exception) { }
// AxeHelper.AssertNoAccessibilityErrors();
//}
}
try
{
// First run can be flaky due to external components
AxeHelper.AssertNoAccessibilityErrors(AxeHelper.IsCommunityToolkitWindowsIssue430);
}
catch (System.Exception) { }
AxeHelper.AssertNoAccessibilityErrors(AxeHelper.IsCommunityToolkitWindowsIssue430);
}
}
}
}
Loading