Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

accessibility-developer-tools

GoogleChrome86.8kApache-2.02.12.0

This is a library of accessibility-related testing and utility code.

accessibility, testing, WCAG

readme

Build Status npm version npm downloads

Accessibility Developer Tools

This is a library of accessibility-related testing and utility code.

Its main component is the accessibility audit: a collection of audit rules checking for common accessibility problems, and an API for running these rules in an HTML page.

There is also a collection of accessibility-related utility code, including but not limited to:

Getting the code

To include just the javascript rules, require the following file:

https://raw.github.com/GoogleChrome/accessibility-developer-tools/stable/dist/js/axs_testing.js

git 1.6.5 or later:

% git clone --recursive https://github.com/GoogleChrome/accessibility-developer-tools.git

Before git 1.6.5:

% git clone https://github.com/GoogleChrome/accessibility-developer-tools.git
% cd accessibility-developer-tools
% git submodule init; git submodule update

Building

You will need node and grunt-cli to build.

  1. (Once only) Install Node.js and npm - useful instructions here: https://gist.github.com/isaacs/579814

    Make sure you have Node.js v 0.8 or higher.

  2. (Once only) Use npm to install grunt-cli

     % npm install -g grunt-cli  # May need to be run as root
  3. (Every time you make a fresh checkout) Install dependencies (including grunt) for this project (run from project root)

     % npm install
  4. (Rebuild if you make changes) Build using grunt (run from project root)

     % grunt

Troubleshooting

This project uses Closure Compiler to build our releases. You may need to install a recent version of JDK in order for builds to successfully complete.

Using the Audit API

Including the library

The simplest option is to include the generated axs_testing.js library on your page. After you build, you will have two versions of axs_testings.js:

  • Distribution Build: project-root/dist/js/axs_testing.js
  • Local Build (use if you make changes): project-root/tmp/build/axs_testing.js

Work is underway to include the library in WebDriver and other automated testing frameworks.

The axs.Audit.run() method

Once you have included axs_testing.js, you can call axs.Audit.run(). This returns an object in the following form:

{
  /** @type {axs.constants.AuditResult} */
  result,  // one of PASS, FAIL or NA

  /** @type {Array.<Element>} */
  elements,  // The elements which the rule fails on, if result == axs.constants.AuditResult.FAIL

  /** @type {axs.AuditRule} */
  rule  // The rule which this result is for.
}

Command Line Runner

The Accessibility Developer Tools project includes a command line runner for the audit. To use the runner, install phantomjs then run the following command from the project root directory.

$ phantomjs tools/runner/audit.js <url-or-filepath>

The runner will load the specified file or URL in a headless browser, inject axs_testing.js, run the audit and output the report text.

Run audit from Selenium WebDriver (Scala):

 val driver = org.openqa.selenium.firefox.FirefoxDriver //use driver of your choice
 val jse = driver.asInstanceOf[JavascriptExecutor]
 jse.executeScript(scala.io.Source.fromURL("https://raw.githubusercontent.com/GoogleChrome/" +
   "accessibility-developer-tools/stable/dist/js/axs_testing.js").mkString)
 val report = jse.executeScript("var results = axs.Audit.run();return axs.Audit.createReport(results);")
 println(report)

Run audit from Selenium WebDriver (Scala)(with caching):

 val cache = collection.mutable.Map[String, String]()
 val driver = org.openqa.selenium.firefox.FirefoxDriver //use driver of your choice
 val jse = driver.asInstanceOf[JavascriptExecutor]
 def getUrlSource(arg: String): String = cache get arg match {
    case Some(result) => result
    case None =>
      val result: String = scala.io.Source.fromURL(arg).mkString
      cache(arg) = result
      result
  }
 jse.executeScript(getUrlSource("https://raw.githubusercontent.com/GoogleChrome/" +
   "accessibility-developer-tools/stable/dist/js/axs_testing.js"))
 val report = js.executeScript("var results = axs.Audit.run();return axs.Audit.createReport(results);")
 println(report)

If println() outputs nothing, check if you need to set DesiredCapabilities for your WebDriver (such as loggingPrefs): https://code.google.com/p/selenium/wiki/DesiredCapabilities

Using the results

Interpreting the result

The result may be one of three constants:

  • axs.constants.AuditResult.PASS - This implies that there were elements on the page that may potentially have failed this audit rule, but they passed. Congratulations!
  • axs.constants.AuditResult.NA - This implies that there were no elements on the page that may potentially have failed this audit rule. For example, an audit rule that checks video elements for subtitles would return this result if there were no video elements on the page.
  • axs.constants.AuditResult.FAIL - This implies that there were elements on the page that did not pass this audit rule. This is the only result you will probably be interested in.

Creating a useful error message

The static, global axs.Audit.createReport(results, opt_url) may be used to create an error message using the return value of axs.Audit.run(). This will look like the following:

*** Begin accessibility audit results ***
An accessibility audit found 4 errors and 4 warnings on this page.
For more information, please see https://github.com/GoogleChrome/accessibility-developer-tools/wiki/Audit-Rules

Error: badAriaAttributeValue (AX_ARIA_04) failed on the following elements (1 - 3 of 3):
DIV:nth-of-type(3) > INPUT
DIV:nth-of-type(5) > INPUT
#aria-invalid

Error: badAriaRole (AX_ARIA_01) failed on the following element:
DIV:nth-of-type(11) > SPAN

Error: controlsWithoutLabel (AX_TEXT_01) failed on the following elements (1 - 3 of 3):
DIV > INPUT
DIV:nth-of-type(12) > DIV:nth-of-type(3) > INPUT
LABEL > INPUT

Error: requiredAriaAttributeMissing (AX_ARIA_03) failed on the following element:
DIV:nth-of-type(13) > DIV:nth-of-type(11) > DIV

Warning: focusableElementNotVisibleAndNotAriaHidden (AX_FOCUS_01) failed on the following element:
#notariahidden

Warning: imagesWithoutAltText (AX_TEXT_02) failed on the following elements (1 - 2 of 2):
#deceptive-img
DIV:nth-of-type(13) > IMG

Warning: lowContrastElements (AX_COLOR_01) failed on the following elements (1 - 2 of 2):
DIV:nth-of-type(13) > DIV
DIV:nth-of-type(13) > DIV:nth-of-type(3)

Warning: nonExistentAriaLabelledbyElement (AX_ARIA_02) failed on the following elements (1 - 2 of 2):
DIV:nth-of-type(3) > INPUT
DIV:nth-of-type(5) > INPUT
*** End accessibility audit results ***

Each rule will have at most five elements listed as failures, in the form of a unique query selector for each element.

Configuring the Audit

If you wish to fine-tune the audit, you can create an axs.AuditConfiguration object, with the following options:

Ignore parts of the page for a particular audit rule

For example, say you have a separate high-contrast version of your page, and there is a CSS rule which causes certain elements (with class pretty) on the page to be low-contrast for stylistic reasons. Running the audit unmodified produces results something like

Warning: lowContrastElements (AX_COLOR_01) failed on the following elements (1 - 5 of 15):
...

You can modify the audit to ignore the elements which are known and intended to have low contrast like this:

var configuration = new axs.AuditConfiguration();
configuration.ignoreSelectors('lowContrastElements', '.pretty');
axs.Audit.run(configuration);

The AuditConfiguration.ignoreSelectors() method takes a rule name, which you can find in the audit report, and a query selector string representing the parts of the page to be ignored for that audit rule. Multiple calls to ignoreSelectors() can be made for each audit rule, if multiple selectors need to be ignored.

Restrict the scope of the entire audit to a subsection of the page

You may have a part of the page which varies while other parts of the page stay constant, like a content area vs. a toolbar. In this case, running the audit on the entire page may give you spurious results in the part of the page which doesn't vary, which may drown out regressions in the main part of the page.

You can set a scope on the AuditConfiguration object like this:

var configuration = new axs.AuditConfiguration();
configuration.scope = document.querySelector('main');  // or however you wish to choose your scope element
axs.Audit.run(configuration);

You may also specify a configuration payload while instantiating the axs.AuditConfiguration, which allows you to provide multiple configuration options at once.

var configuration = new axs.AuditConfiguration({
  auditRulesToRun: ['badAriaRole'],
  scope: document.querySelector('main'),
  maxResults: 5
});

axs.Audit.run(configuration);

License

Copyright 2013 Google Inc. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

changelog

2.11.0 - 2016-09-14

Enhancements

  • Performance enhancements (#263)

2.10.1-rc.0 - 2016-01-13

Bug fixes:

  • Escape special characters to be used in a query selector string (PR #267)
  • Fix exception thrown by RoleTooltipRequiresDescribedBy.js (#269)

2.10.0 - 2015-11-13

2.10.0-rc.1 - 2015-10-19

Bug fixes:

  • linkWithUnclearPurpose should only look at links, not <a> without href. (#245)

2.10.0-rc.0 - 2015-10-09

New rules

  • A tabpanel should be related to a tab via aria-controls or aria-labelledby (src/audits/UncontrolledTabpanel.js)
  • A data table must identify row and column headers (src/audits/TableHasAppropriateHeaders.js)
  • A tooltip element should have an aria-describedby referring to it (src/audits/RoleTooltipRequiresDescribedBy.js).

Enhancements

  • Pull DOM-related functionality out into DOMUtils.js

Bug fixes:

  • Fix findTextAlternatives not always correctly ignoring hidden elements (#217).
  • findTextAlternatives now honors alt attribute of input type image
  • Revert #150 which was causing the extension not to work.
  • AX_HTML_02 (duplicate IDs) now only audits elements that are referenced by an IDREF (#141);
  • Fix #171 by being smarter about finding the composed parent node.
  • Tweak in canScrollTo to handle the (common) case where the container is document.body (#243).

2.9.0 - 2015-09-04

2.9.0-rc.0 - 2015-08-21

New rules

  • A label element may not have labelable descendants other than its labeled control (src/audits/MultipleLabelableElementsPerLabel.js)

Enhancements

  • Implement support for specifying audit configuration options through an object when initializing audits (#165).
  • Implement support for AMD loaders.

Bug fixes:

  • Fix badAriaAttributeValue not correctly handling decimal values (#182).
  • Work around null pointer exception caused by closure compiler issue (#183).
  • Add a special case to handle color "transparent" to fix (#180).
  • Fix matchSelector not working properly in browser environments without vendor prefixes (#189).
  • Fix false positives on elements with no role for Unsupported ARIA Attribute rule (#178 and #199).
  • Fix ARIA tablist and ARIA tab scope (#204)
  • Fix link with clear purpose with text alternative (#156);
  • Handle edge cases in number parser, e.g. "+1", ".1", "01"
  • HTML button containing img with alt attribute now passes controlsWithoutLabel (#202)
  • Disabled elements should be ignored by low contrast audit (#205)
  • Fix input of type "text" did not find correct implied role (#225)
  • Hidden links are no longer relevant for meaningful link text rule.

2.8.0 - 2015-07-24

2.8.0-rc.0 - 2015-07-10

Enhancements:

  • Pull color code into separate file.
  • Improve color suggestion algorithm.
  • Descend into iframes when collecting matching elements.

2.7.1 - 2015-06-30

2.7.1-rc.1 - 2015-06-23

Bug fixes:

  • Check for null textAlternatives in FocusableElementNotVisibleAndNotAriaHidden's relevantElementMatcher method.

2.7.1-rc.0 - 2015-06-15

Enhancements:

  • Rework findTextAlternatives not to return non-exposed text alternatives.
  • Add Bower config (#157)

Bug fixes:

  • Check for any text alternatives when assessing unlabeled images (#154).

2.7.0 - 2015-05-15

New rules

  • This element does not support ARIA roles, states and properties (src/audits/AriaOnReservedElement.js)
  • aria-owns should not be used if ownership is implicit in the DOM (src/audits/AriaOwnsDescendant.js)
  • Elements with ARIA roles must be in the correct scope (src/audits/AriaRoleNotScoped.js)
  • An element's ID must be unique in the DOM (src/audits/DuplicateId.js)
  • The web page should have the content's human language indicated in the markup (src/audits/HumanLangMissing.js)
  • An element's ID must not be present in more that one aria-owns attribute at any time (src/audits/MultipleAriaOwners.js)
  • ARIA attributes which refer to other elements by ID should refer to elements which exist in the DOM (src/audits/NonExistentAriaRelatedElement.js - previously src/audits/NonExistentAriaLabeledBy.js)
  • Elements with ARIA roles must ensure required owned elements are present (src/audits/RequiredOwnedAriaRoleMissing.js)
  • Avoid positive integer values for tabIndex (src/audits/TabIndexGreaterThanZero.js)
  • This element has an unsupported ARIA attribute (src/audits/UnsupportedAriaAttribute.js)

Enhancements:

  • Add configurable blacklist phrases and stop words to LinkWithUnclearPurpose (#99)
  • Detect and warn if we reuse the same code for more than one rule. (#133)
  • Force focus before testing visibility on focusable elements. (#65)
  • Use getDistributedNodes to get nodes distributed into shadowRoots (#128)
  • Add section to Audit Rules page for HumanLangMissing and link to it from rule (#119)
  • Reference "applied role" in axs.utils.getRoles enhancement (#130)
  • Add warning that AX_FOCUS_02 is not available from axs.Audit.run() (#85)

Bug fixes:

  • Incorrect use of nth-of-type against className in utils.getQuerySelectorText (#87)
  • AX_TEXT_01 Accessibility Audit test should probably ignore role=presentation elements (#97)
  • Fix path to audit rules in phantomjs runner (#108)
  • Label audit should fail if form fields lack a label, even with placeholder text (#81)
  • False positives for controls without labels with role=presentation (#23)
  • Fix "valid" flag on return value of axs.utils.getRoles (#131)

Note: this version number is somewhat arbitrary - just bringing it vaguely in line with the extension since that's where the library originated - but will use semver for version bumps going forward from here.

0.0.5 - 2014-02-04

Enhancements:

  • overlapping elements detection code made more sophisticated
  • axs.properties.getFocusProperties() returns more information about visibility
  • new axs.properties.hasDirectTextDescendant() method with more sophisticated detection of text content

Bug fixes:

  • FocusableElementNotVisibleAndNotAriaHidden audit passes on elements which are brought onscreen on focus
  • UnfocusableElementsWithOnclick checks for element.disabled
  • Fix infinite loop when getting descendant text content of a label containing an input
  • Detect elements which are out of scroll area of any parent element, not just the document scroll area
  • findTextAlternatives doesn't throw TypeError if used on a HTMLSelectElement

0.0.4 - 2013-10-03

Enhancements:

  • axs.AuditRule.run() has a new signature: it now takes an options object. Please see method documentation for details.
  • Audit Rule severity can be overridden (per Audit Rule) in AuditConfig.

Bug fixes:

  • axs.utils.isLowContrast() now rounds to the nearest 0.1 before checking (so #777 is now a passing value)
  • MainRoleOnInappropriateElement was always failing due to accessible name calculation taking the main role into account and not descending into content (now just gets descendant content directly)
  • UnfocusableElementsWithOnClick had a dangling if-statement causing very noisy false positives