Generazione di report con Cypress
Not for use with personal data
Come utilizzare @axe-devtools/reporter
con @axe-devtools/cypress
Prerequisiti
Per poter utilizzare il reporter axe DevTools, è necessario prima installarlo nel progetto.
npm install @axe-devtools/reporter
Configurazione
La seguente configurazione è richiesta perché Cypress ha sia il contesto del browser che il contesto del nodo e poiché @axe-devtools/reporter
è un modulo nodo deve essere istanziato nel contesto del nodo, che è disponibile solo quando racchiuso all'interno cy.task
Includi la seguente riga in cypress/support/index.js
import '@axe-devtools/cypress';
after(() => {
cy.getAxeResults().then(async results => {
// create the directory with results
const resultsDir = './results/'
await cy.writeFile(`${resultsDir}results.json`, results)
await cy.task('reportAsHTML', { resultsDir })
})
})
Includi la seguente riga in cypress/plugins/index.js
const axeDevToolsPlugin = require('@axe-devtools/cypress/dist/plugin');
const Reporter = require('@axe-devtools/reporter').default
module.exports = (on, config) => {
axeDevToolsPlugin(on)
on('task', {
// task to create HTML report
reportAsHTML: async ({ resultsDir, branding = 'axeDevToolsCypress' }) => {
reporter = new Reporter(branding, resultsDir)
await reporter.buildHTML(resultsDir);
return null
},
// task to create CSV report
reportAsCSV: async ({ resultsDir, branding = 'axeDevToolsCypress' }) => {
reporter = new Reporter(branding, resultsDir)
await reporter.buildCSV(resultsDir);
return null
},
// task to create Junit XML report
reportAsJunit: async ({ resultsDir, branding = 'axeDevToolsCypress' }) => {
reporter = new Reporter(branding, resultsDir)
await reporter.buildJUnitXML(resultsDir);
return null
}
})
}
Includi la seguente riga in cypress/integration/test.spec.js
describe('Axe DevTools Cypress', () => {
it('Get results from analyzing', () => {
cy.visit('https://broken-workshop.dequelabs.com')
cy.axeAnalyze()
})
})
Vedere anche
- Caricamento dei risultati di accessibilità JSON su axe Reports descrive come caricare i risultati su axe Reports.
- Ottenere una chiave API per axe Reports spiega come ottenere una chiave API per iniziare a utilizzare axe Reports.
- Creazione e filtraggio di report mostra come creare report di accessibilità in formato CSV, XML o HTML a partire dai risultati di accessibilità JSON. Utilizzando questo strumento puoi anche filtrare l'output in base alla gravità.
- Come vengono archiviati i risultati JSON su disco descrive le convenzioni di denominazione dei file per i risultati di accessibilità JSON.