-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccessibilityChecker.py
More file actions
96 lines (80 loc) · 3.28 KB
/
AccessibilityChecker.py
File metadata and controls
96 lines (80 loc) · 3.28 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
import time
from Crawler import login, get_html, crawl, get_page
from GUI import get_user_info
from Queue import Queue
from Report import report
import os
from axe_selenium_python import Axe
def main():
username, password, elevance, suppress, continued = get_user_info()
driver = login(username, password, elevance)
# Output Directory
# Check for existing output directories
existing_output_dirs = [d for d in os.listdir('.') if os.path.isdir(d) and d.endswith(str(username) + "_output")]
if existing_output_dirs:
existing_output_dirs.sort(reverse=True)
print(f"Found existing output directories: {existing_output_dirs}")
output_dir = existing_output_dirs[0]
else:
output_dir = time.strftime("%Y_%m_%d__%H_%M_%S") + "_" + str(username) + "_output"
# Load Queue and CompletedList
queue = Queue(output_dir)
if queue.isEmpty():
print("Queue is empty. Starting from the homepage.")
driver = get_page(driver)
html = get_html(driver)
accessibility_output = accessibility(driver, suppress) # Check accessibility of the page
report(output_dir, driver, accessibility_output, driver.current_url, 0) # Generate report for the page
links = crawl(html, elevance)
for link in links:
queue.enqueue(link)
num = 0
while not queue.isEmpty():
if num > 5:
driver.quit()
driver = login(username, password, elevance)
num = 0
link, id_tracker = queue.dequeue()
try:
driver = get_page(driver, link=link)
print("Crawling:", link)
html = get_html(driver)
if html is not None and "mobilehealthconsumer.com" in driver.current_url:
print("Crawled:", driver.current_url)
accessibility_output = accessibility(driver, suppress) # Check accessibility of the page
report(output_dir, driver, accessibility_output, link, id_tracker) # Generate report for the page
print("Accessibility report generated for:", driver.current_url)
links = crawl(html, elevance)
for link in links:
queue.enqueue(link)
print("Queue Size:", queue.size())
print("---------------" * 5)
num += 1
except Exception as e:
print(f"An error occurred while crawling {link}:", e)
print("---------------" * 5)
continue
def accessibility(driver, suppress):
axe = Axe(driver)
axe.inject() # Inject axe-core JavaScript into the page
results = axe.run()
"""
Suppress known issues
"html-has-lang": {"enabled": False},
"landmark-one-main": {"enabled": False},
"region": {"enabled": False},
"color-contrast": {"enabled": False},
"page-has-heading-one": {"enabled": False}
"""
if suppress:
# Suppress known issues
new_violations = []
for issue in results["violations"]:
if issue["id"] in ["html-has-lang", "landmark-one-main", "region", "color-contrast", "page-has-heading-one"]:
pass
else:
new_violations.append(issue)
results["violations"] = new_violations
return results
if "__main__" == __name__:
main()