Cypressと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

CypressとTypeScriptでテストを設定する

Not for use with personal data
  1. テストフォルダーのルートレベルで、@axe-core/watcherパッケージとそのすべての依存関係をnpmまたはお好みのパッケージマネージャー(例えば、yarnあるいはpnpm)を使用してインストールします。

    npm install --save-dev @axe-core/watcher
  2. で、 cypress.config.ts、 をインポートし、 cypressConfig() 関数を @axe-core/watcher パッケージからインポートして、設定をそれでラップします:

    import { defineConfig } from 'cypress';
    import { cypressConfig } from '@axe-core/watcher/cypress/config';
    
    const ACCESSIBILITY_API_KEY = process.env.ACCESSIBILITY_API_KEY
    const PROJECT_ID = process.env.PROJECT_ID
    
    export default defineConfig(
      cypressConfig({
        axe: {
          apiKey: ACCESSIBILITY_API_KEY,
          projectId: PROJECT_ID
        },
        // Your existing Cypress configuration code here
      })
    );

    必ず、ACCESSIBILITY_API_KEYPROJECT_IDを環境に設定し、あなたの個人用APIキー(AxeアカウントのAPI KEYSタブにあります)とプロジェクトID(プロジェクト作成時のこの手順の上部に表示されるか、プロジェクトページで設定の下にあるプロジェクトを設定を選択することで確認可能です)を使用してください。

  3. Cypressのサポートファイル(通常は cypress/support/e2e.tsと呼ばれます)で、 を @axe-core-watcher/cypress/support インポートし、各テストの後に axeWatcherFlush() を呼び出します:

    import '@axe-core/watcher/cypress/support';
    
    afterEach(() => {
      cy.axeWatcherFlush();
    });
  4. これで完了です。エンドツーエンドテストを実行し、結果を確認してください。なお、 @axe-core/watcher はテスト用のChromeまたはChromiumでのみ実行され、Cypress 実行 モードでのみ使用するべきです。 --headless=new--headed (例えば、 cypress run --headed --browser=chrome-for-testing)と併用されることができます。