3
3
4
4
using Axe . Windows . Automation ;
5
5
using Axe . Windows . Core . Enums ;
6
+ using System ;
6
7
using System . Diagnostics ;
7
8
using System . Linq ;
9
+ using System . Text ;
8
10
9
11
namespace Files . InteractionTests . Helper
10
12
{
@@ -25,11 +27,37 @@ internal static void InitializeAxe()
25
27
public static void AssertNoAccessibilityErrors ( )
26
28
{
27
29
var testResult = AccessibilityScanner . Scan ( null ) . WindowScanOutputs . SelectMany ( output => output . Errors ) . Where ( error => error . Rule . ID != RuleId . BoundingRectangleNotNull ) ;
28
- if ( testResult . Count ( ) != 0 )
30
+ if ( testResult . Any ( ) )
29
31
{
30
- var mappedResult = testResult . Select ( result => "Element " + result . Element . Properties [ "ControlType" ] + " violated rule '" + result . Rule . Description + "'." ) ;
31
- Assert . Fail ( "Failed with the following accessibility errors \r \n " + string . Join ( "\r \n " , mappedResult ) ) ;
32
+ StringBuilder sb = new ( ) ;
33
+ sb . AppendLine ( ) ;
34
+ sb . AppendLine ( "============================================================" ) ;
35
+ sb . AppendJoin ( Environment . NewLine , testResult . Select ( BuildAssertMessage ) ) ;
36
+ sb . AppendLine ( ) ;
37
+ sb . AppendLine ( "============================================================" ) ;
38
+
39
+ Assert . Fail ( sb . ToString ( ) ) ;
40
+ }
41
+ }
42
+
43
+ private static string BuildAssertMessage ( ScanResult result )
44
+ {
45
+ // e.g., "Element Button(50000) violated rule 'The Name property of a focusable element must not be null.'."
46
+ return $ "Element { result . Element . Properties [ "ControlType" ] } at ({ ParseBoundingRectangle ( result . Element . Properties [ "BoundingRectangle" ] ) } ) violated rule \" { result . Rule . Description } \" .";
47
+ }
48
+
49
+ private static string ParseBoundingRectangle ( string boundingRectangle )
50
+ {
51
+ // e.g., "[l=1617,t=120,r=1663,b=152]" to "x=1617,y=120,w=46,h=32"
52
+ var output = new ushort [ 4 ] ;
53
+ var parts = boundingRectangle . Trim ( '[' ) . Trim ( ']' ) . Split ( ',' ) ;
54
+ for ( int index = 0 ; index < 4 ; index ++ )
55
+ {
56
+ if ( ushort . TryParse ( parts [ index ] [ 2 ..] , out var res ) )
57
+ output [ index ] = res ;
32
58
}
59
+
60
+ return $ "x={ output [ 0 ] } ,y={ output [ 1 ] } ,w={ output [ 2 ] - output [ 0 ] } ,h={ output [ 3 ] - output [ 1 ] } ";
33
61
}
34
62
}
35
63
}
0 commit comments