AxeWatcherクラス

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

axeのアクセシビリティテストをSelenium Javaテストスイートに統合するためのメインクラス(Playwrightを使用する場合はAxeWatcherPlaywrightを使用)

Not for use with personal data

AxeWatcherクラスは、Axe Watcher Selenium Java統合の中核コンポーネントであり、既存のエンドツーエンドテストスイートに簡単にアクセシビリティテストを追加することができます。このクラスは、ブラウザオプションを設定し、自動テスト中にアクセシビリティ分析を可能にするためにWebDriverインスタンスをラップするメソッドを提供します。

configure()wrapDriver() は、それぞれのブラウザごとにオーバーロードを提供します。Chrome for Testing または Chromium でテストするには ChromeOptionsChromeDriver を、Microsoft Edge でテストするには EdgeOptionsEdgeDriver を渡します。Microsoft Edge では Watcher 4.5.1 以降および Selenium 4 以降が必要です。

テストフレームワークに統合されると、Axe Watcherは次のことを行います。

  • テストが実行されるときに、ウェブページのアクセシビリティ問題を自動で分析します
  • DOMの変更が検出されると再分析を行います
  • Gitコミットをアクセシビリティ結果にリンクします
  • アクセシビリティの結果をAxe Developer Hubに送信して、追跡と分析を行います

コンストラクタ

AxeWatcher(AxeWatcherOptions options)

指定されたオプションで新しいAxeWatcherインスタンスを作成します。

パラメータ:

  • options - Axe Watcherの設定オプション

例:

AxeWatcherOptions options = new AxeWatcherOptions()
    .setApiKey("your-api-key-here")
    .setProjectId("your-project-ID-here")
    .setServerUrl("https://axe.deque.com");

AxeWatcher watcher = new AxeWatcher(options);

メソッド

configure(ChromeOptions chromeOptions)

ChromeOptionsを設定して、Axe Watcherによるアクセシビリティテストを有効にします。

important

このメソッドは、ChromeDriverインスタンスを作成する前に呼び出す必要があります。

パラメータ:

  • chromeOptions - 設定する既存のChromeOptionsインスタンス

戻り値:

  • Axe Watcherの設定が適用された新しいChromeOptionsインスタンス

例外:

  • IllegalArgumentException - ヘッドレスまたはシークレットモードが有効な場合(Axe Watcherはこれらのモードをサポートしていません)

例:

AxeWatcherOptions options = new AxeWatcherOptions();
options.setApiKey("your-api-key-here");
options.setProjectId("your-project-id-here");
AxeWatcher watcher = new AxeWatcher(options);

ChromeOptions chromeOptions = new ChromeOptions();
// Add any additional Chrome options here
ChromeOptions configuredOptions = watcher.configure(chromeOptions);

// Now create ChromeDriver with the configured options
ChromeDriver driver = new ChromeDriver(configuredOptions);

configure(EdgeOptions edgeOptions)

EdgeOptions を設定して、Microsoft Edge で Axe Watcher によるアクセシビリティテストを可能にします。

important

このメソッドは EdgeDriver インスタンスを作成する前に呼び出す必要があります。Microsoft Edge では Selenium 4 以降が必要です。

パラメータ:

  • edgeOptions - 設定する既存のEdgeOptionsインスタンス

戻り値:

  • Axe Watcher の設定が適用された新しい EdgeOptions インスタンス。渡されたインスタンスからは、コマンドライン引数とバイナリパスのみが引き継がれるため、他の機能は EdgeDriver を構築する前に返されるインスタンスで設定してください。

例外:

  • IllegalArgumentException - ヘッドレスまたはシークレットモードが有効な場合(Axe Watcherはこれらのモードをサポートしていません)
  • IllegalStateException - プロジェクトがバージョン4より古いselenium-javaを使用している場合。Selenium 3 のEdgeOptionsは、Axe Watcher がサポートしていないレガシーの EdgeHTML ブラウザをターゲットにしています。

例:

AxeWatcherOptions options = new AxeWatcherOptions();
options.setApiKey("your-api-key-here");
options.setProjectId("your-project-id-here");
AxeWatcher watcher = new AxeWatcher(options);

EdgeOptions edgeOptions = new EdgeOptions();
// configure() carries over the arguments and the binary path set here;
// set any other capabilities on the returned instance instead
edgeOptions.addArguments("--window-size=1280,720");
EdgeOptions configuredOptions = watcher.configure(edgeOptions);

// Now create EdgeDriver with the configured options
EdgeDriver driver = new EdgeDriver(configuredOptions);

wrapDriver(ChromeDriver chromeDriver)

ChromeDriverインスタンスをラップして、アクセシビリティテスト機能を有効にします。

important

このメソッドは、configure()ChromeDriverをセットアップするために使用された後に呼び出す必要があります。

パラメータ:

  • chromeDriver - ラップするChromeDriverインスタンス

戻り値:

  • アクセシビリティテスト機能が有効化されたラップされたWebDriverインスタンス

例外:

  • RuntimeException - このメソッドが呼ばれる前にconfigure()が呼ばれていない場合

例:

AxeWatcherOptions options = new AxeWatcherOptions();
options.setApiKey("your-api-key-here");
options.setProjectId("your-project-id-here");

AxeWatcher watcher = new AxeWatcher(options);

ChromeOptions chromeOptions = watcher.configure(new ChromeOptions());
ChromeDriver chromeDriver = new ChromeDriver(chromeOptions);

// Wrap the ChromeDriver
WebDriver driver = watcher.wrapDriver(chromeDriver);

// Now use the wrapped driver for testing
driver.get("https://example.com");

wrapDriver(EdgeDriver edgeDriver)

EdgeDriver インスタンスをラップして、アクセシビリティテスト機能を有効にします。

important

このメソッドは、configure()EdgeDriverをセットアップするために使用された後に呼び出す必要があります。

パラメータ:

  • edgeDriver - ラップするEdgeDriverインスタンス

戻り値:

  • アクセシビリティテスト機能が有効化されたラップされたWebDriverインスタンス

例外:

  • RuntimeException - このメソッドが呼ばれる前にconfigure()が呼ばれていない場合

例:

AxeWatcherOptions options = new AxeWatcherOptions();
options.setApiKey("your-api-key-here");
options.setProjectId("your-project-id-here");

AxeWatcher watcher = new AxeWatcher(options);

EdgeOptions edgeOptions = watcher.configure(new EdgeOptions());
EdgeDriver edgeDriver = new EdgeDriver(edgeOptions);

// Wrap the EdgeDriver
WebDriver driver = watcher.wrapDriver(edgeDriver);

// Now use the wrapped driver for testing
driver.get("https://example.com");

enableDebugLogger()

Axe Watcherの操作に関するデバッグログを有効にします。これは、テストの開発中に問題をトラブルシューティングするのに役立ちます。

戻り値:

  • メソッドチェーンに使用するための現在のAxeWatcherインスタンス

例:

AxeWatcherOptions options = new AxeWatcherOptions();
options.setApiKey("your-api-key-here");
options.setProjectId("your-project-id-here");
AxeWatcher watcher = new AxeWatcher(options).enableDebugLogger();

注意事項と制限

  • Axe Watcherは完全なヘッドレスモードをサポートしていません。ヘッドレスの操作が必要な場合は、--headless=new--headlessの代わりに使用してください。
  • Axe Watcherはシークレットモードをサポートしていません。
  • ChromeDriver または EdgeDriver インスタンスを作成する前に、configure() を呼び出す必要があります。
  • ChromeDriver または EdgeDriver インスタンスを作成した後に、wrapDriver() を呼び出す必要があります。
  • Microsoft Edge では Watcher 4.5.1 以降および Selenium 4 以降が必要です。Chrome パス(ChromeOptions/ChromeDriver、Chrome for Testing または Chromium と使用)は、Selenium 3.141.59 以降でサポートされています。
  • すべての結果がAxe Developer Hubに送信されることを確実にするために、テストのティアダウンでラップされたドライバーのaxeWatcher()に対してflush()を呼び出します。

関連情報