Add accessibility assertions in Automated tests
Add accessibility assertions in your regression suite using our accessibility issue functions.
We provide a function called getAccessibilityResultsSummary()
which contains a high-level summary of the accessibility testing conducted within a test case. You can use this function to create assertions based on the issue count within a test case while conducting accessibility testing.
Output fields
Fields which are returned within the function:
Key | Description | Type |
---|---|---|
totalIssueCount |
Summation of issue count | Integer |
issueCountBySeverity |
Issue breakdown by severity | {critical : Integer, minor : Integer, moderate : Integer, serious : Integer} |
Output example
Example assertion
Map<String, Object> summary = AccessibilityUtils.getResultsSummary(driver);
int criticalIssueCount = Integer.parseInt(String.valueOf(((Map)summary.get("issueCountBySeverity")).get("critical")));
Assert.assertTrue(criticalIssueCount < 10, "Critical issue count breached the threshold!");
let summary = await driver.getAccessibilityResultsSummary();
let criticalIssueCount = summary["issueCountBySeverity"]["critical"];
assert.isTrue(criticalIssueCount < 10, "Critical issue count breached the threshold!");
Assertions based on accessibility issues
We provide a function called getAccessibilityResults()
which contains a list of accessibility issues which were detected. You can use this function to create assertions based on the actual issues within a test case while conducting accessibility testing.
Output fields
Fields which are returned within the function:
Key | Description | Type |
---|---|---|
name |
Short one-line description of the issue. | String |
description |
Detailed description of the issue. | String |
rule-id |
ID of the a11y-engine rule corresponding to the issue. | String |
severity |
The severity level of the issue as per WCAG guidelines. | String |
component |
A grouping of similar elements based on their HTML selector & CSS class names. | String |
affectedPage |
Page on which the issue was detected. | String |
wcagTags |
WCAG guideline which has been violated. | String |
moreInfoLink |
A link to detailed documentation about the violated rule. | String |
issueDetails |
This is an array containing the CSS selector & HTML snippet. | Object; Format: {cssSelector : String, htmlSnippet : String} |
howToFix |
Remediation guidance to fix an issue. | String |
issueTags |
This is an array with information if the issue type is Experimental, Best practice, or Needs review. | Object; Format: {experimental : Boolean, bestPractice : Boolean, needsReview : Boolean} |
Output example
Example assertion
/* getColorContrastIssueCount() represents a function which checks if any color contrast issues are present within the results. */
ArrayList<Map<String, Object>> results = AccessibilityUtils.getResults(driver);
int colorContrastIssueCount = getColorContrastIssueCount(results);
Assert.assertTrue(colorContrastIssueCount < 100, "Color contrast issue count breached the threshold!");
/* getColorContrastIssueCount() represents a function which checks if any color contrast issues are present within the results. */
let results = await driver.getAccessibilityResults();
let colorContrastIssueCount = getColorContrastIssueCount(results);
assert.isTrue(colorContrastIssueCount < 100, "Color contrast issue count breached the threshold!");
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked
Thank you for your valuable feedback!