Generazione di report con Cypress

This page is not available in the language you requested. You have been redirected to the English version of the page.
Link to this page copied to clipboard
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