Istruzioni per Cypress 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 Cypress e TypeScript

Free Trial
Not for use with personal data
  1. 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
  2. In cypress.config.ts, importa la funzione cypressConfig dal pacchetto @axe-core/watcher e avvolgi la tua configurazione con essa:

    import { defineConfig } from 'cypress';
    import { cypressConfig } from '@axe-core/watcher';
    
    const API_KEY = process.env.API_KEY
    
    export default defineConfig(
      cypressConfig({
        axe: {
          apiKey: API_KEY
        },
        // Your existing Cypress configuration code here
      })
    );
  3. Nel file di supporto Cypress (comunemente denominato cypress/support/e2e.ts), importa il pacchetto @axe-core/watcher cypressCommands **e chiama ** axeWatcherFlush () dopo ogni test:

    import '@axe-core/watcher/dist/cypressCommands';
    
    afterEach(() => {
      cy.axeWatcherFlush();
    });
  4. Hai terminato. Esegui i test end-to-end e controlla i risultati. Si prega di notare che @axe-core/watcher funziona solo su Chrome e dovrebbe essere utilizzato solo in modalità di esecuzione Cypress. Può essere utilizzato con --headless=new o --headed (ad esempio, cypress run --headed --browser=chrome).