AxeWatcherOptions Klasse
Configureer de axe Watcher voor toegankelijkheidstests in Selenium Java-testen met aanpasbare opties
De AxeWatcherOptions klasse biedt configuratieopties voor de axe Watcher Selenium Java-integratie. Deze klasse stelt je in staat om aan te passen hoe axe Watcher toegankelijkheidstests uitvoert tijdens geautomatiseerde browsertests, inclusief serververbind details, testuitvoeringsgedrag en toegankelijkheidsnormen.
Constructor
AxeWatcherOptions()
Creëert een nieuwe instantie van AxeWatcherOptions met standaardinstellingen. De standaardwaarden zijn:
serverUrl:https://axe.deque.comautoAnalyze:truegit:true
AxeWatcherOptions options = new AxeWatcherOptions();Methoden
setApiKey(String apiKey)
Stelt de API-sleutel in om te authenticeren bij het axe Developer Hub. Dit is vereist om axe Watcher te gebruiken.
Parameters:
apiKey- Jouw axe Developer Hub API-sleutel
Retourneert:
AxeWatcherOptions- De huidige instantie voor method chaining
Voorbeeld:
AxeWatcherOptions options = new AxeWatcherOptions();
options.setApiKey("your-api-key-here");setProjectId(String projectId)
Parameters:
projectId- Het project-ID van het project dat toegankelijkheidsresultaten moet ontvangen
Retourneert:
AxeWatcherOptions- De huidige instantie voor method chaining
Voorbeeld:
AxeWatcherOptions options = new AxeWatcherOptions();
options.setProjectId("your-project-ID-here"); // a uuid identifying the projectsetServerUrl(String serverUrl)
Stelt de server-URL in om toegankelijkheidsresultaten te verzenden. Standaardwaarde is https://axe.deque.com.
Parameters:
serverUrl- URL van de server om toegankelijkheidsresultaten naar te verzenden
Retourneert:
AxeWatcherOptions- De huidige instantie voor method chaining
Voorbeeld:
AxeWatcherOptions options = new AxeWatcherOptions();
options.setServerUrl("https://custom.axe-instance.com");setBuildId(String buildId)
Stelt de build-ID in voor parallelle testrunners. Wanneer niet null, stelt dit parallelle testrunners in staat om resultaten te genereren die verschijnen als één testrun in het axe Developer Hub.
Parameters:
buildId- Build-ID om resultaten onder te aggregeren, typisch een CI/CD build-ID
Retourneert:
AxeWatcherOptions- De huidige instantie voor method chaining
Voorbeeld:
AxeWatcherOptions options = new AxeWatcherOptions();
// Using a CI build ID from an environment variable
options.setBuildId(System.getenv("GITHUB_RUN_ID"));setAutoAnalyze(boolean autoAnalyze)
Bepaalt of de pagina onder test automatisch moet worden geanalyseerd. Standaardwaarde is true.
Parameters:
autoAnalyze- Of de pagina onder test automatisch moet worden geanalyseerd
Retourneert:
AxeWatcherOptions- De huidige instantie voor method chaining
Voorbeeld:
AxeWatcherOptions options = new AxeWatcherOptions();
// Disable automatic analysis for manual control
options.setAutoAnalyze(false);setRunContext(AxeRunContext runContext)
Stelt de context van de pagina onder test in om het bereik van wat wordt geanalyseerd te beperken of om bepaalde elementen van analyse uit te sluiten.
Parameters:
runContext- Run-context voor axe-core analyse
Retourneert:
AxeWatcherOptions- De huidige instantie voor method chaining
Voorbeeld:
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)
Stelt aanvullende opties in voor axe-core analyse, zoals welke regels moeten worden uitgevoerd of uitgeschakeld.
Parameters:
runOptions- Opties uitvoeren voor axe-core-analyse
Geeft terug:
AxeWatcherOptions- De huidige instantie voor method chaining
Voorbeeld:
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)
Stelt URL-patronen in die van analyse moeten worden uitgesloten. Gebruikt de Minimatch bibliotheek om URL's te matchen.
Parameters:
excludeUrlPatterns- URL-patronen om van analyse uit te sluiten
Geeft terug:
AxeWatcherOptions- De huidige instantie voor method chaining
Voorbeeld:
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)
Stelt in of Watcher Git-informatie verzamelt voor de huidige testuitvoering. Standaard is true. Stel in op false wanneer u zich in omgevingen zonder Git bevindt of wanneer het verzamelen van Git-gegevens niet nodig is.
Parameters:
git- Of Git-informatie moet worden verzameld
Geeft terug:
AxeWatcherOptions- De huidige instantie voor method chaining
Voorbeeld:
AxeWatcherOptions options = new AxeWatcherOptions();
// Disable Git info collection
options.setGit(false);setConfigurationOverrides(ConfigurationOverrides configurationOverrides)
Stelt configuratie-aanpassingen in op basis van de globale configuratie-instellingen van het axe-account van uw organisatie.
Parameters:
configurationOverrides- Configuratie-aanpassingen
Geeft terug:
AxeWatcherOptions- De huidige instantie voor method chaining
Voorbeeld:
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()
Haalt de huidige API-sleutel op.
Geeft terug:
String- De huidige API-sleutel
Voorbeeld:
AxeWatcherOptions options = new AxeWatcherOptions();
options.setApiKey("my-api-key");
String apiKey = options.getApiKey(); // Returns "my-api-key"getProjectId()
Haalt de huidige project-ID op. De project-ID identificeert het project dat toegankelijkheidsresultaten van axe Watcher ontvangt.
Geeft terug:
String- De huidige project-ID
Voorbeeld:
AxeWatcherOptions options = new AxeWatcherOptions();
options.setProjectId("my-project-ID"); // should be a uuid identifying the project
String projectId = options.getProjectId(); // Returns the project IDgetServerUrl()
Haalt de huidige server-URL op.
Geeft terug:
String- De huidige server-URL
Voorbeeld:
AxeWatcherOptions options = new AxeWatcherOptions();
String serverUrl = options.getServerUrl(); // Returns default "https://axe.deque.com"getBuildId()
Haalt de huidige build-ID op.
Geeft terug:
String- De huidige build-ID
Voorbeeld:
AxeWatcherOptions options = new AxeWatcherOptions();
options.setBuildId("build-123");
String buildId = options.getBuildId(); // Returns "build-123"getAutoAnalyze()
Haalt op of automatische analyse is ingeschakeld.
Geeft terug:
boolean- Of automatische analyse is ingeschakeld
Voorbeeld:
AxeWatcherOptions options = new AxeWatcherOptions();
boolean autoAnalyze = options.getAutoAnalyze(); // Returns true (default)getRunContext()
Haalt de huidige uitvoeringscontext op.
Geeft terug:
AxeRunContext- De huidige uitvoeringscontext
Voorbeeld:
AxeWatcherOptions options = new AxeWatcherOptions();
AxeRunContext context = new AxeRunContext();
options.setRunContext(context);
AxeRunContext currentContext = options.getRunContext();getRunOptions()
Haalt de huidige uitvoeropties op.
Retourneert:
AxeRunOptions- De huidige uitvoeropties
Voorbeeld:
AxeWatcherOptions options = new AxeWatcherOptions();
AxeRunOptions runOptions = new AxeRunOptions();
options.setRunOptions(runOptions);
AxeRunOptions currentOptions = options.getRunOptions();getExcludeUrlPatterns()
Haalt de huidige uitgesloten URL-patronen op.
Retourneert:
String[]- De huidige uitgesloten URL-patronen
Voorbeeld:
AxeWatcherOptions options = new AxeWatcherOptions();
options.setExcludeUrlPatterns(new String[] {"https://example.com/login*"});
String[] patterns = options.getExcludeUrlPatterns();getGit()
Controleert of het verzamelen van Git-gegevens is ingeschakeld.
Retourneert:
boolean-trueals het verzamelen van Git-gegevens is ingeschakeld (standaard), false als uitgeschakeld
Voorbeeld:
AxeWatcherOptions options = new AxeWatcherOptions();
boolean git = options.getGit(); // Returns true (default)getConfigurationOverrides()
Haalt de huidige configuratie-overrides op.
Retourneert:
ConfigurationOverrides- De huidige configuratie-overrides
Voorbeeld:
AxeWatcherOptions options = new AxeWatcherOptions();
ConfigurationOverrides overrides = new ConfigurationOverrides();
options.setConfigurationOverrides(overrides);
ConfigurationOverrides current = options.getConfigurationOverrides();toJson()
Serialiseert de AxeWatcherOptions instantie naar een JSON-string.
Retourneert:
String- Een JSON-stringrepresentatie van de opties
Geeft een uitzondering:
RuntimeException- AlsconfigurationOverridesenrunOptions.runOnlysamen worden gebruikt (deze zijn wederzijds exclusief)
Voorbeeld:
AxeWatcherOptions options = new AxeWatcherOptions()
.setApiKey("my-api-key")
.setProjectId("my-project-id")
.setServerUrl("https://custom.axe-instance.com");
String json = options.toJson();Configuratiebeperkingen
Bij het configureren van AxeWatcherOptions, let op de volgende beperkingen:
-
De API-sleutel is vereist:
options.setApiKey("your-api-key"); // Required -
Het project-ID is vereist:
options.setProjectId("your-project-ID"); // Required -
Wederzijds exclusieve opties:
Je kunt niet zowel
runOptions.runOnlyalsconfigurationOverrides.accessibilityStandardsamen gebruiken. Als je een specifieke toegankelijkheidsstandaard moet instellen, gebruikConfigurationOverrideszoals hieronder getoond:// 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"))) );
