Instruções para 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

Configurando seus testes com Playwright Test e TypeScript

Not for use with personal data
  1. No nível raiz da sua pasta de testes, instale o pacote @axe-core/watcher e todas as suas dependências usando o npm ou seu gerenciador de pacotes preferido (por exemplo, yarn ou pnpm).

    npm install --save-dev @axe-core/watcher
  2. Crie um arquivo fixtures.ts junto aos seus testes existentes do Playwright Test. Nesse arquivo, importe a função playwrightTest() de @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 }

    Certifique-se de definir ACCESSIBILITY_API_KEY e PROJECT_ID no seu ambiente para a sua chave API pessoal (encontrada na sua conta axe, aba **API KEYS**) e para o ID do seu projeto (mostrado na parte superior destas instruções quando você criou o seu projeto ou disponível na página Projetos ao escolher **Configurar projeto** em **Configurações**). Se a sua organização usa uma instância regional, em nuvem privada ou local do Axe Developer Hub, também defina SERVER_URL para a URL base dessa instância (por exemplo, https://axe-eu.deque.com); caso contrário, omita SERVER_URL e o padrão https://axe.deque.com será utilizado.

  3. Nos seus arquivos de teste, substitua as importações de test e expect do Playwright Test pelo seu arquivo fixtures.ts:

    import { test, expect } from '@playwright/test'
    
    // Becomes:
    import { test, expect } from './fixtures';
  4. Você já fez tudo.