Skip to content

Commit 841df66

Browse files
authored
Merge pull request #3 from automated-a11y/feature/readme
Added Read Me
2 parents a7b0612 + 2a87c27 commit 841df66

File tree

8 files changed

+239
-1
lines changed

8 files changed

+239
-1
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License
2+
3+
Copyright (c) 2023 Sridhar Bandi.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

ReadMe.md

Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
## Accessibility Automation for Web Apps with Java and [Playwright](https://playwright.dev/).
2+
3+
### This project uses [HTML CodeSniffer](https://squizlabs.github.io/HTML_CodeSniffer/) and [Deque Axe](https://www.deque.com/)
4+
5+
**HTML CodeSniffer** : checks HTML source code and detects any Accessibility violations. Comes with standards that cover
6+
the three (A, AA & AAA) conformance levels of the W3C's Web Content Accessibility Guidelines (WCAG) 2.1 and the U.S.
7+
Section 508 legislation.
8+
9+
**Deque Axe** : World’s leading digital accessibility toolkit. Powerful and accurate accessibility toolkit can get you
10+
to 80% issue coverage, or more, during development.
11+
12+
[![jdk badge](https://img.shields.io/badge/jdk-8-green.svg)](http://www.oracle.com/technetwork/java/javase/downloads/index.html)
13+
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/14bf5ccecfb74e7b8a1e4dda85241e32)](https://www.codacy.com/gh/automated-a11y/java-a11y-playwright/dashboard?utm_source=github.com&utm_medium=referral&utm_content=automated-a11y/java-a11y-playwright&utm_campaign=Badge_Grade)
14+
[![Codacy Badge](https://app.codacy.com/project/badge/Coverage/14bf5ccecfb74e7b8a1e4dda85241e32)](https://www.codacy.com/gh/automated-a11y/java-a11y-playwright/dashboard?utm_source=github.com&utm_medium=referral&utm_content=automated-a11y/java-a11y-playwright&utm_campaign=Badge_Coverage)
15+
[![License badge](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)
16+
[![Contributer badge](https://img.shields.io/github/contributors/automated-a11y/java-a11y-playwright.svg)](https://github.com/automated-a11y/java-a11y-playwright/graphs/contributors)
17+
18+
### Features
19+
20+
1. Simple & Easy to use
21+
2. No need of prior knowledge on Accessibility
22+
3. Works with Java [Playwright](https://playwright.dev/)
23+
4. Rich Reporting
24+
5. Open source
25+
26+
### Getting Started
27+
28+
#### Using HTML CodeSniffer
29+
30+
Create object of `HtmlCsRunner` as below. `page` is instance of your single tab or a popup window within a browser
31+
context.
32+
33+
```java
34+
HtmlCsRunner htmlCsRunner=new HtmlCsRunner(page);
35+
```
36+
37+
Once after you navigated to any page/popup with Playwright execute Accessibility on that particular page/popup
38+
39+
```java
40+
htmlCsRunner.execute();
41+
```
42+
43+
The above `execute` will also generate `JSON Report` on accessibility issues at page/popup level
44+
45+
Once after all the tests executed, you can call the below method to generate consolidated `HTML Report` on accessibility
46+
issues
47+
48+
```java
49+
htmlCsRunner.generateHtmlReport();
50+
```
51+
52+
Below is junit example with reporting.
53+
54+
```java
55+
import com.microsoft.playwright.Browser;
56+
import com.microsoft.playwright.BrowserContext;
57+
import com.microsoft.playwright.Page;
58+
import com.microsoft.playwright.Playwright;
59+
import io.github.sridharbandi.pw.HtmlCsRunner;
60+
import org.junit.jupiter.api.*;
61+
62+
import java.io.IOException;
63+
64+
public class HtmlcsTest {
65+
private static HtmlCsRunner htmlCsRunner;
66+
static Playwright playwright;
67+
static Browser browser;
68+
69+
BrowserContext context;
70+
Page page;
71+
72+
@BeforeAll
73+
static void launchBrowser() {
74+
playwright = Playwright.create();
75+
browser = playwright.chromium().launch();
76+
}
77+
78+
@AfterAll
79+
static void closeBrowser() throws IOException {
80+
playwright.close();
81+
htmlCsRunner.generateHtmlReport();
82+
}
83+
84+
@BeforeEach
85+
void createContextAndPage() {
86+
context = browser.newContext();
87+
page = context.newPage();
88+
htmlCsRunner = new HtmlCsRunner(page);
89+
}
90+
91+
@AfterEach
92+
void closeContext() throws IOException {
93+
htmlCsRunner.execute();
94+
context.close();
95+
}
96+
97+
@Test
98+
public void googleTest() {
99+
page.navigate("https://www.google.com/");
100+
}
101+
102+
@Test
103+
public void stockTest() {
104+
page.navigate("https://www.istockphoto.com/");
105+
}
106+
}
107+
```
108+
109+
By default, it will check against `WCAG2AA` standards. However, you can configure it to standard you want to test with
110+
111+
```java
112+
htmlCsRunner.setStandard(HTMLCS.WCAG2A);
113+
```
114+
115+
HTML Reports will be generated under `./target/java-a11y/htmlcs` folder.
116+
117+
Below are the report screenshots
118+
119+
Consolidated Report
120+
121+
![Index](/readme/htmlcs_index.png)
122+
123+
Page Report
124+
125+
![Page](/readme/htmlcs_page.png)
126+
127+
#### Using Deque Axe
128+
129+
Create object of `AxeRunner` as below. `page` is instance of your single tab or a popup window within a browser context.
130+
131+
```java
132+
AxeRunner axeRunner=new AxeRunner(page);
133+
```
134+
135+
Once after you navigated to any page/popup with Playwright execute Accessibility on that particular page/popup
136+
137+
```java
138+
axeRunner.execute();
139+
```
140+
141+
The above `execute` will also generate `JSON Report` on accessibility issues at page/popup level
142+
143+
Once after all the tests executed, you can call the below method to generate consolidated `HTML Report` on accessibility
144+
issues
145+
146+
```java
147+
axeRunner.generateHtmlReport();
148+
```
149+
150+
Below is junit example with reporting.
151+
152+
```java
153+
import com.microsoft.playwright.Browser;
154+
import com.microsoft.playwright.BrowserContext;
155+
import com.microsoft.playwright.Page;
156+
import com.microsoft.playwright.Playwright;
157+
import io.github.sridharbandi.pw.AxeRunner;
158+
import org.junit.jupiter.api.*;
159+
160+
import java.io.IOException;
161+
162+
public class AxeTest {
163+
private static AxeRunner axeRunner;
164+
static Playwright playwright;
165+
static Browser browser;
166+
167+
BrowserContext context;
168+
Page page;
169+
170+
@BeforeAll
171+
static void launchBrowser() {
172+
playwright = Playwright.create();
173+
browser = playwright.chromium().launch();
174+
}
175+
176+
@AfterAll
177+
static void closeBrowser() throws IOException {
178+
playwright.close();
179+
axeRunner.generateHtmlReport();
180+
}
181+
182+
@BeforeEach
183+
void createContextAndPage() {
184+
context = browser.newContext();
185+
page = context.newPage();
186+
axeRunner = new AxeRunner(page);
187+
}
188+
189+
@AfterEach
190+
void closeContext() throws IOException {
191+
axeRunner.execute();
192+
context.close();
193+
}
194+
195+
@Test
196+
public void googleTest() {
197+
page.navigate("https://www.google.com/");
198+
}
199+
200+
@Test
201+
public void stockTest() {
202+
page.navigate("https://www.istockphoto.com/");
203+
}
204+
}
205+
```
206+
207+
HTML Reports will be generated under `./target/java-a11y/axe` folder.
208+
209+
Below are the report screenshots
210+
211+
Consolidated Report
212+
213+
![Index](/readme/axe_index.png)
214+
215+
Page Report
216+
217+
![Page](/readme/axe_page.png)

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>io.github.automated-a11y</groupId>
88
<artifactId>java-a11y-playwright</artifactId>
9-
<version>1.0.0</version>
9+
<version>1.0-SNAPSHOT</version>
1010

1111
<properties>
1212
<maven.compiler.source>8</maven.compiler.source>

readme/axe_index.png

191 KB
Loading

readme/axe_page.png

295 KB
Loading

readme/htmlcs_index.png

174 KB
Loading

readme/htmlcs_page.png

282 KB
Loading

0 commit comments

Comments
 (0)