JavaとSeleniumの手順

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

JavaとSeleniumでテストを設定する

Not for use with personal data
  1. Java Watcherパッケージの新しい依存関係を pom.xml (Maven用) 依存関係セクションに追加してください (Java WatcherパッケージはMaven Centralで利用可能です):

    <dependencies>
    
    <!-- Add this dependency: -->
      <dependency>
         <groupId>com.deque.axe_core</groupId>
         <artifactId>watcher</artifactId>
         <version>4.0.0</version> <!-- Update this as needed -->
      </dependency>
    
    </dependencies>
  2. テストコードにJava Watcherのインポートを追加してください:

    import com.deque.axe_core.commons.AxeWatcherOptions;
    import com.deque.axe_core.selenium.AxeWatcher;
    import com.deque.axe_core.selenium.AxeWatcherDriver;
  3. Java Watcherのセットアップコードを追加し、個人のAPIキーとプロジェクトIDを含めてください (どちらもセキュリティと柔軟性のために環境に保存します):

    AxeWatcherOptions options =
        new AxeWatcherOptions()
            .setApiKey(System.getenv("ACCESSIBILITY_API_KEY"))
            .setProjectId(System.getenv("PROJECT_ID"));
    AxeWatcher watcher = new AxeWatcher(options);
    ChromeOptions chromeOptions = new ChromeOptions();
    chromeOptions = watcher.configure(chromeOptions);
    WebDriver wrappedDriver = watcher.wrapDriver(new ChromeDriver(chromeOptions));

    このコードスニペットは新しい WebDriver インスタンスを作成し、 wrappedDriver アックスコントローラーメソッドを使用するためにキャストする必要があります。

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

  4. テストセッションの最後に、 flush()を呼び出してください:

    ((AxeWatcherDriver) wrappedDriver).axeWatcher().flush();

    を呼び出すと、 flush() テスト実行が終了し、結果が処理されユーザーに提示されることを示します。