Java Watcher APIの概要

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 Watcherが提供するAPIとその使用方法についての情報

Not for use with personal data

Axe WatcherのJava統合は、SeleniumおよびPlaywrightのJavaテストスイートに自動的なアクセシビリティテストを追加するための包括的なSDKを提供します。この統合により、ウェブページをアクセシビリティの問題について自動的に分析し、結果をAxe Developer Hubに送信して追跡と分析を行います。

コアコンポーネント

メインクラス

AxeWatcher - Selenium統合の主要なエントリーポイントです。このクラスはブラウザオプションの構成とWebDriverインスタンスのラップを処理し、アクセシビリティテストを可能にします。

AxeWatcherPlaywright - Playwright統合の主要なエントリーポイントです。LaunchPersistentContextOptionsの構成とPageインスタンスのラップを処理します。

AxeWatcherOptions - Axe Watcherの動作を定義する構成クラスであり、APIキー、サーバーURL、並列テスト用のビルドID、さまざまなテストの動作を含みます。SeleniumとPlaywrightの両方の統合で使用されます。

AxeWatcherGitInfo - 自動Git検出が利用できないまたは信頼できないテスト実行のために、明示的なGitメタデータを保持します。AxeWatcherOptions.setGitInfo()に渡して自動検出をバイパスします。

ConfigurationOverrides - アクセシビリティ標準(WCAG 2.1 AA、WCAG 2.2 AAなど)、ベストプラクティス、実験的ルールなど、グローバルなアクセシビリティ構成設定をオーバーライドすることを可能にします。

ドライバー統合

AxeWatcherDriver - 標準のSelenium WebDriverを拡張して、axeWatcher()メソッドを通じてアクセシビリティテスト機能にアクセスするインターフェースです。

AxeWatcherController - Selenium内でアクセシビリティ分析を行うタイミングと方法を詳細に制御し、テスト結果を開始、停止、分析、フラッシュするメソッドを提供します。

AxeWatcherPlaywrightController - Playwright用に同様の制御メソッドを提供し、ラップされたAxeWatcherPageを通じてアクセス可能です。

構成クラス

ランタイムオプション

AxeRunOptions - ルールの構成や違反の系統情報を含む、axe-coreエンジンの高度なランタイム動作を制御します。

AxeRunOnly - ルールIDやタグ(例:「wcag21aa」、「best-practice」)を指定することにより実行されるアクセシビリティルールを制限します。

AxeRunContext - CSSセレクタを使用して特定のDOM要素を含めるか除外することで、テストの範囲を定義します。

AxeRuleOptions - ルールIDによって個々のアクセシビリティルールを有効または無効にします。

使用方法

基本設定

// Configure options
AxeWatcherOptions options = new AxeWatcherOptions()
    .setApiKey(System.getenv("ACCESSIBILITY_API_KEY")) // Required. Secret stored in an environment variable.
    .setProjectId(System.getenv("PROJECT_ID")); // Required. Store in an environment variable for easy updates.

// Create watcher and configure Chrome
AxeWatcher watcher = new AxeWatcher(options);
ChromeOptions chromeOptions = watcher.configure(new ChromeOptions());
ChromeDriver chromeDriver = new ChromeDriver(chromeOptions);

// Wrap driver for accessibility testing
WebDriver driver = watcher.wrapDriver(chromeDriver);

// Access the controller for manual control
AxeWatcherController controller = ((AxeWatcherDriver) driver).axeWatcher();

高度な構成

地域またはプライベートクラウドインスタンスの構成

組織が地域、プライベートクラウド、オンプレミスのAxe Developer Hubインスタンスを使用している場合、そのインスタンスのベースURLをサーバーURLに設定します。それ以外の場合は、setServerUrl()を省略してデフォルトのhttps://axe.deque.comが使用されます。

AxeWatcherOptions options = new AxeWatcherOptions()
    .setApiKey(System.getenv("ACCESSIBILITY_API_KEY"))
    .setProjectId(System.getenv("PROJECT_ID"))
    .setServerUrl(System.getenv("SERVER_URL")); // e.g., "https://axe-eu.deque.com"

カスタムアクセシビリティ標準

ConfigurationOverrides overrides = new ConfigurationOverrides()
    .setAccessibilityStandard(ConfigurationOverrides.AccessibilityStandard.WCAG22AA)
    .setEnableBestPractices(true)
    .setEnableExperimental(false);

AxeWatcherOptions options = new AxeWatcherOptions()
    .setApiKey(System.getenv("ACCESSIBILITY_API_KEY")) // Required. Secret stored in an environment variable.
    .setProjectId(System.getenv("PROJECT_ID")) // Required. Store in an environment variable for easy updates.
    .setConfigurationOverrides(overrides);

選択的ルール実行

// Run only specific accessibility tags
AxeRunOnly runOnly = new AxeRunOnly()
    .setType("tag")
    .setValues(Arrays.asList("wcag21aa", "best-practice"));

AxeRunOptions runOptions = new AxeRunOptions()
    .setRunOnly(runOnly)
    .setAncestry(true);

AxeWatcherOptions options = new AxeWatcherOptions()
    .setApiKey(System.getenv("ACCESSIBILITY_API_KEY")) // Required. Secret stored in an environment variable.
    .setProjectId(System.getenv("PROJECT_ID")) // Required. Store in an environment variable for easy updates.    
    .setRunOptions(runOptions);

スコープドテスト

// Include only specific elements
AxeRunContext context = new AxeRunContext()
    .setInclude(Arrays.asList("#main-content", ".form-section"))
    .setExclude(Arrays.asList("#header", "#footer"));

AxeWatcherOptions options = new AxeWatcherOptions()
    .setApiKey(System.getenv("ACCESSIBILITY_API_KEY")) // Required. Secret stored in an environment variable.
    .setProjectId(System.getenv("PROJECT_ID")) // Required. Store in an environment variable for easy updates.
    .setRunContext(context);

重要な制約

  1. 相互排他的なオプション: ConfigurationOverrides.accessibilityStandardAxeRunOptions.runOnlyを同時に使用することはできません
  2. ブラウザの制約: 完全なヘッドレスモードやシークレットモードをサポートしていません
  3. メソッドの順番: ChromeDriverを作成する前にconfigure()を、作成後にwrapDriver()を呼び出す必要があります
  4. 結果のフラッシュ: テストのティアダウンで常にcontroller.flush()を呼び出して、結果がAxe Developer Hubに送信されるようにしてください
  5. フレームの制約: コントローラーメソッドは、iframe内または非HTTP(S)ページでは機能しません

この統合により、自動および手動のテストモードを提供し、チームが最小限のコード変更で既存のSelenium Javaテストスイートに包括的なアクセシビリティテストをシームレスに統合できるようになります。