Nella radice della cartella di test, installa il pacchetto @axe-core/watcher e tutte le sue dipendenze utilizzando npm o il tuo gestore di pacchetti preferito (ad esempio, Yarn o pnpm).
npm install --save-dev @axe-core/watcher
In cypress.config.js, importa la funzione cypressConfig dal pacchetto @axe-core/watcher e incapsula la tua configurazione con essa:
const { defineConfig } = require('cypress');
const { cypressConfig } = require('@axe-core/watcher');
const API_KEY = process.env.API_KEY
module.exports = defineConfig(
cypressConfig({
axe: {
apiKey: API_KEY
},
// Your existing Cypress configuration code here
})
);
Nel file di supporto Cypress (comunemente denominato cypress/support/e2e.js), importa i comandi Cypress del pacchetto @axe-core/watcher e chiama axeWatcherFlush() dopo ogni test:
require('@axe-core/watcher/dist/cypressCommands');
afterEach(() => {
cy.axeWatcherFlush();
});
Hai terminato. Esegui i test end-to-end e controlla i risultati. Si prega di notare che @axe-core/watcher funziona solo con Chrome e dovrebbe essere utilizzato solo in modalità di esecuzione Cypress. Può essere utilizzato con --headless=nuovo o --headed (ad esempio, cypress run --headed --browser=chrome
).