Nella cartella principale del tuo ambiente 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/watcherCrea un file fixtures.ts accanto ai tuoi test esistenti di Playwright Test. In questo file, importa la funzione playwrightTest() da @axe-core/watcher:
import { playwrightTest } from '@axe-core/watcher/playwright-test'
const ACCESSIBILITY_API_KEY = process.env.ACCESSIBILITY_API_KEY
const PROJECT_ID = process.env.PROJECT_ID
const SERVER_URL = process.env.SERVER_URL
const { test, expect } = playwrightTest({
axe: {
apiKey: ACCESSIBILITY_API_KEY,
projectId: PROJECT_ID,
serverURL: SERVER_URL
},
headless: false
// Any other Playwright configuration you’d pass to chromium.launchPersistentContext() here
})
export { test, expect }Assicurati di impostare ACCESSIBILITY_API_KEY e PROJECT_ID nel tuo ambiente con la tua chiave API personale (trovata nel tuo account axe, nella scheda **API KEYS**) e con il tuo ID progetto (mostrato in cima a queste istruzioni quando hai creato il tuo progetto o disponibile nella pagina Progetti selezionando **Configura progetto** sotto **Impostazioni**). Se la tua organizzazione utilizza una versione regionale, cloud privata o un'istanza Axe Developer Hub on-premises, imposta anche SERVER_URL all'URL base di quella istanza (ad esempio, https://axe-eu.deque.com); altrimenti, ometti SERVER_URL e verrà utilizzato il valore predefinito https://axe.deque.com.
Nei tuoi file di test, sostituisci gli import di test e expect da Playwright Test con il tuo file fixtures.ts:
import { test, expect } from '@playwright/test'
// Becomes:
import { test, expect } from './fixtures';Hai fatto tutto.