C# API reference

Link to C# API reference copied to clipboard

Axe DevTools C# Classes

This page documents the classes which make up axe DevTools C#

class Deque.AxeDevtools.Selenium.AxeSelenium

The interface to axe. Contains configurations to change how axe runs as well as the ability to run axe.

static Field Type Description
defaultAxeSource string The default axe-core string that will be used.

AxeSelenium(OpenQA.Selenium.Remote.RemoteWebDriver, ReportConfiguration?, string)

Create a new AxeSelenium object for a page with specific configuration.

Param Description
webdriver Selenium object of the page to test. Should be in the state ready to test.
reportConfiguration Configuration for various report-specific information. Defaults to ReportConfiguration.GetDefault()
axeSource axe-core source to use. Defaults to AxeSelenium.defaultAxeSource

ReportResultsAnalyze()

Run axe on the page.

Returns: The report from running axe-core on the page.

var report = new AxeSelenium(driver).Analyze();

AxeSelenium Configure(Spec)

Configure axe. Done via axe.configure

Param Description
spec Spec object to pass.

Returns: This object for chaining.

var spec = new Spec.Spec {
    Checks = new Spec.Check[] {
        new Spec.Check() {
            Id = "dylang",
            Options = (object) new string[] { "dylan" },
            Evaluate = @"function (node, options) {
              var lang = (node.getAttribute('lang') || '').trim().toLowerCase();
              var xmlLang = (node.getAttribute('xml:lang') || '').trim().toLowerCase();
              var invalid = [];
              (options || []).forEach(function(cc) {
                cc = cc.toLowerCase();
                if (lang && (lang === cc || lang.indexOf(cc.toLowerCase() + '-') === 0)) {
                  lang = null;
                }
                if (xmlLang && (xmlLang === cc || xmlLang.indexOf(cc.toLowerCase() + '-') === 0)) {
                  xmlLang = null;
                }
              });
              if (xmlLang) {
                invalid.push('xml:lang='' + xmlLang + ''');
              }
              if (lang) {
                invalid.push('lang='' + lang + ''');
              }
              if (invalid.length) {
                this.data(invalid);
                return true;
              }
              return false;
            }"
        }
    },
    Rules = new Spec.Rule[] {
        new Spec.Rule() {
            Id = "dylang",
            Selector = "html",
            Tags = new string[] { "wcag2aa" },
            All = new string[0],
            Any = new string[0],
            None = new string[] { "dylang" }
        }
    }
};
var report = new AxeSelenium(driver)
  .Configure(spec)
  .Analyze()

AxeSeleniumDisablingRules(string[])

Disable some rules when running axe.

Param Description
rules List of ids of rules.

Returns: This object for chaining.

var report = new AxeSelenium(driver)
  .DisablingRules("html-has-lang", "label")
  .Analyze()

AxeSeleniumExcluding(string[])

Specify part of the page to exclude when running axe.

Param Description
selector List of CSS selectors for elements.

Returns: This object for chaining.

var report = new AxeSelenium(driver)
  .Excluding(".third-party-ad", ".iframe1")
  .Analyze()

AxeSeleniumIncluding(string[])

Specify part of the page to run axe on.

Param Description
selector List of CSS selectors for elements.

Returns: This object for chaining.

var report = new AxeSelenium(driver)
  .Including(".sidebar", ".some-class")
  .Analyze()

AxeSelenium RunOptions(RunOptions)

Specify RunOptions to pass to axe when calling axe.run.

Param Description
options Object to pass

Returns: This object for chaining.

var options = new RunOptions.RunOptions {
  IFrames = false,
  RunOnly = RunOptions.RunOnly.Tags(RunOptions.TagType.Wcag2a)
};
var report = new AxeSelenium(driver)
  .RunOptions(options)
  .Analyze()

AxeSeleniumWithConfigFile(string)

Set where to find a config file. Default path is config/axe-ruleset.json or $AXE_RULESET_PATH.

Param Description
path Path to config file.

Returns: This object for chaining.

var report = new AxeSelenium(driver)
  .WithConfigFile("path/to/file.json")
  .Analyze();

AxeSeleniumWithRules(string[])

Specify rules (by id) to use when running axe.

Param Description
rules List of ids of rules.

Returns: This object for chaining.

var report = new AxeSelenium(driver)
  .WithRules("document-title", "label")
  .WithRules("html-has-lang")
  .Analyze()

AxeSeleniumWithRuleset(string, bool)

Use a specific ruleset (i.e. wcag2.1, 508).

Param Description
rulesetId Id of the ruleset to use.
enableBestPractices Whether or not to turn on rules tagged best-practice. Defaults to false

Returns: This object for chaining.

var report = new AxeSelenium(driver)
  .WithRuleset("508", true)
  .Analyze()

AxeSelenium WithTags(TagType[])

Specify rules (by tag) to use when running axe.

Param Description
tags List of tags of rules.

Returns: This object for chaining.

var report = new AxeSelenium(driver)
  .WithTags(RunTagType.BestPractice)
  .Analyze()

Environment variables

This method allows users to change specific values of the usage service via environment variables

Environment Variable Type
AXE_IS_LOGGED_IN Boolean
AXE_KEYCLOAK_ID String
AXE_USER_ID String
AXE_SESSION_ID String
AXE_USER_STATUS String
AXE_USER_JOB_ROLE String
AXE_DISTINCT_ID String
AXE_IS_DEV_INSTANCE Boolean
AXE_ORGANIZATION String
AXE_APPLICATION String
AXE_METRICS_URL String
AXE_TRACK_USAGE Boolean

AxeSeleniumEnableTracking(bool)

Opt in to or out of sending data to usage service.

Param Description
state Whether tracking is enabled

Returns: This object for chaining.

AxeSeleniumSetTrackingUrl(string)

Set where usage metrics data are sent. Defaults to https://usage.deque.com

Param Description
url URL where it will be sent

Returns: This object for chaining.

AxeSeleniumSetDistinctId(string)

Set distinct id used when sending usage metrics.

Param Description
id UUID to send as distinct id

Returns: This object for chaining.

class Deque.AxeDevtools.Selenium.ReportConfiguration

Configures report-specific information like test suite name or user agent information

static Field Type Description
TIMESTAMP_FORMAT string Format of timestamps in reports.

static ReportConfigurationGetDefault()

Gets the current default configuration. Note that the default can be changed.

Returns: The current default.

static void ResetDefault()

Resets the default to its initial state.

void SetAsDefault()

Sets this object as the default.

ReportConfiguration.GetDefault()
  .TestSuiteName("my-tests")
  .UIState("home-page")
  .SetAsDefault();

ReportConfigurationTestMachine(string)

Sets the machine these tests were run on.

Param Description
testMachine Id for the machine.

Returns: This object for chaining.

ReportConfigurationTestSuiteName(string)

Sets the test suite name.

Param Description
name Name.

Returns: This object for chaining.

ReportConfigurationUIState(string)

Specify the ui-state for this set of tests. Used as ID.

Param Description
id State id.

Returns: This object for chaining.

ReportConfigurationUserAgent(string)

Set the user agent used when testing.

Param Description
userAgent User agent string.

Returns: This object for chaining.

class Deque.AxeDevtools.Selenium.Results.Check

The result of running an axe check.

Field Type Description
Data object Additional information that is specific to the type of Check which is optional. For example, a color contrast check would include the foreground color, background color, contrast ratio, etc.
Id string Unique identifier for this check. Check ids may be the same as Rule ids.
Impact string How serious this particular check is. Can be one of "minor", "moderate", "serious", or "critical". Each check that is part of a rule can have different impacts. The highest impact of all the checks that fail is reported for the rule.
Message string Description of why this check passed or failed.
RelatedNodes List<Node> Optional array of information about other nodes that are related to this check. For example, a duplicate id check violation would list the other selectors that had this same duplicate id.

class Deque.AxeDevtools.Selenium.Results.CheckedNode

An HTML node that was checked by a rule.

Field Type Description
All List<Check> Array of checks that were made where all must have passed.
Any List<Check> Array of checks that were made where at least one must have passed.
Impact string How serious the violation is. Can be one of "minor", "moderate", "serious", or "critical" if the test failed or null if the check passed.
None List<Check> Array of checks that were made where all must have not passed.

class Deque.AxeDevtools.Selenium.Results.Node

Specifies a specific HTML node.

Field Type Description
Html string Snippet of HTML of the Element.
Target object Array of either strings or Arrays of strings. If the item in the array is a string, then it is a CSS selector. If there are multiple items in the array each item corresponds to one level of iframe or frame. If there is one iframe or frame, there should be two entries in target. If there are three iframe levels, there should be four entries in target. If the item in the Array is an Array of strings, then it points to an element in a shadow DOM and each item (except the n-1th) in this array is a selector to a DOM element with a shadow DOM. The last element in the array points to the final shadow DOM node.

class Deque.AxeDevtools.Selenium.Results.Platform

The platform a test was run on.

Field Type Description
TestMachine string Id of the machine the test was run on.
UserAgent string User agent the test was run on.

class Deque.AxeDevtools.Selenium.Results.ReportResults

Results from a test that are compatible with the reporter format.

var axe = new AxeSelenium(driver, ReportConfiguration.GetDefault().UIState("UIState"));
var res = axe.Analyze();
File.WriteAllText(reportPath, JsonConvert.SerializeObject(res));
Field Type Description
EndTime string When the test was complete.
Findings TestResults Axe results.
Id string Id for the test run.
Name string Name of the test run.
Platform Platform Information on the platform on which the test was run.
TestSubject TestSubject Information on where the test was run (e.g. the URL of the webpage).
Type string Type of report. Is always "attest-result".

class Deque.AxeDevtools.Selenium.Results.Rule

Result for a single rule.

Field Type Description
CreatedDate string The date and time that analysis was completed.
Description string Text string that describes what the rule does.
Help string Help text that describes the test that was performed.
HelpUrl string URL that provides more information about the specifics of the violation. Links to a page on the Deque University site.
Id string Unique identifier for the rule.
Impact string How serious the violation is. Can be one of "minor", "moderate", "serious", or "critical" if the Rule failed or null if the check passed.
Nodes List<CheckedNode> Array of all elements the Rule tested.
Tags List<string> Array of tags that this rule is assigned. These tags can be used in the option structure to select which rules are run.
Url string The URL of the page that was tested.

class Deque.AxeDevtools.Selenium.Results.TestEngine

Information on the axe-core engine the test was run on.

Field Type Description
Name string Name of the engine.
Version string Version number for the engine.

class Deque.AxeDevtools.Selenium.Results.TestEnvironment

Information about the environment in which the test was performed.

Field Type Description
OrientationAngle double? Angle of orientation of the screen. (e.g. 0)
OrientationType string Type of orientation of the screen. (e.g. "landscape-primary")
UserAgent string User agent of the browser in which the test was run.
WindowHeight int Height of the window.
WindowWidth int Width of the window.

class Deque.AxeDevtools.Selenium.Results.TestResults

Results returned by running axe on the page.

Field Type Description
Inapplicable List<Rule> These results were aborted and require further testing. This can happen either because of technical restrictions to what the rule can test, or because a JavaScript error occurred.
Incomplete List<Rule> These results indicate which rules did not run because no matching content was found on the page. For example, with no video, those rules won't run.
Passes List<Rule> These results indicate what elements passed the rules.
TestEngine TestEngine Information about the axe-core engine used in the test.
TestEnvironment TestEnvironment Information about the environment in which the test was performed.
TestRunner TestRunner Name of the test runner.
Timestamp string The date and time that analysis was completed.
ToolOptions object Options applied when testing.
Url string The URL of the page that was tested.
Violations List<Rule> These results indicate what elements failed the rules.

class Deque.AxeDevtools.Selenium.Results.TestRunner

Name of the test runner.

Field Type Description
Name string The name.

class Deque.AxeDevtools.Selenium.Results.TestSubject

Information about what is being tested.

Field Type Description
FileName string Filename of the site-under-test. (Can be a URL.)
LineNum int Line number of the test.
State string State of the file.

class Deque.AxeDevtools.Selenium.RunOptions.Context

Specify which element should and which should not be tested.

void Excluding(string[])

Add a selector set for elements which should not be tested.

Param Description
exclude CSS selector set.

void Including(string[])

Add a selector set for elements which should be tested.

Param Description
include CSS selector set.

enum Deque.AxeDevtools.Selenium.RunOptions.ResultGroup

  • Passes
  • Violations
  • Incomplete
  • Inapplicable

class Deque.AxeDevtools.Selenium.RunOptions.RuleStatus

Enables or disables a rule.

Field Type Description
Enabled bool Whether or not it is enabled.

class Deque.AxeDevtools.Selenium.RunOptions.RunOnly

Limit which rules are executed, based on names or tags.

static RunOnlyRules(string[])

Construct a limiter for rules based on ids.

Param Description
rules List of ids of rules to use.

Returns: The RunOnly object.

static RunOnly Tags(TagType[])

Construct a limiter for rules based on tags.

Param Description
types List of tags to use.

Returns: The RunOnly object.

enum Deque.AxeDevtools.Selenium.RunOptions.RunOnlyType

  • Rule
  • Rules
  • Tag
  • Tags

class Deque.AxeDevtools.Selenium.RunOptions.RunOptions

A flexible configuration for how axe operates.

Field Type Description
ElementRef bool? Return element references in addition to the target.
IFrames bool? Tell axe to run inside iframes.
ResultTypes ResultGroup[] Limit which result types are processed and aggregated
Rules Dictionary<string, RuleStatus> Allow customizing a rule's properties (including { enable: false }).
RunOnly RunOnly Limit which rules are executed, based on names or tags.
Selectors bool? Return xpath selectors for elements.

enum Deque.AxeDevtools.Selenium.RunOptions.TagType

  • Wcag2a
  • Wcag2aa
  • Wcag2aaa
  • Wcag21a
  • Wcag21aa
  • Wcag21aaa
  • Wcag22a
  • Wcag22aa
  • Wcag22aaa
  • Section508
  • TTv5
  • EN301549
  • BestPractice

class Deque.AxeDevtools.Selenium.Spec.Check

Used to add checks to the list of checks used by rules, or to override the properties of existing checks.

Field Type Description
After string This is the function that gets called for checks that operate on a page-level basis, to process the results from the iframes.
Enabled bool? This is used to indicate whether the check is on or off by default. Checks that are off are not evaluated, even when included in a rule. Overriding this is a common way to disable a particular check across multiple rules.
Evaluate string This is the function that implements the check's functionality.
Id string This uniquely identifies the check. If the check already exists, this will result in any supplied check properties being overridden.
Matches string A filtering CSS selector that will exclude elements that do not match the CSS selector.
Options object This is the options structure that is passed to the evaluate function and is intended to be used to configure checks. It is the most common property that is intended to be overridden for existing checks.

class Deque.AxeDevtools.Selenium.Spec.Rule

Used to add rules to the existing set of rules, or to override the properties of existing rules.

Field Type Description
All string[] This is a list of checks that, if any "fails", will generate a violation.
Any string[] This is a list of checks that, if none "pass", will generate a violation.
Enabled bool? Whether the rule is turned on. This is a common attribute for overriding.
ExcludeHidden bool? This indicates whether elements that are hidden from all users are to be passed into the rule for evaluation.
Id string This uniquely identifies the rule. If the rule already exists, it will be overridden with any of the attributes supplied.
Matches string A filtering CSS selector that will exclude elements that do not match the CSS selector.
None string[] This is a list of checks that, if any "pass", will generate a violation.
PageLevel bool? When set to true, this rule is only applied when the entire page is tested. Results from nodes on different frames are combined into a single result.
Selector string A CSS selector used to identify the elements that are passed into the rule for evaluation.
Tags string[] A list if the tags that "classify" the rule. In practice, you must supply some valid tags or the default evaluation will not invoke the rule. The convention is to include the standard (WCAG 2, section 508, Trusted Tester v5, or EN 301 549), the WCAG 2 level, Section 508 paragraph, and the WCAG 2 success criteria. Tags are constructed by converting all letters to lower case, removing spaces and periods and concatenating the result. E.g. WCAG 2 A success criteria 1.1.1 would become ["wcag2a", "wcag111"]

class Deque.AxeDevtools.Selenium.Spec.Spec

Configures the format of the data used by axe. This can be used to add new rules, which must be registered with the library to execute.

Field Type Description
Branding Branding Used to set the branding of the helpUrls .
Checks Check[] Used to add checks to the list of checks used by rules, or to override the properties of existing checks.
Locale Locale A locale object to apply (at runtime) to all rules and checks.
ReporterVersion ReporterVersion? Used to set the output format that the axe.run function will return.
Rules Rule[] Used to add rules to the existing set of rules, or to override the properties of existing rules.