What is axe-html-reporter?
The axe-html-reporter npm package is used to generate HTML reports from accessibility test results produced by the axe-core library. It helps in visualizing the accessibility issues found during testing in a user-friendly HTML format.
What are axe-html-reporter's main functionalities?
Generate HTML Report
This feature allows you to generate an HTML report from the results of an accessibility test run using axe-core. The `createHtmlReport` function takes the results object and options for the output directory and report file name, and generates an HTML file.
const { createHtmlReport } = require('axe-html-reporter');
const fs = require('fs');
const results = { /* axe-core results object */ };
createHtmlReport({
results,
options: {
outputDir: 'reports',
reportFileName: 'accessibility-report.html'
}
}).then(() => {
console.log('Report generated successfully');
}).catch(err => {
console.error('Error generating report:', err);
});
Other packages similar to axe-html-reporter
pa11y-reporter-html
The pa11y-reporter-html package is used to generate HTML reports from Pa11y accessibility test results. It is similar to axe-html-reporter in that it provides a way to visualize accessibility issues in an HTML format. However, it is specifically designed to work with Pa11y, another popular accessibility testing tool.
html-reporter
The html-reporter package is a generic tool for generating HTML reports from various types of test results, not limited to accessibility testing. It provides a flexible way to create custom HTML reports, but may require more configuration compared to axe-html-reporter, which is specifically tailored for axe-core results.
axe-html-reporter
Creates an HTML report from Axe-coreĀ® library AxeResults object listing violations, passes, incomplete and incompatible results.
Allows specifying report creation options: reportFileName
, outputDir
, outputDirPath
, projectKey
and customSummary
.
Notes:
customSummary
allows having html parameters
outputDirPath
allows specifying absolute path
Please check sample report output.
createHtmlReport
returns HTML content that can be additionally used for specific integrations.
If only HTML content needed, user can pass doNotCreateReportFile: true
to stop report file creation.
Suggestion on how to use this library if you don't need a report file but need only HTML it produces:
const reportHTML = createHtmlReport({
results: rawAxeResults,
options: {
projectKey: 'I need only raw HTML',
doNotCreateReportFile: true,
},
});
console.log('reportHTML will have full content of HTML file.');
if (!fs.existsSync('build/reports/saveReportHere.html')) {
fs.mkdirSync('build/reports', {
recursive: true,
});
}
fs.writeFileSync('build/reports/saveReportHere.html', reportHTML);
Install
npm i -D 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. If fileName
is not passed, HTML report will be created with default name accessibilityReport.html
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-coreĀ®').page('http://example.com');
test('Automated accessibility testing', async (t) => {
const axeContext = { exclude: [['select']] };
const axeOptions = {
rules: {
'object-alt': { enabled: true },
'role-img-alt': { enabled: true },
'input-image-alt': { enabled: true },
'image-alt': { enabled: true },
},
};
const { error, results } = await runAxe(axeContext, axeOptions);
await t.expect(error).notOk(`axe check failed with an error: ${error.message}`);
createHtmlReport({
results,
options: {
projectKey: 'EXAMPLE',
},
});
});
Run TestCafe test:
npx testcafe
Running tests in:
- Chrome 85.0.4183.121 / Linux
TestCafe tests with Axe-coreĀ®
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 { createHtmlReport } from 'axe-html-reporter';
(() => {
createHtmlReport({ results: 'AxeCoreResults' });
createHtmlReport({ results: { violations: 'Result[]' } });
createHtmlReport({
results: 'AxeCoreResults',
options: { projectKey: 'JIRA_PROJECT_KEY' },
});
createHtmlReport({
results: 'AxeCoreResults',
options: {
projectKey: 'JIRA_PROJECT_KEY',
outputDir: 'axe-core-reports',
reportFileName: 'exampleReport.html',
},
});
const customSummary = `Test Case: Full page analysis
<br>Steps:</br>
<ol style="margin: 0">
<li>Open https://dequeuniversity.com/demo/mars/</li>
<li>Analyze full page with all rules enabled</li>
</ol>`;
createHtmlReport({
results: 'AxeResults',
options: {
projectKey: 'DEQUE',
customSummary,
outputDir: 'docs',
reportFileName: 'index.html',
},
});
})();
CommonJS
const { createHtmlReport } = require('axe-html-reporter');
(() => {
createHtmlReport({ results: { violations: 'Result[]' } });
})();