axe-html-reporter
Creates an HTML report from axe results object with list of violations, passes and incomplete results.
Allows specifying url
, projectKey
and outputDir
.
See sample report output
Install
npm i axe-html-reporter
Usage
Example usage in TestCafe
To run TestCafe tests with axe-core, install testcafe, axe-core and @testcafe-community/axe:
npm i -D axe-html-reporter testcafe axe-core @testcafe-community/axe
For TestCafe example add the following clientScript in your .testcaferc.json
config:
{
"clientScripts":[{"module":"axe-core/axe.min.js"}]
}
In the example bellow fileName
is not passed. In this case html report with default name accessibilityReport.html
will be created in artifacts
directory.
See full TestCafe test example is bellow:
import { runAxe } from '@testcafe-community/axe';
import { createHtmlReport } from 'axe-html-reporter';
fixture('TestCafe tests with Axe').page('http://example.com');
test('Automated accessibility testing', async (t) => {
const axeContext = { exclude: [['select']] };
const axeOptions = { rules: rulesMap() };
const { error, results } = await runAxe(axeContext, axeOptions);
await t.expect(error).eql(null, `axe check failed with an error: ${error.message}`);
createHtmlReport({
violations: results.violations,
passes: results.passes,
incomplete: results.incomplete,
url: results.url,
projectKey: 'EXAMPLE',
});
});
Run TestCafe test:
npx testcafe
Running tests in:
- Chrome 85.0.4183.121 / Linux
TestCafe tests with Axe
HTML report was saved into the following directory /Users/axe-demos/artifacts/accessibilityReport.html
✓ Automated accessibility testing
1 passed (1s)
Example usage in any JS framework
import { axeHtmlReporter } from 'axe-html-reporter';
(() => {
const results = { violations: {}, passes: {}, incomplete: {}, inapplicable: {}, url: 'http://example.com' };
axeHtmlReporter({
violations: results.violations,
passes: results.passes,
incomplete: results.incomplete,
});
axeHtmlReporter({
violations: results.violations,
passes: results.passes,
incomplete: results.incomplete,
projectKey: 'JIRA_PROJECT_KEY',
url: results.url,
});
axeHtmlReporter({
violations: results.violations,
passes: results.passes,
incomplete: results.incomplete,
projectKey: 'JIRA_PROJECT_KEY',
outputDir: 'axe-reports',
url: results.url,
fileName: 'exampleReport.html',
});
})();
CommonJS
const { axeHtmlReporter } = require('axe-html-reporter');
(() => {
axeHtmlReporter({ violations: results.violations });
})();