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"));
    // Optional: uncomment and set SERVER_URL if using a regional, private cloud, or on-premises instance:
    // options.setServerUrl(System.getenv("SERVER_URL"));
    AxeWatcher watcher = new AxeWatcher(options);
    ChromeOptions chromeOptions = new ChromeOptions();
    chromeOptions = watcher.configure(chromeOptions);
    WebDriver wrappedDriver = watcher.wrapDriver(new ChromeDriver(chromeOptions));

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

    ACCESSIBILITY_API_KEYPROJECT_ID を環境に設定し、個人用 API キー(Axe アカウントの**API KEYS**タブで見つかります)とプロジェクト ID(プロジェクトを作成した際にこれらの指示の上部に表示されるか、プロジェクトページで**プロジェクトを設定**を選択して**設定**から入手できます)を使用してください。組織が地域のプライベートクラウドやオンプレミスの Axe Developer Hub インスタンスを使用している場合は、そのインスタンスのベース URL をSERVER_URLに設定してください(例: https://axe-eu.deque.com)。それ以外の場合、SERVER_URLを省略し、デフォルトのhttps://axe.deque.comが使用されます。

  4. テストセッションの終わりにflush()を呼び出します:

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

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