Skip to main content
No Result Found

Add accessibility assertions in Automated tests

Add accessibility assertions in your regression suite using our accessibility issue functions.

We provide a function called getResultsSummary() 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

Terminal
Copy icon Copy
{
  issueCountBySeverity: { critical: 10, serious: 20, moderate: 30, minor: 40 },
  totalIssueCount: 100
}

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!");

Assertions based on accessibility issues

We provide a function called getResults() 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

Terminal
Copy icon Copy
[
  {
  affectedPage: 'https://bstackdemo.com/',
  component: 'SPAN#',
  description: 'Ensures the contrast between foreground and background colors meets WCAG 2 AA minimum contrast ratio thresholds',
  howToFix: 'Fix any of the following:\n' +
    '  Element has insufficient color contrast of 2.77 (foreground color: #9c9b9b, background color: #ffffff, font size: 10.5pt (14px), font weight: normal). Expected contrast ratio of 4.5:1',
  issueDetails: {
    cssSelector: '#\\31  > .shelf-item__price > .installment > span',
    htmlSnippet: '<span>or 9 x</span>'
  },
  issueTags: { bestPractice: false, experimental: false, needsReview: false },
  moreInfoLink: 'https://api-accessibility.browserstack.com/more-info/a11y-engine-2.0/color-contrast',
  name: 'Elements must meet minimum color contrast ratio thresholds',
  ruleId: 'color-contrast',
  severity: 'serious',
  wcagTags: 'WCAG 1.4.3'
}
]

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!"); 

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

Is this page helping you?

Yes
No

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!

Talk to an Expert
Download Copy Check Circle