API
Static method
AccessibilityAuditor#UserWayAnalysis(AuditConfig config): AnalysisResult
Runs analysis on the current page and returns result object that contains information about violations, that were found on the page.
Default configs (you may not create AnalysisConfig instance if you need default static analysis configuration):
var analysisConfig = new AnalysisConfigBuilder()
.Level(Level.AA) // Scans only for A- and AA-violation levels
.SwitchOff(false) // Analysis will not be performed at all if set to true
.Build();
var auditConfig = new AuditConfigBuilder()
.SaveReport(true) // Saves JSON-report for CA11Y
.ElementScreenshots(false) // Does not take screenshots
.Strict(false) // Does not fail if violations were found
.Build();
Full configs:
public class AnalysisConfig
{
public ISet<Rule>? IncludeRules { get; set; }; // Accessibility guidelines' rules that should be checked on your website
public ISet<Rule>? ExcludeRules { get; set; } // Accessibility guidelines' rules that should NOT be checked on your website
public bool IncludeBestPractices { get; set; } // Whether to show our web content recommendations for your website or not
public bool IncludeExperimental { get; set; } // Whether to show our beta-tested accessibility rules
public Level Level { get; set; } // Specify violations of which level should be searched by analysis
public ISet<string>? IgnoreSelectors { get; set; } // Specify list of CSS-selectors (ids, classes etc.) that should be ignored by analysis
public bool SwitchOff { get; set; } // Turn off analysis, if you do not need it at the moment for some reason
}
public class AuditConfig
{
public WebDriver Driver { get; set; } // Provide your configured WebDriver with already loaded page
public AnalysisConfig? AnalysisConfiguration { get; set; } // Provide configuration for UserWay static analysis script
public bool SaveReport { get; set; } // Whether JSON-report with violations should be saved on your device or not
public string ReportPath { get; set; } // Path to directory, where JSON-reports, HTML-pages and screenshots will be saved
public bool ElementScreenshots { get; set; } // Whether to take screenshots of violations or not
public bool Strict { get; set; } // Whether analysis should fail if at least one violation was found or not
public ISet<string> CustomTags { get; set; } // Tags that will be added for violations found by this analysis
}
Rules
public enum Rule
{
UNKNOWN,
ACCESSKEYS,
AREA_ALT,
ARIA_ALLOWED_ATTR,
ARIA_ALLOWED_ROLE,
ARIA_COMMAND_NAME,
ARIA_DIALOG_NAME,
ARIA_HIDDEN_BODY,
ARIA_HIDDEN_FOCUS,
ARIA_INPUT_FIELD_NAME,
ARIA_METER_NAME,
ARIA_PROGRESSBAR_NAME,
ARIA_REQUIRED_ATTR,
ARIA_REQUIRED_CHILDREN,
ARIA_REQUIRED_PARENT,
ARIA_ROLEDESCRIPTION,
ARIA_ROLES,
ARIA_TEXT,
ARIA_TOGGLE_FIELD_NAME,
ARIA_TOOLTIP_NAME,
ARIA_TREEITEM_NAME,
ARIA_VALID_ATTR,
ARIA_VALID_ATTR_VALUE,
AUDIO_CAPTION,
AUTOCOMPLETE_VALID,
AVOID_INLINE_SPACING,
BLINK,
BOLD,
BUTTON_NAME,
BYPASS,
BYPASS_MOVE_FOCUS,
COLOR_CONTRAST,
COLOR_CONTRAST_ENHANCED,
CSS_ORIENTATION_LOCK,
CUSTOM_FOCUSABLE_ELEMENTS,
DEFINITION_LIST,
DLITEM,
DOCUMENT_TITLE,
DUPLICATE_ID,
DUPLICATE_ID_ACTIVE,
DUPLICATE_ID_ARIA,
EMPTY_HEADING,
EMPTY_TABLE_HEADER,
FIELDSET_LEGEND,
FOCUS_ORDER_SEMANTICS,
FORM_FIELD_MULTIPLE_LABELS,
FRAME_FOCUSABLE_CONTENT,
FRAME_TITLE,
FRAME_TITLE_UNIQUE,
HEADING_ORDER,
HIDDEN_CONTENT,
HTML_HAS_LANG,
HTML_LANG_VALID,
HTML_XML_LANG_MISMATCH,
IDENTICAL_LINKS_SAME_PURPOSE,
IMAGE_ALT,
IMAGE_ALT_LONG,
IMAGE_ALT_SUSPICIOUS,
IMAGE_LINK_WITHOUT_TEXT,
IMAGE_REDUNDANT_ALT,
IMAGE_SAME_ALT,
INPUT_BUTTON_NAME,
INPUT_IMAGE_ALT,
INVALID_ID,
ITALIC,
LABEL,
LABEL_CONTENT_NAME_MISMATCH,
LABEL_TITLE_ONLY,
LANDMARK_BANNER_IS_TOP_LEVEL,
LANDMARK_COMPLEMENTARY_IS_TOP_LEVEL,
LANDMARK_CONTENT_INFO_IS_TOP_LEVEL,
LANDMARK_MAIN_IS_TOP_LEVEL,
LANDMARK_NO_DUPLICATE_BANNER,
LANDMARK_NO_DUPLICATE_CONTENTINFO,
LANDMARK_NO_DUPLICATE_MAIN,
LANDMARK_ONE_MAIN,
LANDMARK_UNIQUE,
LINK_AMBIGUOUS_TEXT,
LINK_IN_TEXT_BLOCK,
LINK_NAME,
LINK_NO_MENTION_TARGET_BLANK,
LINK_REFER_TO_IMAGE,
LIST,
LISTITEM,
MARQUEE,
META_REFRESH,
META_REFRESH_NO_EXCEPTIONS,
META_VIEWPORT,
META_VIEWPORT_LARGE,
NESTED_INTERACTIVE,
NO_AUTOPLAY_AUDIO,
NO_AUTOPLAY_AUDIO_NO_EXCEPTIONS,
OBJECT_ALT,
P_AS_HEADING,
PAGE_HAS_HEADING_ONE,
PRESENTATION_ROLE_CONFLICT,
REGION,
ROLE_IMG_ALT,
SCOPE_ATTR_VALID,
SCROLLABLE_REGION_FOCUSABLE,
SELECT_NAME,
SERVER_SIDE_IMAGE_MAP,
SKIP_LINK,
SVG_IMG_ALT,
TABINDEX,
TABLE_DUPLICATE_NAME,
TABLE_FAKE_CAPTION,
TARGET_SIZE,
TD_HAS_HEADER,
TD_HEADERS_ATTR,
TH_HAS_DATA_CELLS,
VALID_LANG,
VIDEO_CAPTION
}
Examples
var analysisConfig = new AnalysisConfigBuilder()
.ExcludeRules([Rule.TARGET_SIZE, Rule.VIDEO_CAPTION, Rule.SVG_IMG_ALT])
.IncludeBestPractices(true)
.IncludeExperimental(false)
.Level(Level.AAA)
.IgnoreSelectors([".my-class", "button", "#lettuce"])
.SwitchOff(false)
.Build();
var options = new ChromeOptions();
options.AddArgument("--headless");
var driver = new ChromeDriver(options);
driver.Url = "https://userway.org";
var auditConfig = new AuditConfigBuilder()
.Driver(driver)
.AnalysisConfiguration(analysisConfig)
.SaveReport(true)
.ReportPath("./uw-a11y-reports")
.ElementScreenshots(true)
.Build();
var result = AccessibilityAuditor.UserWayAnalysis(auditConfig);
// assert ...
Config
AnalysisConfig
IncludeRules
Set of rules to include. Accepts a set of Rule
values. Default is []
.
ExcludeRules
Set of rules to exclude. Accepts a set of Rule
values. Default is []
.
Note, that this parameter has higher priority then includeRules. It means that if the same rule was
added in includeRules and excludeRules then this rule will be excluded.
IncludeBestPractices
Specify whether to include best practices rules (our recommendations). Default is true
.
IncludeExperimental
Specify whether to include experimental rules (beta tested possibly unstable rules). Default is true
.
Level
Specify the conformance level. Possible values: A
, AA
, AAA
. Default is AA
.
IgnoreSelectors
List of selectors for elements to ignore. Accepts an ISet<string>
.
Note: use "ignoreSelectors" only to exclude specific elements, avoid using it in root element like body, head, html ( for such elements you can manually exclude related rules ) To see list of all rules related to html or body elements refer to "Rules" section.
SwitchOff
Default value is false
. Set this property to true
if you want to temporarily disable static analysis.
AuditConfig
Driver
Provide your configured Selenium WebDriver instance with already loaded target page.
CustomTags
This property is used to distinguish issues by some criteria. For example, you have test method that goes through your site's flow. This flow includes:
- Login into the system
- Creating a post
- Watching the list of all posts.
You want to execute scans after each of these parts, and you also want to filter issues on CA11Y dashboard by the following criteria:
- Issues that were found during login
- Issues that were found during creation of a post
- Issues that were found during watching the list of all posts.
For this result you can start first scan with
["general-flow", "login"]
, second with["general-flow", "creating-post"]
and third with["general-flow", "watching-posts"]
AnalysisConfiguration
Provide your AnalysisConfig
instance. This config is completely optional.
SaveReport
Default value is false
. Set this property to true
if you want to save JSON-report with your webpage violations.
ReportPath
Default value is ./uw-a11y-reports
. Specify here path to directory where you wish to save all JSON-reports, HTML-pages and violations screenshots.
Screenshots
Default value is false
. Set this property to true
if you want auditor to take screenshots of violations on your webpage.
Strict
Default value is false
. Set this property to true
if you want analysis to instantly stop if at least one violation
was found.
If analysis was stopped due to strict
configuration, then it will return AnalysisResult
object with status == AnalysisStatus.FAILED_ON_STRICT
.
Environment variables
Almost each property of analysis can be specified as environment variable. Note that environment variables have higher
priority than configuration that was specified via AnalysisConfig
and AuditConfig
.
Here is list of all environment variables that you can use:
USERWAY_CA_SWITCH_OFF # true or false
UW_A11Y_SAVE_JSON_REPORT # true or false
UW_A11Y_REPORT_PATH # Path to directory where auditor should save all result files
UW_A11Y_SCREENSHOTS # true or false
UW_A11Y_STRICT # true or false
UW_A11Y_INCLUDE_RULES # Separated with `,` list of strings
UW_A11Y_EXCLUDE_RULES # Separated with `,` list of strings
UW_A11Y_WITH_BEST_PRACTICES # true or false
UW_A11Y_WITH_EXPERIMENTAL # true or false
UW_A11Y_LEVEL # A, AA, AAA
UW_A11Y_IGNORE_SELECTORS # Separated with `,` list of strings
UW_A11Y_PRINT_VIOLATIONS_TABLE # true or false
Note: you can set USERWAY_CA_SWITCH_OFF=true
if you want to disable UserWay analysis on pipeline, for example.