|
13 | 13 | # limitations under the License. |
14 | 14 |
|
15 | 15 | import asyncio |
16 | | -from asyncio import Future |
17 | 16 |
|
18 | 17 | import pytest |
19 | 18 |
|
|
22 | 21 |
|
23 | 22 |
|
24 | 23 | async def test_should_fire(page: Page, server): |
25 | | - on_dialog_actions_complete: Future[None] = asyncio.Future() |
| 24 | + result = [] |
26 | 25 |
|
27 | | - async def on_dialog(dialog: Dialog): |
| 26 | + def on_dialog(dialog: Dialog): |
| 27 | + result.append(True) |
28 | 28 | assert dialog.type == "alert" |
29 | 29 | assert dialog.defaultValue == "" |
30 | 30 | assert dialog.message == "yo" |
31 | | - on_dialog_actions_complete.set_result(await dialog.accept()) |
| 31 | + asyncio.create_task(dialog.accept()) |
32 | 32 |
|
33 | | - page.on("dialog", lambda dialog: asyncio.create_task(on_dialog(dialog))) |
| 33 | + page.on("dialog", on_dialog) |
34 | 34 | await page.evaluate("alert('yo')") |
35 | | - await on_dialog_actions_complete |
| 35 | + assert result |
36 | 36 |
|
37 | 37 |
|
38 | 38 | async def test_should_allow_accepting_prompts(page: Page, server): |
39 | | - on_dialog_actions_complete: Future[None] = asyncio.Future() |
| 39 | + result = [] |
40 | 40 |
|
41 | | - async def on_dialog(dialog: Dialog): |
| 41 | + def on_dialog(dialog: Dialog): |
| 42 | + result.append(True) |
42 | 43 | assert dialog.type == "prompt" |
43 | 44 | assert dialog.defaultValue == "yes." |
44 | 45 | assert dialog.message == "question?" |
45 | | - on_dialog_actions_complete.set_result(await dialog.accept("answer!")) |
| 46 | + asyncio.create_task(dialog.accept("answer!")) |
46 | 47 |
|
47 | | - page.on("dialog", lambda dialog: asyncio.create_task(on_dialog(dialog))) |
| 48 | + page.on("dialog", on_dialog) |
48 | 49 | assert await page.evaluate("prompt('question?', 'yes.')") == "answer!" |
49 | | - await on_dialog_actions_complete |
| 50 | + assert result |
50 | 51 |
|
51 | 52 |
|
52 | 53 | async def test_should_dismiss_the_prompt(page: Page, server): |
53 | | - on_dialog_actions_complete: Future[None] = asyncio.Future() |
| 54 | + result = [] |
54 | 55 |
|
55 | | - async def on_dialog(dialog: Dialog): |
56 | | - on_dialog_actions_complete.set_result(await dialog.dismiss()) |
| 56 | + def on_dialog(dialog: Dialog): |
| 57 | + result.append(True) |
| 58 | + asyncio.create_task(dialog.dismiss()) |
57 | 59 |
|
58 | | - page.on("dialog", lambda dialog: asyncio.create_task(on_dialog(dialog))) |
| 60 | + page.on("dialog", on_dialog) |
59 | 61 | assert await page.evaluate("prompt('question?')") is None |
60 | | - await on_dialog_actions_complete |
| 62 | + assert result |
61 | 63 |
|
62 | 64 |
|
63 | 65 | async def test_should_accept_the_confirm_prompt(page: Page, server): |
64 | | - on_dialog_actions_complete: Future[None] = asyncio.Future() |
| 66 | + result = [] |
65 | 67 |
|
66 | | - async def on_dialog(dialog: Dialog): |
67 | | - on_dialog_actions_complete.set_result(await dialog.accept()) |
| 68 | + def on_dialog(dialog: Dialog): |
| 69 | + result.append(True) |
| 70 | + asyncio.create_task(dialog.accept()) |
68 | 71 |
|
69 | | - page.on("dialog", lambda dialog: asyncio.create_task(on_dialog(dialog))) |
| 72 | + page.on("dialog", on_dialog) |
70 | 73 | assert await page.evaluate("confirm('boolean?')") is True |
71 | | - await on_dialog_actions_complete |
| 74 | + assert result |
72 | 75 |
|
73 | 76 |
|
74 | 77 | async def test_should_dismiss_the_confirm_prompt(page: Page, server): |
75 | | - on_dialog_actions_complete: Future[None] = asyncio.Future() |
| 78 | + result = [] |
76 | 79 |
|
77 | | - async def on_dialog(dialog: Dialog): |
78 | | - on_dialog_actions_complete.set_result(await dialog.dismiss()) |
| 80 | + def on_dialog(dialog: Dialog): |
| 81 | + result.append(True) |
| 82 | + asyncio.create_task(dialog.dismiss()) |
79 | 83 |
|
80 | | - page.on("dialog", lambda dialog: asyncio.create_task(on_dialog(dialog))) |
| 84 | + page.on("dialog", on_dialog) |
81 | 85 | assert await page.evaluate("confirm('boolean?')") is False |
82 | | - await on_dialog_actions_complete |
| 86 | + assert result |
83 | 87 |
|
84 | 88 |
|
85 | 89 | # TODO: Logger support not yet here |
|
0 commit comments