Istruzioni per Playwright Test e TypeScript

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

Configurazione dei test con Playwright Test e TypeScript

Not for use with personal data
  1. 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/watcher
  2. Crea 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 (che si trova nel tuo account Axe, scheda **API KEYS**) e l'ID del tuo progetto (mostrato nella parte superiore di queste istruzioni quando hai creato il tuo progetto o disponibile nella pagina Progetti scegliendo **Configura progetto** sotto **Impostazioni**). Se la tua organizzazione utilizza un'istanza regionale, cloud privato o on-premise di Axe Developer Hub, imposta anche SERVER_URL sull'URL di base di tale istanza (per esempio, https://axe-eu.deque.com); altrimenti, ometti SERVER_URL e verrà utilizzato il https://axe.deque.com predefinito.

  3. 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';
  4. Hai fatto tutto.