Accessibility Testing with aXe!



Accessibility Testing with aXe!

0 0


a11y-testing-with-axe

Slides for my talks on Accessibility testing with aXe-core

On Github marcysutton / a11y-testing-with-axe

Accessibility Testing with aXe!

By Marcy Sutton / @MarcySutton Senior Front-End Engineer, Deque Systems

Test automation

Prevents broken code from going to production

Accessibility

means EVERYONE can use the Web

Rio 2016: We're the Superhumans

People with Disabilities

  • Visual: Blind, low-vision, color blind
  • Hearing: Deaf, hard-of-hearing
  • Motor: spinal cord injury, MS, Cerebral palsy, ALS
  • Cognitive: Autism, learning, TBI, memory, attention

Accessibility & Automated Testing sitting in a tree...

  • Test low-hanging fruit
  • Document accessibility intent
  • Prevent regressions
  • Get help from experts
NOT a substitute for actual user testing

WCAG & Section 508

Guidelines and rules for creating accessible websites

WCAG = guidelines Section 508 = required for gov't agencies

The A11Y Testing Situation

We can automate testing in browsers, but not assistive technologies (yet).

Best practices and development tools help here.

Test low-hanging fruit

Easy wins

Use tools to help you find:

  • Lacking keyboard support
  • Missing labels
  • Invalid ARIA attributes
  • Color contrast
  • …and more!

What is axe-core?

  • JavaScript library for accessibility testing
  • Engine powering browser extensions, test integrations
  • A handy unit testing tool
  • Open source*

Document accessibility intent~and~ prevent regressionswith test coverage

Tools for the job

axe-core API (2.0.5)

  • axe.a11yCheck(context, options, callback)
  • axe.getRules(['wcag2a', 'section508'...])
  • axe.configure(options)
  • axe.reset()
  • axe.registerPlugin(plugin)
  • axe.cleanup()

https://github.com/dequelabs/axe-core/blob/master/doc/API.md

axe.a11yCheck

  // Test an element reference, selector, or include/exclude object.
  var context = { exclude: ['#some-id'] };
  var config = {
    rules: {
        "color-contrast": { enabled: false },
        "valid-lang": { enabled: false }
    }
  };

  axe.a11yCheck(context, config, function(results) {
    // do stuff with the results
  });
			        

https://github.com/dequelabs/axe-core/blob/master/doc/API.md#a11ycheck-parameters

Unit testing with axe-core

Install from npm:

  npm install axe-core --save-dev
				        

Include script and run tests:

  var axe = require('axe-core');

  describe('Custom component', function() {
    it('should have no a11y violations', function(done) {
      axe.a11yCheck('.some-element-selector', {}, function (results) {
        expect(result.violations.length).toBe(0);
        done();
      });
    });
  });
					

What is axe-webdriverjs?

An open source library that injects axe-coreinto Selenium Webdriver instances

Integration testing with axe-webdriverjs

  npm install axe-webdriverjs --save-dev
			        
  var AxeBuilder = require('axe-webdriverjs'),
      WebDriver = require('selenium-webdriver');
 
  var driver = new WebDriver.Builder()
    .forBrowser('firefox')
    .build();
 
  driver
    .get('https://localhost:4000')
    .then(function (done) {
      AxeBuilder(driver)
        .analyze(function (results) {
          expect(results.violations.length).toBe(0);
          done();
        });
    });
						

Get help from experts

The aXe Team (besides yours truly)

Accessibility Testing with aXe! By Marcy Sutton / @MarcySutton Senior Front-End Engineer, Deque Systems