Files
angular__angular/tools/axe-protractor/axe-protractor.js
T
Paul Gschwendtner c5fb94f2a4 chore: run a11y audits on protractor (#2010)
* chore: run a11y audits on protractor

* Fixes accessibility issue in grid-list with `role="listitem"`
* Adds protractor plugin to run aXe-core accessibility audits
* Fixes a bunch of a11y issues in the e2e app to make the aXe audits green

* Force menu y-positions because viewport might be different on Selenium browsers.

* Navigiation links should be hidden by default because those can interfere with the tests.
2016-12-13 12:10:31 -08:00

49 lines
1.2 KiB
JavaScript

'use strict';
/**
* Protractor Plugin to run axe-core accessibility audits after Angular bootstrapped.
*/
const AxeBuilder = require('axe-webdriverjs');
const {buildMessage} = require('./build-message');
/* List of pages which were already checked by axe-core and shouldn't run again */
const checkedPages = [];
/**
* Protractor plugin hook which always runs when Angular successfully bootstrapped.
*/
function onPageStable() {
AxeBuilder(browser.driver)
.configure(this.config || {})
.analyze(results => handleResults(this, results));
}
/**
* Processes the axe-core results by reporting recognized violations
* to Protractor and printing them out.
* @param {!protractor.ProtractorPlugin} context
* @param {!axe.AxeResults} results
*/
function handleResults(context, results) {
if (checkedPages.indexOf(results.url) === -1) {
checkedPages.push(results.url);
results.violations.forEach(violation => {
let specName = `${violation.help} (${results.url})`;
let message = '\n' + buildMessage(violation);
context.addFailure(message, {specName});
});
}
}
exports.name = 'protractor-axe';
exports.onPageStable = onPageStable;