From 9277a41e5d1fef654638dfffbc8270f5387db3a4 Mon Sep 17 00:00:00 2001 From: 0x5BFA <62196528+0x5bfa@users.noreply.github.com> Date: Mon, 21 Jul 2025 00:31:00 +0900 Subject: [PATCH] Init --- .../Helper/AxeHelper.cs | 34 +++++++++++++++++-- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/tests/Files.InteractionTests/Helper/AxeHelper.cs b/tests/Files.InteractionTests/Helper/AxeHelper.cs index e65ccadbb385..39036c6ffdc0 100644 --- a/tests/Files.InteractionTests/Helper/AxeHelper.cs +++ b/tests/Files.InteractionTests/Helper/AxeHelper.cs @@ -3,8 +3,10 @@ using Axe.Windows.Automation; using Axe.Windows.Core.Enums; +using System; using System.Diagnostics; using System.Linq; +using System.Text; namespace Files.InteractionTests.Helper { @@ -25,11 +27,37 @@ internal static void InitializeAxe() public static void AssertNoAccessibilityErrors() { var testResult = AccessibilityScanner.Scan(null).WindowScanOutputs.SelectMany(output => output.Errors).Where(error => error.Rule.ID != RuleId.BoundingRectangleNotNull); - if (testResult.Count() != 0) + if (testResult.Any()) { - 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)); + StringBuilder sb = new(); + sb.AppendLine(); + sb.AppendLine("============================================================"); + sb.AppendJoin(Environment.NewLine, testResult.Select(BuildAssertMessage)); + sb.AppendLine(); + sb.AppendLine("============================================================"); + + Assert.Fail(sb.ToString()); + } + } + + private static string BuildAssertMessage(ScanResult result) + { + // e.g., "Element Button(50000) violated rule 'The Name property of a focusable element must not be null.'." + return $"Element {result.Element.Properties["ControlType"]} at ({ParseBoundingRectangle(result.Element.Properties["BoundingRectangle"])}) violated rule \"{result.Rule.Description}\"."; + } + + private static string ParseBoundingRectangle(string boundingRectangle) + { + // e.g., "[l=1617,t=120,r=1663,b=152]" to "x=1617,y=120,w=46,h=32" + var output = new ushort[4]; + var parts = boundingRectangle.Trim('[').Trim(']').Split(','); + for (int index = 0; index < 4; index++) + { + if (ushort.TryParse(parts[index][2..], out var res)) + output[index] = res; } + + return $"x={output[0]},y={output[1]},w={output[2] - output[0]},h={output[3] - output[1]}"; } } } \ No newline at end of file