mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
c5fb94f2a4
* 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.
49 lines
1.2 KiB
JavaScript
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;
|