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 Javaのテストスイートに自動アクセシビリティテストを追加するための包括的なSDKが提供されます。この統合は、ウェブページを自動で解析してアクセシビリティの問題を検出し、結果をAxe Developer Hubに送信してトラッキングと解析を行います。

コアコンポーネント

メインクラス

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

AxeWatcherOptions - axe Watcherの動作を定義する設定クラスで、APIキー、サーバーURL、パラレルテスト用のビルドID、各種テスト動作を含みます。

ConfigurationOverrides - グローバルなアクセシビリティ設定を上書きすることを可能にし、アクセシビリティ基準(WCAG 2.1 AA、WCAG 2.2 AAなど)、ベストプラクティス、実験的ルールを含みます。

ドライバーとの統合

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

AxeWatcherController - アクセシビリティ解析の実行タイミングと方法に対して詳細な制御を提供し、結果の開始、停止、解析、およびフラッシュするためのメソッドを持ちます。

設定クラス

実行時オプション

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();

高度な設定

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

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テストスイートに包括的なアクセシビリティテストをシームレスに統合することを可能にします。