1
1
# Java-a11y
2
2
## Accessibility Automation for Web Apps with Java and Selenium Webdriver.
3
3
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.
5
11
6
12
[ ![ 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" )
7
13
[ ![ 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
21
27
<dependency >
22
28
<groupId >io.github.sridharbandi</groupId >
23
29
<artifactId >java-a11y</artifactId >
24
- <version >2.1.4 </version >
30
+ <version >3.0.0 </version >
25
31
</dependency >
26
32
```
27
33
For gradle based project add the below dependency
28
34
```
29
- compile 'io.github.sridharbandi:java-a11y:2.1.4 '
35
+ compile 'io.github.sridharbandi:java-a11y:3.0.0 '
30
36
```
31
37
For non gradle/maven project download the jar from below mentioned link and add it to CLASSPATH for your project
32
38
33
39
[ https://github.com/sridharbandi/Java-a11y/releases ] ( https://github.com/sridharbandi/Java-a11y/releases )
34
40
35
41
### 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.
37
44
``` 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);;
48
46
```
49
47
50
48
Once after you navigated to any page/popup with Selenium Webdriver execute Accessibility on that particular page/popup
51
49
``` java
52
- accessibilityRunner. execute();
53
- // or you can pass report name
54
- accessibilityRunner. execute(" Google" );
50
+ htmlCsRunner. execute();
55
51
```
56
52
57
53
The above ` execute ` will also generate ` JSON Report ` on accessibility issues at page/popup level
58
54
59
55
Once after all the tests executed, you can call the below method to generate consolidated ` HTML Report ` on accessibility issues
60
56
``` java
61
- accessibilityRunner . generateHtmlReport();
57
+ htmlCsRunner . generateHtmlReport();
62
58
```
63
59
64
- This library can be used along with Junit, TestNG and Cucumber/JBehave.
65
-
66
60
Below is junit example with reporting.
67
61
68
62
``` java
69
- import AccessibilityRunner ;
63
+ import freemarker.template.TemplateException ;
70
64
import io.github.bonigarcia.wdm.ChromeDriverManager ;
71
- import io.github.sridharbandi.util.Standard ;
65
+ import io.github.sridharbandi.HtmlCsRunner ;
72
66
import org.junit.jupiter.api.AfterAll ;
73
67
import org.junit.jupiter.api.AfterEach ;
74
68
import org.junit.jupiter.api.BeforeEach ;
69
+ import org.junit.jupiter.api.Test ;
75
70
import org.openqa.selenium.WebDriver ;
76
71
import 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 ;
80
72
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 ;
83
76
84
77
/**
85
78
* A sample test to demonstrate
86
79
*/
87
- public class AccessibilityTest {
80
+ public class Example {
81
+
88
82
private WebDriver driver;
89
- private static AccessibilityRunner accessibilityRunner ;
83
+ private static HtmlCsRunner htmlCsRunner ;
90
84
91
85
@BeforeEach
92
86
public void beforeTest () {
93
87
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 ));
100
90
driver. manage(). window(). fullscreen();
101
- accessibilityRunner = new AccessibilityRunner (driver);
102
- accessibilityRunner. setStandard(Standard . WCAG2AA );
103
- }
91
+ htmlCsRunner = new HtmlCsRunner (driver);
104
92
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();
117
93
}
118
94
119
95
@AfterEach
120
- public void tearDown () {
96
+ public void tearDown () throws TemplateException , IOException , URISyntaxException {
97
+ htmlCsRunner. execute();
121
98
driver. quit();
122
99
}
123
100
124
101
@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/" );
127
114
}
128
115
}
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 )
129
134
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);;
130
139
```
131
140
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
133
142
``` 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();
141
144
```
142
145
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
144
149
``` java
145
- Accessibility . REPORT_PATH = System . getProperty( " user.dir " ) + " /target/accessibility " ;
150
+ axeRunner . generateHtmlReport() ;
146
151
```
147
152
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);
150
185
151
- #### Consolidated Report
152
- ![ Index] ( /readme/index.png )
186
+ }
153
187
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
+ }
156
193
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
+ }
158
198
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
161
215
216
+ Consolidated Report
162
217
218
+ ![ Index] ( /readme/axe_index.png )
163
219
220
+ Page Report
164
221
222
+ ![ Page] ( /readme/axe_page.png )
0 commit comments