-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathtest_accessibility.py
More file actions
128 lines (96 loc) · 5.38 KB
/
Copy pathtest_accessibility.py
File metadata and controls
128 lines (96 loc) · 5.38 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
import pytest
from playwright.sync_api import Page, expect
@pytest.mark.accessibility
def test_accessibility_iframe_titles(page: Page):
"""Test that PDF viewer iframes have proper titles for screen readers."""
expect(page.get_by_text("Test PDF Viewer with auto zoom (fit to width)")).to_be_visible()
# Check that PDF viewer iframe has proper title
iframe_components = page.locator('iframe[title="streamlit_pdf_viewer.streamlit_pdf_viewer"]')
expect(iframe_components).to_have_count(1)
# Verify that the iframe has the expected title
iframe = iframe_components.nth(0)
title = iframe.get_attribute('title')
assert title == "streamlit_pdf_viewer.streamlit_pdf_viewer", "Iframe should have proper title"
@pytest.mark.accessibility
def test_accessibility_keyboard_navigation(page: Page):
"""Test that PDF viewers are accessible via keyboard navigation."""
iframe_components = page.locator('iframe[title="streamlit_pdf_viewer.streamlit_pdf_viewer"]')
expect(iframe_components).to_have_count(1)
# Test keyboard navigation to the iframe
iframe = iframe_components.nth(0)
# Focus on the iframe
iframe.focus()
# Check that the iframe is focusable
focused_element = page.evaluate("document.activeElement")
assert focused_element is not None, "Iframe should be focusable"
@pytest.mark.accessibility
def test_accessibility_zoom_levels_for_visibility(page: Page):
"""Test that different zoom levels improve accessibility for users with visual impairments."""
iframe_components = page.locator('iframe[title="streamlit_pdf_viewer.streamlit_pdf_viewer"]')
expect(iframe_components).to_have_count(1)
# Test the PDF viewer
iframe_frame = page.frame_locator('iframe[title="streamlit_pdf_viewer.streamlit_pdf_viewer"]').nth(0)
canvas = iframe_frame.locator("canvas").first
# Wait for the canvas to be visible before getting bounding box
expect(canvas).to_be_visible()
canvas_box = canvas.bounding_box()
# Verify that the canvas has reasonable dimensions for accessibility
assert canvas_box is not None, "Canvas bounding box should be available"
assert canvas_box['width'] > 0, "Canvas should have positive width for accessibility"
assert canvas_box['height'] > 0, "Canvas should have positive height for accessibility"
@pytest.mark.accessibility
def test_accessibility_screen_reader_compatibility(page: Page):
"""Test that PDF viewers are compatible with screen readers."""
iframe_components = page.locator('iframe[title="streamlit_pdf_viewer.streamlit_pdf_viewer"]')
expect(iframe_components).to_have_count(1)
# Check that the iframe has proper ARIA attributes or is properly labeled
iframe = iframe_components.nth(0)
# Check for title attribute (already tested above)
title = iframe.get_attribute('title')
assert title is not None, "Iframe should have a title for screen readers"
# Check that the iframe is not hidden from screen readers
aria_hidden = iframe.get_attribute('aria-hidden')
assert aria_hidden != 'true', "Iframe should not be hidden from screen readers"
@pytest.mark.accessibility
def test_accessibility_high_contrast_mode(page: Page):
"""Test that PDF viewers work well in high contrast mode."""
# Simulate high contrast mode by adding CSS
page.add_style_tag(content="""
* {
filter: contrast(200%) !important;
}
""")
iframe_components = page.locator('iframe[title="streamlit_pdf_viewer.streamlit_pdf_viewer"]')
expect(iframe_components).to_have_count(1)
# Check that the viewer is still visible and functional in high contrast
iframe_frame = page.frame_locator('iframe[title="streamlit_pdf_viewer.streamlit_pdf_viewer"]').nth(0)
pdf_viewer = iframe_frame.locator('div[id="pdfViewer"]')
expect(pdf_viewer).to_be_visible()
# Check for canvas elements
canvas = pdf_viewer.locator("canvas").first
expect(canvas).to_be_visible()
@pytest.mark.accessibility
def test_accessibility_responsive_text_sizing(page: Page):
"""Test that PDF viewers respond well to different text sizes."""
# Test with different viewport sizes that might affect text rendering
viewports = [
{"width": 1920, "height": 1080}, # Large desktop
{"width": 375, "height": 667}, # Mobile
]
for viewport in viewports:
page.set_viewport_size(viewport)
page.wait_for_timeout(500)
iframe_components = page.locator('iframe[title="streamlit_pdf_viewer.streamlit_pdf_viewer"]')
expect(iframe_components).to_have_count(1)
# Check that the viewer remains accessible
iframe_frame = page.frame_locator('iframe[title="streamlit_pdf_viewer.streamlit_pdf_viewer"]').nth(0)
pdf_viewer = iframe_frame.locator('div[id="pdfViewer"]')
expect(pdf_viewer).to_be_visible()
# Check for canvas elements
canvas = pdf_viewer.locator("canvas").first
expect(canvas).to_be_visible()
# Verify canvas has reasonable dimensions for accessibility
canvas_box = canvas.bounding_box()
assert canvas_box is not None, f"Canvas bounding box should be available at viewport {viewport}"
assert canvas_box['width'] > 0, f"Canvas should be visible at viewport {viewport}"
assert canvas_box['height'] > 0, f"Canvas should have positive height at viewport {viewport}"