11# Java-a11y
22## Accessibility Automation for Web Apps with Java and Selenium Webdriver.
33
4- This project uses [ HTML_CodeSniffer] ( https://squizlabs.github.io/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.
4+ > Note If you are using version 2.1.4 and below, refer [ readme] ( /ReadMe_Pre.md )
5+
6+ ### This project uses [ HTML CodeSniffer] ( https://squizlabs.github.io/HTML_CodeSniffer/ ) and [ Deque Axe] ( https://www.deque.com/ )
7+
8+ ** HTML CodeSniffer** : 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.1 and the U.S. Section 508 legislation.
9+
10+ ** Deque Axe** : World’s leading digital accessibility toolkit. Powerful and accurate accessibility toolkit can get you to 80% issue coverage, or more, during development.
511
612[ ![ Maven Central] ( https://img.shields.io/maven-central/v/io.github.sridharbandi/java-a11y.svg )] ( http://search.maven.org/#search|ga|1|g:"io.github.sridharbandi" )
713[ ![ jdk badge] ( https://img.shields.io/badge/jdk-8-green.svg )] ( http://www.oracle.com/technetwork/java/javase/downloads/index.html )
@@ -21,144 +27,196 @@ For maven based project add the below dependency
2127<dependency >
2228 <groupId >io.github.sridharbandi</groupId >
2329 <artifactId >java-a11y</artifactId >
24- <version >2.1.4 </version >
30+ <version >3.0.0 </version >
2531</dependency >
2632```
2733For gradle based project add the below dependency
2834```
29- compile 'io.github.sridharbandi:java-a11y:2.1.4 '
35+ compile 'io.github.sridharbandi:java-a11y:3.0.0 '
3036```
3137For non gradle/maven project download the jar from below mentioned link and add it to CLASSPATH for your project
3238
3339[ https://github.com/sridharbandi/Java-a11y/releases ] ( https://github.com/sridharbandi/Java-a11y/releases )
3440
3541### Getting Started
36- 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
42+ #### Using HTML CodeSniffer
43+ Create object of ` HtmlCsRunner ` as below. ` driver ` will be your WebDriver instance.
3744``` java
38- ChromeOptions chromeOptions = new ChromeOptions ();
39- LoggingPreferences logPrefs = new LoggingPreferences ();
40- logPrefs. enable(LogType . BROWSER , Level . ALL );
41- chromeOptions. setCapability(" goog:loggingPrefs" , logPrefs);
42- WebDriver driver = new ChromeDriver (chromeOptions);
43- ```
44-
45- This library is very easy to use. Create object of ` AccessibilityRunner ` as below
46- ``` java
47- AccessibilityRunner accessibilityRunner = new AccessibilityRunner (driver);
45+ HtmlCsRunner htmlCsRunner = new HtmlCsRunner (driver);;
4846```
4947
5048Once after you navigated to any page/popup with Selenium Webdriver execute Accessibility on that particular page/popup
5149``` java
52- accessibilityRunner. execute();
53- // or you can pass report name
54- accessibilityRunner. execute(" Google" );
50+ htmlCsRunner. execute();
5551```
5652
5753The above ` execute ` will also generate ` JSON Report ` on accessibility issues at page/popup level
5854
5955Once after all the tests executed, you can call the below method to generate consolidated ` HTML Report ` on accessibility issues
6056``` java
61- accessibilityRunner . generateHtmlReport();
57+ htmlCsRunner . generateHtmlReport();
6258```
6359
64- This library can be used along with Junit, TestNG and Cucumber/JBehave.
65-
6660Below is junit example with reporting.
6761
6862``` java
69- import AccessibilityRunner ;
63+ import freemarker.template.TemplateException ;
7064import io.github.bonigarcia.wdm.ChromeDriverManager ;
71- import io.github.sridharbandi.util.Standard ;
65+ import io.github.sridharbandi.HtmlCsRunner ;
7266import org.junit.jupiter.api.AfterAll ;
7367import org.junit.jupiter.api.AfterEach ;
7468import org.junit.jupiter.api.BeforeEach ;
69+ import org.junit.jupiter.api.Test ;
7570import org.openqa.selenium.WebDriver ;
7671import org.openqa.selenium.chrome.ChromeDriver ;
77- import org.openqa.selenium.chrome.ChromeOptions ;
78- import org.openqa.selenium.logging.LogType ;
79- import org.openqa.selenium.logging.LoggingPreferences ;
8072
81- import java.util.concurrent.TimeUnit ;
82- import java.util.logging.Level ;
73+ import java.io.IOException ;
74+ import java.net.URISyntaxException ;
75+ import java.time.Duration ;
8376
8477/**
8578 * A sample test to demonstrate
8679 */
87- public class AccessibilityTest {
80+ public class Example {
81+
8882 private WebDriver driver;
89- private static AccessibilityRunner accessibilityRunner ;
83+ private static HtmlCsRunner htmlCsRunner ;
9084
9185 @BeforeEach
9286 public void beforeTest () {
9387 ChromeDriverManager . chromedriver(). setup();
94- ChromeOptions chromeOptions = new ChromeOptions ();
95- LoggingPreferences logPrefs = new LoggingPreferences ();
96- logPrefs. enable(LogType . BROWSER , Level . ALL );
97- chromeOptions. setCapability(" goog:loggingPrefs" , logPrefs);
98- driver = new ChromeDriver (chromeOptions);
99- driver. manage(). timeouts(). pageLoadTimeout(120 , TimeUnit . SECONDS );
88+ driver = new ChromeDriver ();
89+ driver. manage(). timeouts(). pageLoadTimeout(Duration . ofSeconds(60 ));
10090 driver. manage(). window(). fullscreen();
101- accessibilityRunner = new AccessibilityRunner (driver);
102- accessibilityRunner. setStandard(Standard . WCAG2AA );
103- }
91+ htmlCsRunner = new HtmlCsRunner (driver);
10492
105- @org . junit.jupiter.api. Test
106- public void googleTest () throws InterruptedException {
107- driver. get(" https://www.google.co.uk/" );
108- // executes accessibility on Google Search Page
109- accessibilityRunner. execute(" Google" );
110- }
111-
112- @org . junit.jupiter.api. Test
113- public void w3cschoolsTest () throws InterruptedException {
114- driver. get(" https://www.w3schools.com/" );
115- // executes accessibility on W3 Schools home Page
116- accessibilityRunner. execute();
11793 }
11894
11995 @AfterEach
120- public void tearDown () {
96+ public void tearDown () throws TemplateException , IOException , URISyntaxException {
97+ htmlCsRunner. execute();
12198 driver. quit();
12299 }
123100
124101 @AfterAll
125- public static void generateReport () {
126- accessibilityRunner. generateHtmlReport();
102+ public static void generateReport () throws IOException {
103+ htmlCsRunner. generateHtmlReport();
104+ }
105+
106+ @Test
107+ public void googleTest () {
108+ driver. get(" https://www.google.com/" );
109+ }
110+
111+ @Test
112+ public void stockTest () {
113+ driver. get(" https://www.istockphoto.com/" );
127114 }
128115}
116+ ```
117+
118+ By default, it will check against ` WCAG2AA ` standards. However, you can configure it to standard you want to test with
119+ ``` java
120+ htmlCsRunner. setStandard(HTMLCS. WCAG2A );
121+ ```
122+
123+ HTML Reports will be generated under ` ./target/java-a11y/htmlcs ` folder.
124+
125+ Below are the report screenshots
126+
127+ Consolidated Report
128+
129+ ![ Index] ( /readme/htmlcs_index.png )
130+
131+ Page Report
132+
133+ ![ Page] ( /readme/htmlcs_page.png )
129134
135+ #### Using Deque Axe
136+ Create object of ` AxeRunner ` as below. ` driver ` will be your WebDriver instance.
137+ ``` java
138+ AxeRunner axeRunner = new AxeRunner (driver);;
130139```
131140
132- By default it will check against ` WCAG2AA ` standards. However you can configure it to standard you want to test with
141+ Once after you navigated to any page/popup with Selenium Webdriver execute Accessibility on that particular page/popup
133142``` java
134- Accessibility . STANDARD = Standard . WCAG2AAA ;
135- // Or
136- Accessibility . STANDARD = Standard . WCAG2AA ;
137- // Or
138- Accessibility . STANDARD = Standard . WCAG2A ;
139- // Or
140- Accessibility . STANDARD = Standard . Section508 ;
143+ axeRunner. execute();
141144```
142145
143- By default it will save reports under project root in ` accessibility ` folder. However you can configure it where to save
146+ The above ` execute ` will also generate ` JSON Report ` on accessibility issues at page/popup level
147+
148+ Once after all the tests executed, you can call the below method to generate consolidated ` HTML Report ` on accessibility issues
144149``` java
145- Accessibility . REPORT_PATH = System . getProperty( " user.dir " ) + " /target/accessibility " ;
150+ axeRunner . generateHtmlReport() ;
146151```
147152
148- ### Reports
149- Below are the report screenshots
153+ Below is junit example with reporting.
154+
155+ ``` java
156+ import freemarker.template.TemplateException ;
157+ import io.github.bonigarcia.wdm.ChromeDriverManager ;
158+ import io.github.sridharbandi.AxeRunner ;
159+ import org.junit.jupiter.api.AfterAll ;
160+ import org.junit.jupiter.api.AfterEach ;
161+ import org.junit.jupiter.api.BeforeEach ;
162+ import org.junit.jupiter.api.Test ;
163+ import org.openqa.selenium.WebDriver ;
164+ import org.openqa.selenium.chrome.ChromeDriver ;
165+
166+ import java.io.IOException ;
167+ import java.net.URISyntaxException ;
168+ import java.time.Duration ;
169+
170+ /**
171+ * A sample test to demonstrate
172+ */
173+ public class Example {
174+
175+ private WebDriver driver;
176+ private static AxeRunner axeRunner;
177+
178+ @BeforeEach
179+ public void beforeTest () {
180+ ChromeDriverManager . chromedriver(). setup();
181+ driver = new ChromeDriver ();
182+ driver. manage(). timeouts(). pageLoadTimeout(Duration . ofSeconds(60 ));
183+ driver. manage(). window(). fullscreen();
184+ axeRunner = new AxeRunner (driver);
150185
151- #### Consolidated Report
152- ![ Index] ( /readme/index.png )
186+ }
153187
154- #### Page Report
155- ![ Page] ( /readme/page.png )
188+ @AfterEach
189+ public void tearDown () throws TemplateException , IOException , URISyntaxException {
190+ axeRunner. execute();
191+ driver. quit();
192+ }
156193
157- Complete example : [ https://github.com/sridharbandi/Java-a11y-example ] ( https://github.com/sridharbandi/Java-a11y-example )
194+ @AfterAll
195+ public static void generateReport () throws IOException {
196+ axeRunner. generateHtmlReport();
197+ }
158198
159- ### Todo
160- 1 . Remaining Unit tests
199+ @Test
200+ public void googleTest () {
201+ driver. get(" https://www.google.com/" );
202+ }
203+
204+ @Test
205+ public void stockTest () {
206+ driver. get(" https://www.istockphoto.com/" );
207+ }
208+
209+ }
210+ ```
211+
212+ HTML Reports will be generated under ` ./target/java-a11y/axe ` folder.
213+
214+ Below are the report screenshots
161215
216+ Consolidated Report
162217
218+ ![ Index] ( /readme/axe_index.png )
163219
220+ Page Report
164221
222+ ![ Page] ( /readme/axe_page.png )
0 commit comments