-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Expand file tree
/
Copy pathAccessibilityReport.java
More file actions
130 lines (104 loc) · 5.04 KB
/
AccessibilityReport.java
File metadata and controls
130 lines (104 loc) · 5.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
///usr/bin/env jbang "$0" "$@" ; exit $?
//DEPS com.github:copilot-sdk-java:0.2.1-java.1
import com.github.copilot.sdk.*;
import com.github.copilot.sdk.events.*;
import com.github.copilot.sdk.json.*;
import java.io.*;
import java.util.*;
import java.util.concurrent.*;
/**
* Accessibility Report Generator — analyzes web pages using the Playwright MCP server
* and generates WCAG-compliant accessibility reports.
*
* Usage:
* jbang AccessibilityReport.java
*/
public class AccessibilityReport {
public static void main(String[] args) throws Exception {
System.out.println("=== Accessibility Report Generator ===\n");
var reader = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter URL to analyze: ");
String urlLine = reader.readLine();
if (urlLine == null) {
System.out.println("No URL provided. Exiting.");
return;
}
String url = urlLine.trim();
if (url.isEmpty()) {
System.out.println("No URL provided. Exiting.");
return;
}
if (!url.startsWith("http://") && !url.startsWith("https://")) {
url = "https://" + url;
}
System.out.printf("%nAnalyzing: %s%n", url);
System.out.println("Please wait...\n");
try (var client = new CopilotClient()) {
client.start().get();
// Configure Playwright MCP server for browser automation
Map<String, Object> mcpConfig = Map.of(
"type", "local",
"command", "npx",
"args", List.of("@playwright/mcp@latest"),
"tools", List.of("*")
);
var session = client.createSession(
new SessionConfig()
.setOnPermissionRequest(PermissionHandler.APPROVE_ALL)
.setModel("claude-opus-4.6")
.setStreaming(true)
.setMcpServers(Map.of("playwright", mcpConfig))
).get();
// Stream output token-by-token
var idleLatch = new CountDownLatch(1);
session.on(AssistantMessageDeltaEvent.class,
ev -> System.out.print(ev.getData().deltaContent()));
session.on(SessionIdleEvent.class,
ev -> idleLatch.countDown());
session.on(SessionErrorEvent.class, ev -> {
System.err.printf("%nError: %s%n", ev.getData().message());
idleLatch.countDown();
});
String prompt = """
Use the Playwright MCP server to analyze the accessibility of this webpage: %s
Please:
1. Navigate to the URL using playwright-browser_navigate
2. Take an accessibility snapshot using playwright-browser_snapshot
3. Analyze the snapshot and provide a detailed accessibility report
Format the report with emoji indicators:
- 📊 Accessibility Report header
- ✅ What's Working Well (table with Category, Status, Details)
- ⚠️ Issues Found (table with Severity, Issue, WCAG Criterion, Recommendation)
- 📋 Stats Summary (links, headings, focusable elements, landmarks)
- ⚙️ Priority Recommendations
Use ✅ for pass, 🔴 for high severity issues, 🟡 for medium severity, ❌ for missing items.
Include actual findings from the page analysis.
""".formatted(url);
session.send(new MessageOptions().setPrompt(prompt));
idleLatch.await();
System.out.println("\n\n=== Report Complete ===\n");
// Prompt user for test generation
System.out.print("Would you like to generate Playwright accessibility tests? (y/n): ");
String generateTestsLine = reader.readLine();
String generateTests = generateTestsLine == null ? "" : generateTestsLine.trim();
if (generateTests.equalsIgnoreCase("y") || generateTests.equalsIgnoreCase("yes")) {
var testLatch = new CountDownLatch(1);
session.on(SessionIdleEvent.class,
ev -> testLatch.countDown());
String testPrompt = """
Based on the accessibility report you just generated for %s,
create Playwright accessibility tests in Java.
Include tests for: lang attribute, title, heading hierarchy, alt text,
landmarks, skip navigation, focus indicators, and touch targets.
Use Playwright's accessibility testing features with helpful comments.
Output the complete test file.
""".formatted(url);
System.out.println("\nGenerating accessibility tests...\n");
session.send(new MessageOptions().setPrompt(testPrompt));
testLatch.await();
System.out.println("\n\n=== Tests Generated ===");
}
session.close();
}
}
}