17
17
18
18
import pytest
19
19
20
+ from playwright .async_api import Page
20
21
21
- async def test_accessibility_should_work (page , is_firefox , is_chromium ):
22
+
23
+ async def test_accessibility_should_work (
24
+ page : Page , is_firefox : bool , is_chromium : bool
25
+ ) -> None :
22
26
await page .set_content (
23
27
"""<head>
24
28
<title>Accessibility Test</title>
@@ -109,54 +113,62 @@ async def test_accessibility_should_work(page, is_firefox, is_chromium):
109
113
assert await page .accessibility .snapshot () == golden
110
114
111
115
112
- async def test_accessibility_should_work_with_regular_text (page , is_firefox ):
116
+ async def test_accessibility_should_work_with_regular_text (
117
+ page : Page , is_firefox : bool
118
+ ) -> None :
113
119
await page .set_content ("<div>Hello World</div>" )
114
120
snapshot = await page .accessibility .snapshot ()
121
+ assert snapshot
115
122
assert snapshot ["children" ][0 ] == {
116
123
"role" : "text leaf" if is_firefox else "text" ,
117
124
"name" : "Hello World" ,
118
125
}
119
126
120
127
121
- async def test_accessibility_roledescription (page ) :
128
+ async def test_accessibility_roledescription (page : Page ) -> None :
122
129
await page .set_content ('<p tabIndex=-1 aria-roledescription="foo">Hi</p>' )
123
130
snapshot = await page .accessibility .snapshot ()
131
+ assert snapshot
124
132
assert snapshot ["children" ][0 ]["roledescription" ] == "foo"
125
133
126
134
127
- async def test_accessibility_orientation (page ) :
135
+ async def test_accessibility_orientation (page : Page ) -> None :
128
136
await page .set_content (
129
137
'<a href="" role="slider" aria-orientation="vertical">11</a>'
130
138
)
131
139
snapshot = await page .accessibility .snapshot ()
140
+ assert snapshot
132
141
assert snapshot ["children" ][0 ]["orientation" ] == "vertical"
133
142
134
143
135
- async def test_accessibility_autocomplete (page ) :
144
+ async def test_accessibility_autocomplete (page : Page ) -> None :
136
145
await page .set_content ('<div role="textbox" aria-autocomplete="list">hi</div>' )
137
146
snapshot = await page .accessibility .snapshot ()
147
+ assert snapshot
138
148
assert snapshot ["children" ][0 ]["autocomplete" ] == "list"
139
149
140
150
141
- async def test_accessibility_multiselectable (page ) :
151
+ async def test_accessibility_multiselectable (page : Page ) -> None :
142
152
await page .set_content (
143
153
'<div role="grid" tabIndex=-1 aria-multiselectable=true>hey</div>'
144
154
)
145
155
snapshot = await page .accessibility .snapshot ()
156
+ assert snapshot
146
157
assert snapshot ["children" ][0 ]["multiselectable" ]
147
158
148
159
149
- async def test_accessibility_keyshortcuts (page ) :
160
+ async def test_accessibility_keyshortcuts (page : Page ) -> None :
150
161
await page .set_content (
151
162
'<div role="grid" tabIndex=-1 aria-keyshortcuts="foo">hey</div>'
152
163
)
153
164
snapshot = await page .accessibility .snapshot ()
165
+ assert snapshot
154
166
assert snapshot ["children" ][0 ]["keyshortcuts" ] == "foo"
155
167
156
168
157
169
async def test_accessibility_filtering_children_of_leaf_nodes_should_not_report_text_nodes_inside_controls (
158
- page , is_firefox
159
- ):
170
+ page : Page , is_firefox : bool
171
+ ) -> None :
160
172
await page .set_content (
161
173
"""
162
174
<div role="tablist">
@@ -179,13 +191,14 @@ async def test_accessibility_filtering_children_of_leaf_nodes_should_not_report_
179
191
# WebKit rich text accessibility is iffy
180
192
@pytest .mark .only_browser ("chromium" )
181
193
async def test_accessibility_plain_text_field_with_role_should_not_have_children (
182
- page , browser_channel
183
- ):
194
+ page : Page ,
195
+ ) -> None :
184
196
await page .set_content (
185
197
"""
186
198
<div contenteditable="plaintext-only" role='textbox'>Edit this image:<img src="fakeimage.png" alt="my fake image"></div>"""
187
199
)
188
200
snapshot = await page .accessibility .snapshot ()
201
+ assert snapshot
189
202
assert snapshot ["children" ][0 ] == {
190
203
"multiline" : True ,
191
204
"name" : "" ,
@@ -196,13 +209,14 @@ async def test_accessibility_plain_text_field_with_role_should_not_have_children
196
209
197
210
@pytest .mark .only_browser ("chromium" )
198
211
async def test_accessibility_plain_text_field_without_role_should_not_have_content (
199
- page , browser_channel
200
- ):
212
+ page : Page ,
213
+ ) -> None :
201
214
await page .set_content (
202
215
"""
203
216
<div contenteditable="plaintext-only">Edit this image:<img src="fakeimage.png" alt="my fake image"></div>"""
204
217
)
205
218
snapshot = await page .accessibility .snapshot ()
219
+ assert snapshot
206
220
assert snapshot ["children" ][0 ] == {
207
221
"name" : "" ,
208
222
"role" : "generic" ,
@@ -212,13 +226,14 @@ async def test_accessibility_plain_text_field_without_role_should_not_have_conte
212
226
213
227
@pytest .mark .only_browser ("chromium" )
214
228
async def test_accessibility_plain_text_field_with_tabindex_and_without_role_should_not_have_content (
215
- page , browser_channel
216
- ):
229
+ page : Page ,
230
+ ) -> None :
217
231
await page .set_content (
218
232
"""
219
233
<div contenteditable="plaintext-only" tabIndex=0>Edit this image:<img src="fakeimage.png" alt="my fake image"></div>"""
220
234
)
221
235
snapshot = await page .accessibility .snapshot ()
236
+ assert snapshot
222
237
assert snapshot ["children" ][0 ] == {
223
238
"name" : "" ,
224
239
"role" : "generic" ,
@@ -227,8 +242,8 @@ async def test_accessibility_plain_text_field_with_tabindex_and_without_role_sho
227
242
228
243
229
244
async def test_accessibility_non_editable_textbox_with_role_and_tabIndex_and_label_should_not_have_children (
230
- page , is_chromium , is_firefox
231
- ):
245
+ page : Page , is_chromium : bool , is_firefox : bool
246
+ ) -> None :
232
247
await page .set_content (
233
248
"""
234
249
<div role="textbox" tabIndex=0 aria-checked="true" aria-label="my favorite textbox">
@@ -255,12 +270,13 @@ async def test_accessibility_non_editable_textbox_with_role_and_tabIndex_and_lab
255
270
"value" : "this is the inner content " ,
256
271
}
257
272
snapshot = await page .accessibility .snapshot ()
273
+ assert snapshot
258
274
assert snapshot ["children" ][0 ] == golden
259
275
260
276
261
277
async def test_accessibility_checkbox_with_and_tabIndex_and_label_should_not_have_children (
262
- page ,
263
- ):
278
+ page : Page ,
279
+ ) -> None :
264
280
await page .set_content (
265
281
"""
266
282
<div role="checkbox" tabIndex=0 aria-checked="true" aria-label="my favorite checkbox">
@@ -270,12 +286,13 @@ async def test_accessibility_checkbox_with_and_tabIndex_and_label_should_not_hav
270
286
)
271
287
golden = {"role" : "checkbox" , "name" : "my favorite checkbox" , "checked" : True }
272
288
snapshot = await page .accessibility .snapshot ()
289
+ assert snapshot
273
290
assert snapshot ["children" ][0 ] == golden
274
291
275
292
276
293
async def test_accessibility_checkbox_without_label_should_not_have_children (
277
- page , is_firefox
278
- ):
294
+ page : Page , is_firefox : bool
295
+ ) -> None :
279
296
await page .set_content (
280
297
"""
281
298
<div role="checkbox" aria-checked="true">
@@ -289,10 +306,11 @@ async def test_accessibility_checkbox_without_label_should_not_have_children(
289
306
"checked" : True ,
290
307
}
291
308
snapshot = await page .accessibility .snapshot ()
309
+ assert snapshot
292
310
assert snapshot ["children" ][0 ] == golden
293
311
294
312
295
- async def test_accessibility_should_work_a_button (page ) :
313
+ async def test_accessibility_should_work_a_button (page : Page ) -> None :
296
314
await page .set_content ("<button>My Button</button>" )
297
315
298
316
button = await page .query_selector ("button" )
@@ -302,7 +320,7 @@ async def test_accessibility_should_work_a_button(page):
302
320
}
303
321
304
322
305
- async def test_accessibility_should_work_an_input (page ) :
323
+ async def test_accessibility_should_work_an_input (page : Page ) -> None :
306
324
await page .set_content ('<input title="My Input" value="My Value">' )
307
325
308
326
input = await page .query_selector ("input" )
@@ -313,9 +331,7 @@ async def test_accessibility_should_work_an_input(page):
313
331
}
314
332
315
333
316
- async def test_accessibility_should_work_on_a_menu (
317
- page , is_webkit , is_chromium , browser_channel
318
- ):
334
+ async def test_accessibility_should_work_on_a_menu (page : Page ) -> None :
319
335
await page .set_content (
320
336
"""
321
337
<div role="menu" title="My Menu">
@@ -345,15 +361,15 @@ async def test_accessibility_should_work_on_a_menu(
345
361
346
362
347
363
async def test_accessibility_should_return_null_when_the_element_is_no_longer_in_DOM (
348
- page ,
349
- ):
364
+ page : Page ,
365
+ ) -> None :
350
366
await page .set_content ("<button>My Button</button>" )
351
367
button = await page .query_selector ("button" )
352
368
await page .eval_on_selector ("button" , "button => button.remove()" )
353
369
assert await page .accessibility .snapshot (root = button ) is None
354
370
355
371
356
- async def test_accessibility_should_show_uninteresting_nodes (page ) :
372
+ async def test_accessibility_should_show_uninteresting_nodes (page : Page ) -> None :
357
373
await page .set_content (
358
374
"""
359
375
<div id="root" role="textbox">
@@ -369,6 +385,7 @@ async def test_accessibility_should_show_uninteresting_nodes(page):
369
385
370
386
root = await page .query_selector ("#root" )
371
387
snapshot = await page .accessibility .snapshot (root = root , interesting_only = False )
388
+ assert snapshot
372
389
assert snapshot ["role" ] == "textbox"
373
390
assert "hello" in snapshot ["value" ]
374
391
assert "world" in snapshot ["value" ]
0 commit comments