Skip to content

Latest commit

 

History

History
164 lines (132 loc) · 5.7 KB

ReadMe_Pre.md

File metadata and controls

164 lines (132 loc) · 5.7 KB

Java-a11y

Accessibility Automation for Web Apps with Java and Selenium Webdriver.

This project uses HTML_CodeSniffer that checks HTML source code and detects any Accessibility violations. Comes with standards that cover the three (A, AA & AAA) conformance levels of the W3C's Web Content Accessibility Guidelines (WCAG) 2.0 and the U.S. Section 508 legislation.

Maven Central jdk badge License badge Contributer badge

Features

  1. Simple & Easy to use
  2. No need of prior knowledge on Accessibility
  3. Works with Java Selenium Webdriver
  4. Rich Reporting
  5. Open source

Usage

For maven based project add the below dependency

<dependency>
  <groupId>io.github.sridharbandi</groupId>
  <artifactId>java-a11y</artifactId>
  <version>2.1.4</version>
</dependency>

For gradle based project add the below dependency

compile 'io.github.sridharbandi:java-a11y:2.1.4'

For non gradle/maven project download the jar from below mentioned link and add it to CLASSPATH for your project

https://github.com/sridharbandi/Java-a11y/releases

Getting Started

Make sure to enable logging capabilities to Webdriver is you are using the version 2.1.2 and below. Below is the example for Chromedriver

ChromeOptions chromeOptions = new ChromeOptions();
LoggingPreferences logPrefs = new LoggingPreferences();
logPrefs.enable(LogType.BROWSER, Level.ALL);
chromeOptions.setCapability("goog:loggingPrefs", logPrefs);
WebDriver driver = new ChromeDriver(chromeOptions);

This library is very easy to use. Create object of AccessibilityRunner as below

AccessibilityRunner accessibilityRunner = new AccessibilityRunner(driver);

Once after you navigated to any page/popup with Selenium Webdriver execute Accessibility on that particular page/popup

accessibilityRunner.execute();
//or you can pass report name
accessibilityRunner.execute("Google");

The above execute will also generate JSON Report on accessibility issues at page/popup level

Once after all the tests executed, you can call the below method to generate consolidated HTML Report on accessibility issues

accessibilityRunner.generateHtmlReport();

This library can be used along with Junit, TestNG and Cucumber/JBehave.

Below is junit example with reporting.

import AccessibilityRunner;
import io.github.bonigarcia.wdm.ChromeDriverManager;
import io.github.sridharbandi.util.Standard;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.logging.LogType;
import org.openqa.selenium.logging.LoggingPreferences;

import java.util.concurrent.TimeUnit;
import java.util.logging.Level;

/**
 * A sample test to demonstrate
 */
public class AccessibilityTest {
    private WebDriver driver;
    private static AccessibilityRunner accessibilityRunner;

    @BeforeEach
    public void beforeTest() {
        ChromeDriverManager.chromedriver().setup();
        ChromeOptions chromeOptions = new ChromeOptions();
        LoggingPreferences logPrefs = new LoggingPreferences();
        logPrefs.enable(LogType.BROWSER, Level.ALL);
        chromeOptions.setCapability("goog:loggingPrefs", logPrefs);
        driver = new ChromeDriver(chromeOptions);
        driver.manage().timeouts().pageLoadTimeout(120, TimeUnit.SECONDS);
        driver.manage().window().fullscreen();
        accessibilityRunner = new AccessibilityRunner(driver);
        accessibilityRunner.setStandard(Standard.WCAG2AA);
    }

    @org.junit.jupiter.api.Test
    public void googleTest() throws InterruptedException {
        driver.get("https://www.google.co.uk/");
        //executes accessibility on Google Search Page
        accessibilityRunner.execute("Google");
    }

    @org.junit.jupiter.api.Test
    public void w3cschoolsTest() throws InterruptedException {
        driver.get("https://www.w3schools.com/");
        //executes accessibility on W3 Schools home Page
        accessibilityRunner.execute();
    }

    @AfterEach
    public void tearDown() {
        driver.quit();
    }

    @AfterAll
    public static void generateReport() {
        accessibilityRunner.generateHtmlReport();
    }
}

By default it will check against WCAG2AA standards. However you can configure it to standard you want to test with

Accessibility.STANDARD = Standard.WCAG2AAA;
//Or
Accessibility.STANDARD = Standard.WCAG2AA;
//Or
Accessibility.STANDARD = Standard.WCAG2A;
//Or
Accessibility.STANDARD = Standard.Section508;

By default it will save reports under project root in accessibility folder. However you can configure it where to save

Accessibility.REPORT_PATH =  System.getProperty("user.dir")+"/target/accessibility";

Reports

Below are the report screenshots

Consolidated Report

Index

Page Report

Page

Complete example : https://github.com/sridharbandi/Java-a11y-example

Todo

  1. Remaining Unit tests