Reading Time: <10 minutes

What’s up Guys! Welcome to automationcalling.com

Accessibility_Test_Automation

I wanted to give credits and would like to say a ton of Thanks to dequelabs who have been continuously researching on accessibility standards in terms of ADA, WCAG, Section 508, AODA, CVAA, made open source contribution on axe-core  and Thanks to contributor for https://github.com/dequelabs/axe-selenium-java

Alright! Before take a look on this blog I would recommend you to go through basic understanding of what is Accessibility testing, how to do manual and automation, what are all tools available for automation etc., Accessibility Test, Automation Tools & Comparison

Note: Please Keep it in mind Automation cannot be replaced to Manual test because 100% automation is impossible for Accessibility testing. According to Analysis, up to 30% Accessibility test can be automated.

This blog and test automation framework is developed & inspired based on https://github.com/dequelabs/axe-selenium-java and aXE-core API helper class. I built this framework with combination of Selenium Java, Cucumber JVM and BDD, however this is a base framework but I let give you an opportunity to enhance further based on your requirements.

Pre-requisites:

API

To run the example:

  1. Please make sure to add in resource folder either axe.js or axe.min.js which can be found in aXe-core API
  2. Add your application url in feature files
  3. Create necessary page objects based on your requirements, currently examples are available.
  4. mvn clean test to build and run the TestNG tests that drive Selenium against the application.

To use the AXE helper library in your framework:

<!-- https://mvnrepository.com/artifact/com.deque/axe-selenium -->
<dependency>
    <groupId>com.deque</groupId>
    <artifactId>axe-selenium</artifactId>
    <version>2.1</version>
</dependency>

Framework Implementation:

AccessibilityTestUtils is a builder class which was actually created top of AXE.builder class to support Cucumber JVM implementation for flexible data driven approach in cucumber data table.

public class AccessibiliyTestUtils {
    private WebDriver driver;
    private AXE.Builder builder;
    private JSONObject responseJSON;

    private URL scriptUrl = AccessibiliyTestUtils.class.getResource("/axe.js");

    public AccessibiliyTestUtils(WebDriver driver) {
        this.driver = driver;
        builder = new AXE.Builder(driver, scriptUrl);
    }


    public JSONObject runAnalyze() {
        responseJSON = builder.analyze();
        return responseJSON;
    }

    public JSONObject runAnalyzeWithSpecificWebElement(By locator) {
        responseJSON = builder.analyze(driver.findElement(locator));
        return responseJSON;
    }

    public AccessibiliyTestUtils skipFrame() {
        builder.skipFrames();
        return this;
    }

    public AccessibiliyTestUtils includeSelectors(String selector) {
        builder.include(selector);
        return this;
    }

    public AccessibiliyTestUtils excludeSelectors(String selector) {
        builder.exclude(selector);
        return this;
    }
  • Use AccessibiliyTestUtils constructor to inject js file on page which was initialized as driver.
  • runAnalyze: Will run accessibility test using AXE helper class.
  • runAnalyzeWithSpecificWebElement: Pass specific locator to analyze and run accessibility test. for eg., driver.findElement(By.name(“name”))
  • skipFrames prevents aXe to be recursively injected into all iframes.
  • includeSelectors  for eg., title, p, h1
  • excludeSelectors  for eg., title, p, h1

Feature File implementation:

Feature: This test about 508_WCAG Compliance Automation test with possible Scenarios covered by Selenium_Java_AXE

  Scenario: To Run full accessibility test using AXE API for the given page
    Given Launch chrome "chrome" with the given url "https://automationcalling.com/"
    When User navigate to "CONTACT" page.
    And Run accessibility test with the following param
      | FullTest | SkipFrames | WithOptions | includeSelector | excludeSelector | WithElement |
      | Yes      | No         | No          | No              | No              | No          |
    Then No Accessibiiity violation must be returned

  Scenario: To Run accessibility test using AXE API with include and exclude selector
    Given Launch chrome "chrome" with the given url "https://automationcalling.com/"
    When User navigate to "CONTACT" page.
    And Run accessibility test with the following param
      | FullTest | SkipFrames | WithOptions | includeSelector | excludeSelector | WithElement |
      | No       | No         | No          | title           | h1              | No          |
    Then No Accessibiiity violation must be returned

  Scenario: To Run accessibility test using AXE API with specific element
    Given Launch chrome "chrome" with the given url "https://automationcalling.com/"
    When User navigate to "CONTACT" page.
    And Run accessibility test with the following param
      | FullTest | SkipFrames | WithOptions | includeSelector | excludeSelector | WithElement  |
      | No       | No         | No          | No              | No              | name:g2-name |
    Then No Accessibiiity violation must be returned

To validate accessibility test automation, use the following steps:

Run accessibility test with the following param
  | FullTest | SkipFrames | WithOptions | includeSelector | excludeSelector | WithElement |
  | Yes      | No         | No          | No              | No              | No          |

To verify  no accessibility error, use the following steps:

No Accessibiiity violation must be returned

Accessibility Test Automation Cucumber results:

report1

report2

To play further with framework, please clone from GitHub: https://github.com/automationcalling/accessibilitytestautomation

Thanks for your time. Please subscribe automationcalling.com for more updates!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s