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.
Add the function to your test cases to add assertions to your build.
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!");
...
console.log('calling getAccessibilityResultsSummary');
var summary = await browser.getAccessibilityResultsSummary();
console.log(summary);
let criticalIssueCount = summary?.issueCountBySeverity?.critical ?? 0;
assert.strictEqual(criticalIssueCount < 10, true, `Critical issue count exceeded threshold! Found: ${criticalIssueCount}`);
...
For WDIO automated tests, you must import com.browserstack.accessibility.AccessibilityUtils
in your test case.
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.
Add the function to your test cases to add assertions to your build.
Output fields
Fields which are returned within the function:
Key | Description | Type |
---|---|---|
Issue name |
Name of the accessibility issue. | String |
Description |
Detailed description of the issue. | String |
WCAG Info |
WCAG guideline which has been violated. | String |
severity |
The severity level of the issue as per WCAG guidelines. | String |
className |
The class associated with the element having the issue. | Strring |
viewId |
The identifier for the view where the issue was found. | String |
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!");
...
let results = await browser.getAccessibilityResults();
console.log("Accessibility Results:", results);
if (!results) {
throw new Error("Accessibility results not available! Test cannot proceed.");
}
function getAccessibilityLabelIssueCount(results) {
return results.filter(issue => issue.issueName === "Interactive Element Accessibility Label").length;
}
let accessibilityLabelIssueCount = getAccessibilityLabelIssueCount(results);
console.log(`Interactive Element Accessibility Label Issues Found: ${accessibilityLabelIssueCount}`);
assert.strictEqual(accessibilityLabelIssueCount < 50, true, `Accessibility Label issue count exceeded threshold! Found: ${accessibilityLabelIssueCount}`);
...
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!