AxeWatcherOptions クラス

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

Selenium Java テストで axe Watcher をアクセス検証するための、カスタマイズ可能なオプションを設定

Not for use with personal data

この AxeWatcherOptions クラスは、axe Watcher Selenium Java インテグレーションのための設定オプションを提供します。このクラスを使用すると、axe Watcher が自動ブラウザテスト中にアクセス検証をどのように行うかをカスタマイズできます。これには、サーバー接続の詳細、テスト実行の挙動、およびアクセシビリティ基準が含まれます。

コンストラクタ

AxeWatcherOptions()

はデフォルト設定で新しいインスタンスを作成します。デフォルト値は以下の通りです AxeWatcherOptions

  • serverUrl: https://axe.deque.com
  • autoAnalyze: true
  • git: true
AxeWatcherOptions options = new AxeWatcherOptions();

メソッド

setApiKey(String apiKey)

axe Developer Hub で認証するための API キーを設定します。axe Watcher を使用するにはこれが必要です。

パラメータ:

  • apiKey - axe Developer Hub の API キー

戻り値:

  • AxeWatcherOptions - メソッドチェーン用の現在のインスタンス

例:

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

setProjectId(String projectId)

パラメータ:

  • projectId - アクセシビリティ結果を受け取るプロジェクトの ID

戻り値:

  • AxeWatcherOptions - メソッドチェーン用の現在のインスタンス

例:

AxeWatcherOptions options = new AxeWatcherOptions();
options.setProjectId("your-project-ID-here"); // a uuid identifying the project

setServerUrl(String serverUrl)

アクセシビリティ結果を送信するサーバーの URL を設定します。デフォルトは https://axe.deque.comです。

パラメータ:

  • serverUrl - アクセシビリティ結果を送信するサーバーの URL

戻り値:

  • AxeWatcherOptions - メソッドチェーン用の現在のインスタンス

例:

AxeWatcherOptions options = new AxeWatcherOptions();
options.setServerUrl("https://custom.axe-instance.com");

setBuildId(String buildId)

並行テストランナー用のビルド ID を設定します。null でない場合、並行テストランナーは結果を生成し、axe Developer Hub で単一のテストランとして表示されます。

パラメータ:

  • buildId - 結果を集約するためのビルド ID、通常は CI/CD ビルド ID

戻り値:

  • AxeWatcherOptions - メソッドチェーン用の現在のインスタンス

例:

AxeWatcherOptions options = new AxeWatcherOptions();
// Using a CI build ID from an environment variable
options.setBuildId(System.getenv("GITHUB_RUN_ID"));

setAutoAnalyze(boolean autoAnalyze)

テスト対象ページを自動的に分析するかどうかを設定します。デフォルトは trueです。

パラメータ:

  • autoAnalyze - テスト対象ページを自動分析するかどうか

戻り値:

  • AxeWatcherOptions - メソッドチェーン用の現在のインスタンス

例:

AxeWatcherOptions options = new AxeWatcherOptions();
// Disable automatic analysis for manual control
options.setAutoAnalyze(false);

setRunContext(AxeRunContext runContext)

テスト対象ページのコンテキストを設定し、分析する範囲を制限したり、特定の要素を分析から除外したりします。

パラメータ:

  • runContext - axe-core 分析用の実行コンテキスト

戻り値:

  • AxeWatcherOptions - メソッドチェーン用の現在のインスタンス

例:

AxeWatcherOptions options = new AxeWatcherOptions();
// Only analyze main content and exclude navigation
AxeRunContext context = new AxeRunContext()
    .setInclude(Arrays.asList("#main-content"))
    .setExclude(Arrays.asList("#navigation"));
options.setRunContext(context);

setRunOptions(AxeRunOptions runOptions)

axe-core 分析のための追加オプションを設定します。たとえば、実行または無効化するルールを指定します。

パラメータ:

  • runOptions - axe-core解析の実行オプション

戻り値:

  • AxeWatcherOptions - メソッドチェーンのための現在のインスタンス

例:

AxeWatcherOptions options = new AxeWatcherOptions();
// Disable the color contrast rule and focus on WCAG 2.1 AA
Map<String, AxeRuleOptions> rules = new HashMap<>();
rules.put("color-contrast", new AxeRuleOptions().setEnabled(false));

AxeRunOnly runOnly = new AxeRunOnly()
    .setType("tag")
    .setValues(Arrays.asList("wcag21aa"));

AxeRunOptions runOptions = new AxeRunOptions()
    .setRules(rules)
    .setRunOnly(runOnly);

options.setRunOptions(runOptions);

setExcludeUrlPatterns(String[] excludeUrlPatterns)

解析から除外するURLパターンを設定します。 Minimatch ライブラリを使用してURLをマッチさせます。

パラメータ:

  • excludeUrlPatterns - 解析から除外するURLパターン

戻り値:

  • AxeWatcherOptions - メソッドチェーンのための現在のインスタンス

例:

AxeWatcherOptions options = new AxeWatcherOptions();
// Exclude login pages and admin dashboard
options.setExcludeUrlPatterns(new String[] {
    "https://example.com/login*",
    "https://example.com/admin/*"
});

setGit(boolean git)

Watcherが現在のテスト実行のためにGit情報を収集するかどうかを設定します。デフォルトは trueです。Gitのない環境で実行する場合や、Gitデータ収集が不要な場合は false に設定してください。

パラメータ:

  • git - Git情報を収集するかどうか

戻り値:

  • AxeWatcherOptions - メソッドチェーンのための現在のインスタンス

例:

AxeWatcherOptions options = new AxeWatcherOptions();
// Disable Git info collection
options.setGit(false);

setConfigurationOverrides(ConfigurationOverrides configurationOverrides)

組織のaxeアカウントのグローバル設定に基づいて設定のオーバーライドを設定します。

パラメータ:

  • configurationOverrides - 設定のオーバーライド

戻り値:

  • AxeWatcherOptions - メソッドチェーンのための現在のインスタンス

例:

AxeWatcherOptions options = new AxeWatcherOptions();
// Override to use WCAG 2.2 AA and enable best practices
ConfigurationOverrides overrides = new ConfigurationOverrides()
    .setAccessibilityStandard(ConfigurationOverrides.AccessibilityStandard.WCAG22AA)
    .setEnableBestPractices(true);
options.setConfigurationOverrides(overrides);

getApiKey()

現在のAPIキーを取得します。

戻り値:

  • String - 現在のAPIキー

例:

AxeWatcherOptions options = new AxeWatcherOptions();
options.setApiKey("my-api-key");
String apiKey = options.getApiKey(); // Returns "my-api-key"

getProjectId()

現在のプロジェクトIDを取得します。プロジェクトIDは、axe Watcherのアクセシビリティ結果を受け取るプロジェクトを識別します。

戻り値:

  • String - 現在のプロジェクトID

例:

AxeWatcherOptions options = new AxeWatcherOptions();
options.setProjectId("my-project-ID"); // should be a uuid identifying the project
String projectId = options.getProjectId(); // Returns the project ID

getServerUrl()

現在のサーバーURLを取得します。

戻り値:

  • String - 現在のサーバーURL

例:

AxeWatcherOptions options = new AxeWatcherOptions();
String serverUrl = options.getServerUrl(); // Returns default "https://axe.deque.com"

getBuildId()

現在のビルドIDを取得します。

戻り値:

  • String - 現在のビルドID

例:

AxeWatcherOptions options = new AxeWatcherOptions();
options.setBuildId("build-123");
String buildId = options.getBuildId(); // Returns "build-123"

getAutoAnalyze()

自動解析が有効かどうかを取得します。

戻り値:

  • boolean - 自動解析が有効かどうか

例:

AxeWatcherOptions options = new AxeWatcherOptions();
boolean autoAnalyze = options.getAutoAnalyze(); // Returns true (default)

getRunContext()

現在の実行コンテキストを取得します。

戻り値:

  • AxeRunContext - 現在の実行コンテキスト

例:

AxeWatcherOptions options = new AxeWatcherOptions();
AxeRunContext context = new AxeRunContext();
options.setRunContext(context);
AxeRunContext currentContext = options.getRunContext();

getRunOptions()

現在の実行オプションを取得します。

戻り値:

  • AxeRunOptions - 現在の実行オプション

例:

AxeWatcherOptions options = new AxeWatcherOptions();
AxeRunOptions runOptions = new AxeRunOptions();
options.setRunOptions(runOptions);
AxeRunOptions currentOptions = options.getRunOptions();

getExcludeUrlPatterns()

現在の除外URLパターンを取得します。

戻り値:

  • String[] - 現在の除外URLパターン

例:

AxeWatcherOptions options = new AxeWatcherOptions();
options.setExcludeUrlPatterns(new String[] {"https://example.com/login*"});
String[] patterns = options.getExcludeUrlPatterns();

getGit()

Git情報の収集が有効かどうかを取得します。

戻り値:

  • boolean - true Git情報収集が有効な場合(デフォルト)、無効な場合はfalse

例:

AxeWatcherOptions options = new AxeWatcherOptions();
boolean git = options.getGit(); // Returns true (default)

getConfigurationOverrides()

現在の構成オーバーライドを取得します。

戻り値:

  • ConfigurationOverrides - 現在の構成オーバーライド

例:

AxeWatcherOptions options = new AxeWatcherOptions();
ConfigurationOverrides overrides = new ConfigurationOverrides();
options.setConfigurationOverrides(overrides);
ConfigurationOverrides current = options.getConfigurationOverrides();

toJson()

インスタンスを AxeWatcherOptions JSON文字列にシリアライズします。

戻り値:

  • String - オプションのJSON文字列表現

例外:

  • RuntimeException - configurationOverridesrunOptions.runOnly が同時に使用された場合(これらは相互排他的です)

例:

AxeWatcherOptions options = new AxeWatcherOptions()
    .setApiKey("my-api-key")
    .setProjectId("my-project-id")
    .setServerUrl("https://custom.axe-instance.com");
String json = options.toJson();

構成の制限

構成を行う際には、 AxeWatcherOptions、次の制約に注意してください:

  1. APIキーは必須です

    options.setApiKey("your-api-key"); // Required
  2. プロジェクトIDは必須です

    options.setProjectId("your-project-ID"); // Required
  3. 相互排他的オプション

    同時に runOptions.runOnly を使用することはできません。特定のアクセシビリティ基準を設定する必要がある場合は、 configurationOverrides.accessibilityStandard を以下のように使用してください: ConfigurationOverrides として以下に示します:

    // Correct: Using ConfigurationOverrides
    options.setConfigurationOverrides(
        new ConfigurationOverrides()
            .setAccessibilityStandard(ConfigurationOverrides.AccessibilityStandard.WCAG22AA)
    );
    
    // Correct: Using RunOptions.runOnly
    options.setRunOptions(
        new AxeRunOptions()
            .setRunOnly(new AxeRunOnly().setType("tag").setValues(Arrays.asList("wcag22aa")))
    );
    
    // Incorrect: Using both together will throw an exception
    options.setConfigurationOverrides(
        new ConfigurationOverrides()
            .setAccessibilityStandard(ConfigurationOverrides.AccessibilityStandard.WCAG22AA)
    ).setRunOptions(
        new AxeRunOptions()
            .setRunOnly(new AxeRunOnly().setType("tag").setValues(Arrays.asList("wcag21aa")))
    );

参照