-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathAccessibilityCheckingConfiguration.cs
77 lines (65 loc) · 3.68 KB
/
AccessibilityCheckingConfiguration.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using Deque.AxeCore.Commons;
using Deque.AxeCore.Selenium;
using Lombiq.Tests.UI.Extensions;
using Lombiq.Tests.UI.Helpers;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Lombiq.Tests.UI.Services;
public class AccessibilityCheckingConfiguration
{
/// <summary>
/// Gets or sets a value indicating whether to create an accessibility report if the given test fails accessibility
/// checking.
/// </summary>
public bool CreateReportOnFailure { get; set; } = true;
/// <summary>
/// Gets or sets a value indicating whether to create an accessibility report for every test, regardless of them
/// failing or not. You can use this to e.g. compile an accessibility report for the whole app, encompassing all
/// pages checked by tests. The reports will be added to the test dump.
/// </summary>
public bool CreateReportAlways { get; set; }
/// <summary>
/// Gets or sets a configuration delegate for the <see cref="AxeBuilder"/> instance used for accessibility checking.
/// For more information on the various options see <see
/// href="https://troywalshprof.github.io/SeleniumAxeDotnet/#/?id=axebuilder-reference"/>. Defaults to <see
/// cref="ConfigureWcag22aa"/>.
/// </summary>
public Action<AxeBuilder> AxeBuilderConfigurator { get; set; } = axeBuilder => ConfigureWcag22aa(axeBuilder);
/// <summary>
/// Gets or sets a value indicating whether to automatically run accessibility checks every time a page changes
/// (either due to explicit navigation or clicks) and assert on the validation results.
/// </summary>
public bool RunAccessibilityCheckingAssertionOnAllPageChanges { get; set; }
/// <summary>
/// Gets or sets a predicate that determines whether accessibility checking and asserting the results should run for
/// the current page. This is only used if <see cref="RunAccessibilityCheckingAssertionOnAllPageChanges"/> is set to
/// <see langword="true"/>. Defaults to <see
/// cref="EnableOnValidatablePagesAccessibilityCheckingAndAssertionOnPageChangeRule"/>.
/// </summary>
public Predicate<UITestContext> AccessibilityCheckingAndAssertionOnPageChangeRule { get; set; } =
EnableOnValidatablePagesAccessibilityCheckingAndAssertionOnPageChangeRule;
/// <summary>
/// Gets or sets a delegate to run assertions on the <see cref="AxeResult"/> when accessibility checking happens.
/// Defaults to <see cref="AssertAxeResultIsEmpty"/>.
/// </summary>
public Action<AxeResult> AssertAxeResult { get; set; } = AssertAxeResultIsEmpty;
// Returns AxeBuilder so it can be chained.
public static readonly Func<AxeBuilder, AxeBuilder> ConfigureWcag21aa = axeBuilder =>
axeBuilder.WithTags("wcag2a", "wcag2aa", "wcag21a", "wcag21aa");
public static readonly Func<AxeBuilder, AxeBuilder> ConfigureWcag22aa = axeBuilder =>
axeBuilder.WithTags("wcag2a", "wcag2aa", "wcag21a", "wcag21aa", "wcag22a", "wcag22aa");
public static readonly Action<AxeResult> AssertAxeResultIsEmpty = axeResult =>
{
axeResult.Violations.AxeResultItemsShouldBeEmpty();
axeResult.Incomplete.AxeResultItemsShouldBeEmpty();
};
public static readonly Func<IEnumerable<AxeResultItem>, string> AxeResultItemsToString =
items =>
string.Join(
Environment.NewLine,
items.Select(item =>
$"{item.Help}: {Environment.NewLine}{string.Join(Environment.NewLine, item.Nodes.Select(node => " " + node.Html))}"));
public static readonly Predicate<UITestContext> EnableOnValidatablePagesAccessibilityCheckingAndAssertionOnPageChangeRule =
UrlCheckHelper.IsValidatablePage;
}