Git Product home page Git Product logo

axe-html-reporter's Introduction

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.');
// suggestion on how to create file by yourself
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').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}`);
    // creates html report with the default file name `accessibilityReport.html`
    createHtmlReport({
        results,
        options: {
            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 { createHtmlReport } from 'axe-html-reporter';

(() => {
    // creates html report with the default name `accessibilityReport.html` file
    createHtmlReport({ results: 'AxeResults' }); // full AxeResults object
    // creates html report with the default name `accessibilityReport.html` file and all supported AxeResults values
    createHtmlReport({ results: { violations: 'Result[]' } }); // passing only violations from axe.run output
    // creates html report with the default name `accessibilityReport.html` file and adds url and projectKey
    createHtmlReport({
        results: 'AxeResults',
        options: { projectKey: 'JIRA_PROJECT_KEY' },
    });
    // creates html report with the name `exampleReport.html` in 'axe-reports' directory and adds projectKey to the header
    createHtmlReport({
        results: 'AxeResults',
        options: {
            projectKey: 'JIRA_PROJECT_KEY',
            outputDir: 'axe-reports',
            reportFileName: 'exampleReport.html',
        },
    });
    // creates html report with all optional parameters, saving the report into 'docs' directory with report file name 'index.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');

(() => {
    // creates html report with the name `accessibilityReport.html` file
    createHtmlReport({ results: { violations: 'Result[]' } });
})();

axe-html-reporter's People

Contributors

aermakova avatar lpelypenko avatar mskelton avatar vkyt avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.