Berichte mit Cypress generieren
Integration des @axe-devtools/reporter-Pakets mit @axe-devtools/cypress zur Erstellung von Berichten
So nutzen Sie @axe-devtools/reporter mit @axe-devtools/cypress
Voraussetzungen
Um den Axe DevTools Reporter verwenden zu können, müssen Sie ihn zuerst in Ihrem Projekt installieren.
npm install @axe-devtools/reporterDiese Anweisungen gelten für Cypress 10.0 und höher.
Einrichtung
Die folgende Einrichtung ist erforderlich, da Cypress sowohl den Browser- als auch den Node-Kontext hat und da @axe-devtools/reporter ein Node-Modul ist, muss es im Node-Kontext instanziiert werden, welcher nur verfügbar ist innerhalb von cy.task
Fügen Sie Folgendes in cypress/support/e2e.js:
import '@axe-devtools/cypress';
after(() => {
cy.getAxeResults().then(async results => {
const resultsDir = './results/'
// Use Cypress.spec.name for a unique filename per spec file to avoid overwriting results
await cy.writeFile(`${resultsDir}${Cypress.spec.name}.json`, results)
// reportName labels the results and is used as the prefix in the generated report filenames
await cy.task('reportAsHTML', { resultsDir, reportName: 'axeDevToolsCypress' })
})
})Innerhalb der cypress.config.js -Datei die Reporter-Aufgaben hinzufügen in setupNodeEvents:
const { defineConfig } = require('cypress');
const axeDevToolsPlugin = require('@axe-devtools/cypress/dist/plugin');
const { Reporter } = require('@axe-devtools/reporter');
module.exports = defineConfig({
e2e: {
setupNodeEvents(on, config) {
axeDevToolsPlugin(on);
on('task', {
// Reads all .json result files in resultsDir and generates an HTML report;
// reportName labels the results and is used as the prefix in the generated HTML filenames
reportAsHTML: async ({ resultsDir, reportName = 'axeDevToolsCypress' }) => {
const reporter = new Reporter(reportName, resultsDir);
await reporter.buildHTML(resultsDir);
return null;
},
// Reads all .json result files in resultsDir and generates a CSV report
reportAsCSV: async ({ resultsDir, reportName = 'axeDevToolsCypress' }) => {
const reporter = new Reporter(reportName, resultsDir);
await reporter.buildCSV(resultsDir);
return null;
},
// Reads all .json result files in resultsDir and generates a JUnit XML report
reportAsJunit: async ({ resultsDir, reportName = 'axeDevToolsCypress' }) => {
const reporter = new Reporter(reportName, resultsDir);
await reporter.buildJUnitXML(resultsDir);
return null;
}
});
return config;
}
}
});Fügen Sie Folgendes in cypress/e2e/test.cy.js:
describe('Axe DevTools Cypress', () => {
it('Scans the page for accessibility issues', () => {
// Visit the page to test
cy.visit('https://broken-workshop.dequelabs.com')
// Run an accessibility scan; results are collected and written to a file by the after() hook in support/e2e.js
cy.axeAnalyze()
})
})Siehe auch
– Hochladen von JSON-Zugänglichkeitsergebnissen in axe Reports beschreibt, wie Sie Ihre Ergebnisse in axe Reports hochladen.
- Erhalten eines API-Schlüssels für axe Reports erklärt, wie Sie einen API-Schlüssel erhalten, um mit der Verwendung von axe Reports zu beginnen.
– Berichte erstellen und filtern zeigt, wie Sie aus Ihren JSON-Zugänglichkeitsergebnissen Zugänglichkeitsberichte im CSV-, XML- oder HTML-Format erstellen können. Mit diesem Tool können Sie Ihre Ausgabe auch nach Schweregrad filtern. – So werden JSON-Ergebnisse auf der Festplatte gespeichert beschreibt die Dateibenennungskonventionen für JSON-Zugänglichkeitsergebnisse.
