Class AccessibilityActions
AccessibilityHelper.
Typical usage:
driver.accessibility()
.analyzePage("Home")
.assertNoCriticalViolations("Home")
.backToBrowser();
Analysis results are cached in a ConcurrentHashMap
keyed by a composite of page name, AccessibilityConfig identity via
config.hashCode(), and the saveReport flag.
Successive calls with the same config instance and the same page name will
reuse the cached result. Note that two separately constructed AccessibilityConfig
objects with identical settings will produce different cache keys because
AccessibilityConfig does not override equals/hashCode.
Thread safety: Each AccessibilityActions instance is tied to a single
SHAFT.GUI.WebDriver instance and must not be shared across threads.
The internal cache (ConcurrentHashMap) is safe for concurrent
reads, but the analysis itself (browser interaction) is not.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionAccessibilityActions(org.openqa.selenium.WebDriver rawDriver, BrowserActions browserActions) Constructs anAccessibilityActionsinstance backed by the supplied rawWebDriverand the caller'sBrowserActionscontext. -
Method Summary
Modifier and TypeMethodDescriptionanalyzeAndReturn(String pageName) Analyzes the current page and returns theAccessibilityHelper.AccessibilityResultfor programmatic inspection.analyzeAndReturn(String pageName, boolean saveReport) Analyzes the current page, optionally saving the HTML report to disk, and returns theAccessibilityHelper.AccessibilityResultfor programmatic inspection.analyzeAndReturn(String pageName, AccessibilityHelper.AccessibilityConfig config) Analyzes the current page using a customAccessibilityHelper.AccessibilityConfig, saves the report, and returns the result.analyzeAndReturn(String pageName, AccessibilityHelper.AccessibilityConfig config, boolean saveReport) Analyzes the current page using the given configuration andsaveReportflag, then returns theAccessibilityHelper.AccessibilityResult.analyzePage(String pageName) Runs an accessibility audit on the current page, saves the HTML report to disk, and attaches it to the Allure report under the givenpageName.analyzePage(String pageName, AccessibilityHelper.AccessibilityConfig config) Runs an accessibility audit on the current page using a customAccessibilityHelper.AccessibilityConfig, saves the HTML report to disk, and attaches it to the Allure report.analyzeWithIgnoredRules(String pageName, List<String> ignoredRuleIds) Analyzes the current page and attaches a filtered Allure report that excludes the specified rule IDs, without permanently modifying the cached result.assertAccessibilityScoreAtLeast(String pageName, double minimumPercentage) Asserts that the accessibility score for the given page is at leastminimumPercentage.assertAccessibilityScoreAtLeast(String pageName, double minimumPercentage, boolean saveReport) Asserts that the accessibility score for the given page is at leastminimumPercentage, with control over whether the HTML report is saved to disk.assertAccessibilityScoreAtLeast(String pageName, double minimumPercentage, AccessibilityHelper.AccessibilityConfig config) Asserts that the accessibility score for the given page is at leastminimumPercentage, using a customAccessibilityHelper.AccessibilityConfig.assertAccessibilityScoreAtLeast(String pageName, double minimumPercentage, AccessibilityHelper.AccessibilityConfig config, boolean saveReport) Asserts that the accessibility score for the given page is at leastminimumPercentage, using a customAccessibilityHelper.AccessibilityConfigand explicit control over report persistence.Asserts (hard assertion) that the current page is fully accessible according toAccessibilityHelper.isAccessible(WebDriver)'s default criteria (zero violations).assertNoCriticalViolations(String pageName) Asserts (hard assertion) that the current page has no accessibility violations with an impact level of"critical".assertNoViolationsByImpact(String pageName, String... impactLevels) Asserts (hard assertion) that the current page has no accessibility violations matching any of the supplied impact levels.Returns theBrowserActionsinstance that was used to create thisAccessibilityActions, enabling fluent chaining back into browser-level operations.failIfViolationsExist(String pageName) Attaches a filtered Allure report for the given page and throws anAssertionErrorif any accessibility violations exist.Verifies (soft assertion) that the current page is fully accessible according toAccessibilityHelper.isAccessible(WebDriver)'s default criteria (zero violations).verifyNoCriticalViolations(String pageName) Verifies (soft assertion) that the current page has no accessibility violations with an impact level of"critical".
-
Constructor Details
-
AccessibilityActions
Constructs anAccessibilityActionsinstance backed by the supplied rawWebDriverand the caller'sBrowserActionscontext.The raw driver is wrapped in a
SHAFT.GUI.WebDriverso that SHAFT's assertion and verification helpers are available internally.- Parameters:
rawDriver- the underlying SeleniumWebDriverused to run axe-core scriptsbrowserActions- theBrowserActionsinstance to return to whenbackToBrowser()is called
-
-
Method Details
-
analyzePage
Runs an accessibility audit on the current page, saves the HTML report to disk, and attaches it to the Allure report under the givenpageName.The result is cached so that subsequent assertion calls for the same page reuse it without triggering another axe run.
Example:
driver.accessibility().analyzePage("Checkout");- Parameters:
pageName- a human-readable label used to name the saved report file and the Allure attachment (e.g."HomePage")- Returns:
- this
AccessibilityActionsinstance for method chaining
-
analyzePage
public AccessibilityActions analyzePage(String pageName, AccessibilityHelper.AccessibilityConfig config) Runs an accessibility audit on the current page using a customAccessibilityHelper.AccessibilityConfig, saves the HTML report to disk, and attaches it to the Allure report.Use this overload when you need to restrict the audit to specific WCAG tags, rules, or impact levels that differ from the default configuration.
Example:
AccessibilityHelper.AccessibilityConfig config = new AccessibilityHelper.AccessibilityConfig() .setTags(List.of("wcag2a", "wcag2aa")); driver.accessibility().analyzePage("Checkout", config);- Parameters:
pageName- a human-readable label used to name the saved report file and Allure attachmentconfig- custom axe-core configuration controlling which rules / tags are included- Returns:
- this
AccessibilityActionsinstance for method chaining
-
analyzeAndReturn
Analyzes the current page and returns theAccessibilityHelper.AccessibilityResultfor programmatic inspection. The report is saved to disk and the result is cached.Subsequent calls with the same
pageNamereturn the cached result without running the audit again.Example:
AccessibilityHelper.AccessibilityResult result = driver.accessibility().analyzeAndReturn("ProductPage"); int violationCount = result.getViolations().size();- Parameters:
pageName- a human-readable label for the page being audited- Returns:
- the
AccessibilityHelper.AccessibilityResultcontaining violations, passes, and the overall accessibility score
-
analyzeAndReturn
public AccessibilityHelper.AccessibilityResult analyzeAndReturn(String pageName, boolean saveReport) Analyzes the current page, optionally saving the HTML report to disk, and returns theAccessibilityHelper.AccessibilityResultfor programmatic inspection.Example:
// Analyze without persisting a report file AccessibilityHelper.AccessibilityResult result = driver.accessibility().analyzeAndReturn("SearchPage", false);- Parameters:
pageName- a human-readable label for the page being auditedsaveReport-trueto persist the HTML report file on disk;falseto skip file creation (useful for assertion-only checks)- Returns:
- the
AccessibilityHelper.AccessibilityResultfor the audited page
-
analyzeAndReturn
public AccessibilityHelper.AccessibilityResult analyzeAndReturn(String pageName, AccessibilityHelper.AccessibilityConfig config) Analyzes the current page using a customAccessibilityHelper.AccessibilityConfig, saves the report, and returns the result. The result is cached for the givenpageName+configcombination.Example:
AccessibilityHelper.AccessibilityConfig config = new AccessibilityHelper.AccessibilityConfig() .setTags(List.of("best-practice")); AccessibilityHelper.AccessibilityResult result = driver.accessibility().analyzeAndReturn("CartPage", config);- Parameters:
pageName- a human-readable label for the page being auditedconfig- custom axe-core configuration;nulluses the default configuration- Returns:
- the
AccessibilityHelper.AccessibilityResultfor the audited page
-
analyzeAndReturn
public AccessibilityHelper.AccessibilityResult analyzeAndReturn(String pageName, AccessibilityHelper.AccessibilityConfig config, boolean saveReport) Analyzes the current page using the given configuration andsaveReportflag, then returns theAccessibilityHelper.AccessibilityResult.This is the canonical overload that all other
analyzeAndReturnvariants delegate to. Results are memoized: the first call computes and caches the result; subsequent calls with an identical key return the cached value immediately.Example:
AccessibilityHelper.AccessibilityConfig config = new AccessibilityHelper.AccessibilityConfig() .setTags(List.of("wcag2a")); AccessibilityHelper.AccessibilityResult result = driver.accessibility().analyzeAndReturn("LoginPage", config, false);- Parameters:
pageName- a human-readable label for the page being auditedconfig- custom axe-core configuration;nullapplies the default configurationsaveReport-trueto persist the HTML report file;falseto skip it- Returns:
- the
AccessibilityHelper.AccessibilityResultfor the audited page
-
analyzeWithIgnoredRules
Analyzes the current page and attaches a filtered Allure report that excludes the specified rule IDs, without permanently modifying the cached result.This is useful when certain known violations should be suppressed from the report for a particular context (e.g. third-party widgets) while keeping the full cached result intact for other callers.
Example:
driver.accessibility() .analyzeWithIgnoredRules("Dashboard", List.of("color-contrast", "label"));- Parameters:
pageName- a human-readable label for the page being audited; used to retrieve or create the cached result and to name the Allure attachmentignoredRuleIds- axe-core rule IDs (e.g."color-contrast","label") to exclude from the attached report; the underlying cached violations list is restored after the attachment is created- Returns:
- this
AccessibilityActionsinstance for method chaining
-
assertNoCriticalViolations
Asserts (hard assertion) that the current page has no accessibility violations with an impact level of"critical".The audit result is fetched from the cache or computed on demand. Failure causes the test to stop immediately (hard assertion semantics).
Example:
driver.accessibility() .analyzePage("PaymentPage") .assertNoCriticalViolations("PaymentPage");- Parameters:
pageName- a human-readable label identifying the page to assert against; must match the label used in a precedinganalyzePage(String)oranalyzeAndReturn(String)call so the cache is hit- Returns:
- this
AccessibilityActionsinstance for method chaining
-
verifyNoCriticalViolations
Verifies (soft assertion) that the current page has no accessibility violations with an impact level of"critical".Unlike
assertNoCriticalViolations(String), a soft assertion failure is recorded but does not stop test execution immediately; all failures are reported at the end of the test.Example:
driver.accessibility() .analyzePage("CartPage") .verifyNoCriticalViolations("CartPage");- Parameters:
pageName- a human-readable label identifying the page to verify; must match the label used in a preceding analysis call so the cache is hit- Returns:
- this
AccessibilityActionsinstance for method chaining
-
assertIsAccessible
Asserts (hard assertion) that the current page is fully accessible according toAccessibilityHelper.isAccessible(WebDriver)'s default criteria (zero violations).Example:
driver.accessibility().assertIsAccessible();- Returns:
- this
AccessibilityActionsinstance for method chaining
-
verifyIsAccessible
Verifies (soft assertion) that the current page is fully accessible according toAccessibilityHelper.isAccessible(WebDriver)'s default criteria (zero violations).Unlike
assertIsAccessible(), a failure is recorded but does not halt the test.Example:
driver.accessibility().verifyIsAccessible();- Returns:
- this
AccessibilityActionsinstance for method chaining
-
assertNoViolationsByImpact
Asserts (hard assertion) that the current page has no accessibility violations matching any of the supplied impact levels.A filtered Allure attachment is generated showing only the violations that matched the requested impact levels, making failures easier to triage.
Example:
driver.accessibility() .assertNoViolationsByImpact("ProfilePage", "critical", "serious");- Parameters:
pageName- a human-readable label for the page being checked; used for caching and the assertion failure messageimpactLevels- one or more axe-core impact levels to check (case-insensitive):"minor","moderate","serious","critical"- Returns:
- this
AccessibilityActionsinstance for method chaining
-
failIfViolationsExist
Attaches a filtered Allure report for the given page and throws anAssertionErrorif any accessibility violations exist.This method is a strict gate: any violation — regardless of impact level — causes an immediate hard failure. Use
assertNoViolationsByImpact(String, String...)when you need to filter by severity.Example:
driver.accessibility() .analyzePage("LandingPage") .failIfViolationsExist("LandingPage");- Parameters:
pageName- a human-readable label for the page being checked; must match a previously analyzed page so the cached result is reused- Returns:
- this
AccessibilityActionsinstance for method chaining - Throws:
AssertionError- if one or more accessibility violations are present on the page
-
assertAccessibilityScoreAtLeast
public AccessibilityActions assertAccessibilityScoreAtLeast(String pageName, double minimumPercentage) Asserts that the accessibility score for the given page is at leastminimumPercentage. The report is saved to disk.The score is computed by
AccessibilityHelper.AccessibilityResult.getAccessibilityScore()and represents the ratio of passing rules to total rules as a percentage (0–100).Example:
driver.accessibility() .assertAccessibilityScoreAtLeast("HomePage", 90.0);- Parameters:
pageName- a human-readable label for the page being checkedminimumPercentage- the minimum acceptable accessibility score (inclusive), in the range0.0–100.0- Returns:
- this
AccessibilityActionsinstance for method chaining - Throws:
IllegalArgumentException- ifminimumPercentageis outside[0, 100]AssertionError- if the computed score is belowminimumPercentage
-
assertAccessibilityScoreAtLeast
public AccessibilityActions assertAccessibilityScoreAtLeast(String pageName, double minimumPercentage, boolean saveReport) Asserts that the accessibility score for the given page is at leastminimumPercentage, with control over whether the HTML report is saved to disk.Example:
// Assert score without persisting a report file driver.accessibility() .assertAccessibilityScoreAtLeast("ResultsPage", 85.0, false);- Parameters:
pageName- a human-readable label for the page being checkedminimumPercentage- the minimum acceptable accessibility score (inclusive), in the range0.0–100.0saveReport-trueto persist the HTML report file;falseto skip it- Returns:
- this
AccessibilityActionsinstance for method chaining - Throws:
IllegalArgumentException- ifminimumPercentageis outside[0, 100]AssertionError- if the computed score is belowminimumPercentage
-
assertAccessibilityScoreAtLeast
public AccessibilityActions assertAccessibilityScoreAtLeast(String pageName, double minimumPercentage, AccessibilityHelper.AccessibilityConfig config) Asserts that the accessibility score for the given page is at leastminimumPercentage, using a customAccessibilityHelper.AccessibilityConfig. The report is saved to disk.Example:
AccessibilityHelper.AccessibilityConfig config = new AccessibilityHelper.AccessibilityConfig() .setTags(List.of("wcag2a")); driver.accessibility() .assertAccessibilityScoreAtLeast("ProfilePage", 95.0, config);- Parameters:
pageName- a human-readable label for the page being checkedminimumPercentage- the minimum acceptable accessibility score (inclusive), in the range0.0–100.0config- custom axe-core configuration applied during the audit- Returns:
- this
AccessibilityActionsinstance for method chaining - Throws:
IllegalArgumentException- ifminimumPercentageis outside[0, 100]AssertionError- if the computed score is belowminimumPercentage
-
assertAccessibilityScoreAtLeast
public AccessibilityActions assertAccessibilityScoreAtLeast(String pageName, double minimumPercentage, AccessibilityHelper.AccessibilityConfig config, boolean saveReport) Asserts that the accessibility score for the given page is at leastminimumPercentage, using a customAccessibilityHelper.AccessibilityConfigand explicit control over report persistence.This is the most flexible overload and is the one all other
assertAccessibilityScoreAtLeastvariants ultimately delegate to.Example:
AccessibilityHelper.AccessibilityConfig config = new AccessibilityHelper.AccessibilityConfig() .setTags(List.of("wcag2aa")); driver.accessibility() .assertAccessibilityScoreAtLeast("SettingsPage", 80.0, config, true);- Parameters:
pageName- a human-readable label for the page being checkedminimumPercentage- the minimum acceptable accessibility score (inclusive), in the range0.0–100.0config- custom axe-core configuration applied during the audit;nulluses the default configurationsaveReport-trueto persist the HTML report file;falseto skip it- Returns:
- this
AccessibilityActionsinstance for method chaining - Throws:
IllegalArgumentException- ifminimumPercentageis outside[0, 100]AssertionError- if the computed score is belowminimumPercentage
-
backToBrowser
Returns theBrowserActionsinstance that was used to create thisAccessibilityActions, enabling fluent chaining back into browser-level operations.Example:
driver.accessibility() .analyzePage("Home") .assertNoCriticalViolations("Home") .backToBrowser() .navigateToURL("https://example.com/about");- Returns:
- the originating
BrowserActionsinstance
-