Skip to content

Commit 4b4962c

Browse files
authored
tests: migrated some async tests over to sync (microsoft#132)
1 parent 359f8cc commit 4b4962c

18 files changed

+724
-27
lines changed

playwright/async_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def __str__(self) -> str:
5757
return self._impl_obj.__str__()
5858

5959
def _sync(self, future: asyncio.Future) -> Any:
60-
return asyncio.get_event_loop().run_until_complete(future)
60+
return self._loop.run_until_complete(future)
6161

6262
def _wrap_handler(self, handler: Any) -> Callable[..., None]:
6363
if callable(handler):

tests/async/test_console.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
import asyncio
1616
from typing import List
1717

18-
from playwright.console_message import ConsoleMessage
19-
from playwright.page import Page
18+
from playwright.async_api import ConsoleMessage, Page
2019

2120

2221
async def test_console_should_work(page: Page, server):

tests/async/test_dialog.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616

1717
import pytest
1818

19-
from playwright.dialog import Dialog
20-
from playwright.page import Page
19+
from playwright.async_api import Dialog, Page
2120

2221

2322
async def test_should_fire(page: Page, server):

tests/async/test_download.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
import pytest
2020

2121
from playwright import Error as PlaywrightError
22-
from playwright.browser import Browser
23-
from playwright.page import Page
22+
from playwright.async_api import Browser, Page
2423

2524

2625
def assert_file_content(path, content):

tests/async/test_geolocation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818
import pytest
1919

20+
from playwright import Error
2021
from playwright.async_api import BrowserContext, Page
21-
from playwright.helper import Error
2222

2323

2424
async def test_should_work(page: Page, server, context: BrowserContext):

tests/async/test_input.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import asyncio
1616
import os
1717

18-
from playwright.page import Page
18+
from playwright.async_api import Page
1919
from playwright.path_utils import get_file_dirname
2020

2121
_dirname = get_file_dirname()
@@ -69,7 +69,7 @@ async def test_should_set_from_memory(page):
6969
async def test_should_emit_event(page: Page, server):
7070
await page.setContent("<input type=file>")
7171
fc_done: asyncio.Future = asyncio.Future()
72-
page.once("filechooser", lambda file_chooser: fc_done.set_result(file_chooser)),
72+
page.once("filechooser", lambda file_chooser: fc_done.set_result(file_chooser))
7373
await page.click("input")
7474
file_chooser = await fc_done
7575
assert file_chooser

tests/async/test_interception.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@
1616

1717
import pytest
1818

19-
from playwright.async_api import Browser, Route
20-
from playwright.helper import Error
21-
from playwright.page import Page
19+
from playwright import Error
20+
from playwright.async_api import Browser, Page, Route
2221

2322

2423
async def test_page_route_should_intercept(page, server):

tests/async/test_launcher.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818
import pytest
1919

20-
from playwright.browser_type import BrowserType
21-
from playwright.helper import Error
20+
from playwright import Error
21+
from playwright.async_api import BrowserType
2222

2323

2424
async def test_browser_type_launch_should_reject_all_promises_when_browser_is_closed(

tests/async/test_navigation.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@
1919

2020
import pytest
2121

22-
from playwright import Error
23-
from playwright.helper import TimeoutError
24-
from playwright.network import Request
22+
from playwright import Error, TimeoutError
23+
from playwright.async_api import Request
2524

2625

2726
async def test_goto_should_work(page, server):

tests/async/test_network.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@
1919

2020
import pytest
2121

22-
from playwright.helper import Error
23-
from playwright.network import Request
24-
from playwright.page import Page
22+
from playwright import Error
23+
from playwright.async_api import Page, Request
2524

2625

2726
async def test_request_fulfill(page):

tests/async/test_pdf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
import pytest
1919

20-
from playwright.page import Page
20+
from playwright.async_api import Page
2121

2222

2323
@pytest.mark.only_browser("chromium")

tests/async/test_popup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
import asyncio
1616
from typing import List, cast
1717

18-
from playwright.browser import Browser, Page
19-
from playwright.network import Request, Route
18+
from playwright.async_api import Browser, Page, Request, Route
2019

2120

2221
async def test_link_navigation_inherit_user_agent_from_browser_context(

tests/async/test_queryselector.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import pytest
44

5-
from playwright.helper import Error
6-
from playwright.page import Page
5+
from playwright import Error
6+
from playwright.async_api import Page
77

88

99
async def test_selectors_register_should_work(selectors, page: Page, utils):

tests/async/test_worker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import pytest
1919

2020
from playwright import Error
21-
from playwright.page import Page, Worker
21+
from playwright.async_api import Page, Worker
2222

2323

2424
async def test_workers_page_workers(page, server):

0 commit comments

Comments
 (0)