axe DevTools for Web Configuration for C#

This page is not available in the language you requested. You have been redirected to the English version of the page.
Link to this page copied to clipboard

Configuration information and sample code for axe DevTools for Web for C#

Not for use with personal data

This article describes how to configure axe DevTools for Web for C#.

Step 1: Declare the Selenium driver to use while running tests in the C# setup.

[SetUp]
public void Setup()
{
  driver = new ChromeDriver();
  driver.Navigate().GoToUrl("http://abcdcomputech.dequecloud.com/");
}

Step 2: Specify portions of the page to include or exclude from testing.

/*
* TestCase: uses axe.Analyze() to scan the certain content on the page.
*/
[Test]
public void IncludingAndExcludingElements()
{
  var axe = new AxeSelenium(driver).Excluding("#header").Including("#homecontent");
  var results = axe.Analyze();
  Assert.That(results.Findings.Violations.Count, Is.EqualTo(0));
}

Step 3: Axe DevTools C# packages a version of the axe-core JavaScript library. Alternatively, provide your own copy through configuration.

note

The axe-core library expects your audit suite to be located in your project at: /config/axe-ruleset.json. Alternatively, you can specify the location by setting the AXE_RULESET_PATH environment variable, directly in configuration.

Step 4: Define rulesets or specific rules for a single accessibility check or for the entire test suite.

/*
 * TestCase: uses axe.Analyze() to scan the page
 * with specific ruleset, in this case 508
*/
[Test]
public void AccessibilityAnalyzeWith508Ruleset()
{
 var axe = new AxeSelenium(driver).WithRuleset("508");
  var results = axe.Analyze();
  AxeReporting.CreateResultsOutput(results, "508-rules");
  Assert.That(results.Findings.Violations.Count, Is.EqualTo(0));
}

/*
 * TestCase: uses axe.Analyze() to scan the page
 * with only the specified rules.
*/
[Test]
public void AccessibilityAnalyzeWithSpecificRules()
{
  var axe = new AxeSelenium(driver).WithRules("heading-order", "link-name");
  var results = axe.Analyze();
  AxeReporting.CreateResultsOutput(results, "specific-rules");
  Assert.That(results.Findings.Violations.Count, Is.EqualTo(0));
}

See Custom Rulesets for general information about Writing Rules, Rules, Checks, and Results, and Rule Descriptions.