1+ //******************************************************************************
2+ //
3+ // Copyright (c) 2023 Microsoft Corporation. All rights reserved.
4+ //
5+ // This code is licensed under the MIT License (MIT).
6+ //
7+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
8+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
9+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
10+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
11+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
12+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
13+ // THE SOFTWARE.
14+ //
15+ //******************************************************************************
16+
17+ using Axe . Windows . Automation ;
18+ using System . Diagnostics ;
19+ using System . Linq ;
20+
21+ namespace UITests
22+ {
23+ public class AxeHelper
24+ {
25+ public static IScanner AccessibilityScanner ;
26+
27+ internal static void InitializeAxe ( )
28+ {
29+ var processes = Process . GetProcessesByName ( "WinUIGallery.DesktopWap" ) ;
30+ Assert . IsTrue ( processes . Length > 0 ) ;
31+
32+ var config = Config . Builder . ForProcessId ( processes [ 0 ] . Id ) . Build ( ) ;
33+
34+ AccessibilityScanner = ScannerFactory . CreateScanner ( config ) ;
35+ }
36+
37+ public static void AssertNoAccessibilityErrors ( )
38+ {
39+ var testResult = AccessibilityScanner . Scan ( null ) . WindowScanOutputs . SelectMany ( output => output . Errors ) ;
40+ if ( testResult . Count ( ) != 0 )
41+ {
42+ var mappedResult = testResult . Select ( result => "Element " + result . Element . Properties [ "ControlType" ] + " violated rule '" + result . Rule . Description + "'." ) ;
43+ Assert . Fail ( "Failed with the following accessibility errors \r \n " + string . Join ( "\r \n " , mappedResult ) ) ;
44+ }
45+ }
46+ }
47+ }
0 commit comments