Installeer in de hoofdmap van je testmap het @axe-core/watcher-pakket en al zijn afhankelijkheden met npm of je voorkeurspakketbeheerder (bijvoorbeeld yarn of pnpm).
npm install --save-dev @axe-core/watcherImporteer in cypress.config.js de cypressConfig() functie uit het @axe-core/watcher pakket en omhul uw configuratie hiermee. Stel de testingTypes array in om component te bevatten:
const { defineConfig } = require('cypress');
const { cypressConfig } = require('@axe-core/watcher/cypress/config');
const ACCESSIBILITY_API_KEY = process.env.ACCESSIBILITY_API_KEY
const PROJECT_ID = process.env.PROJECT_ID
const SERVER_URL = process.env.SERVER_URL
module.exports = defineConfig(
cypressConfig({
axe: {
apiKey: ACCESSIBILITY_API_KEY,
projectId: PROJECT_ID,
serverURL: SERVER_URL,
testingTypes: ['component']
},
// Your existing Cypress configuration code here
component: {
// Your component testing configuration
// For example:
// devServer: {
// framework: 'react',
// bundler: 'webpack',
//},
},
})
);Zorg ervoor dat je ACCESSIBILITY_API_KEY en PROJECT_ID in je omgeving instelt op je persoonlijke API-sleutel (te vinden in je Axe-account, tabblad **API-SLEUTELS**) en je project-ID (weergegeven bovenaan deze instructies toen je je project maakte of beschikbaar van de Projecten-pagina door **Project configureren** te kiezen onder **Instellingen**). Als je organisatie een regionale, private cloud of on-premises Axe Developer Hub-instantie gebruikt, stel dan ook SERVER_URL in op de basis-URL van die instantie (bijvoorbeeld, https://axe-eu.deque.com); zo niet, laat dan SERVER_URL weg en zal de standaard https://axe.deque.com gebruikt worden.
Importeer in uw Cypress-componentondersteuningsbestand (meestal genoemd cypress/support/component.js) het @axe-core/watcher pakket cypressCommands en roep axeWatcherFlush() na elke test aan:
require('@axe-core/watcher/cypress/support');
afterEach(() => {
cy.axeWatcherFlush();
});U bent klaar. Voer uw componenttests uit en controleer uw resultaten. Houd er rekening mee dat @axe-core/watcher alleen in Chrome voor Testing of Chromium werkt en alleen in de Cypress run-modus moet worden gebruikt. Het kan worden gebruikt met --headless=new of --headed (bijvoorbeeld, cypress run --headed --browser=chrome-for-testing --component).