diff --git a/playwright/_impl/__init__.py b/playwright/_impl/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/playwright/_impl/_page.py b/playwright/_impl/_page.py index 5c71a692c..39cc154bb 100644 --- a/playwright/_impl/_page.py +++ b/playwright/_impl/_page.py @@ -850,7 +850,7 @@ def my_predicate(request: Request) -> bool: if matcher: return matcher.matches(request.url) if predicate: - return url_or_predicate(request) + return predicate(request) return True return self.expect_event( diff --git a/playwright/_impl/_stream.py b/playwright/_impl/_stream.py index a346bf7e5..b2663e330 100644 --- a/playwright/_impl/_stream.py +++ b/playwright/_impl/_stream.py @@ -14,7 +14,7 @@ import base64 from pathlib import Path -from typing import Dict +from typing import Dict, Union from playwright._impl._connection import ChannelOwner @@ -25,7 +25,7 @@ def __init__( ) -> None: super().__init__(parent, type, guid, initializer) - async def save_as(self, path: Path) -> None: + async def save_as(self, path: Union[str, Path]) -> None: with open(path, mode="wb") as file: while True: binary = await self._channel.send("read") diff --git a/playwright/_impl/_wait_helper.py b/playwright/_impl/_wait_helper.py index 896287cc6..a5ca59c41 100644 --- a/playwright/_impl/_wait_helper.py +++ b/playwright/_impl/_wait_helper.py @@ -15,17 +15,15 @@ import asyncio import uuid from asyncio.tasks import Task -from typing import Any, Callable, Generic, List, Tuple, TypeVar +from typing import Any, Callable, List, Tuple from pyee import EventEmitter from playwright._impl._api_types import Error, TimeoutError from playwright._impl._connection import ChannelOwner -T = TypeVar("T") - -class WaitHelper(Generic[T]): +class WaitHelper: def __init__(self, channel_owner: ChannelOwner, api_name: str) -> None: self._result: asyncio.Future = asyncio.Future() self._wait_id = uuid.uuid4().hex diff --git a/tests/async/test_download.py b/tests/async/test_download.py index b5dbb4f9d..0bc939505 100644 --- a/tests/async/test_download.py +++ b/tests/async/test_download.py @@ -64,7 +64,9 @@ async def test_should_report_downloads_with_accept_downloads_false(page: Page, s await download.path() except Error as exc: error = exc - assert "accept_downloads" in await download.failure() + failure_reason = await download.failure() + assert failure_reason + assert "accept_downloads" in failure_reason assert error assert "accept_downloads: True" in error.message diff --git a/tests/async/test_network.py b/tests/async/test_network.py index c8e50ddf6..1d9da9345 100644 --- a/tests/async/test_network.py +++ b/tests/async/test_network.py @@ -123,6 +123,7 @@ async def test_page_events_request_should_report_requests_and_responses_handled_ assert sw_response == "responseFromServiceWorker:foo" assert request.url == server.PREFIX + "/serviceworkers/fetchdummy/foo" response = await request.response() + assert response assert response.url == server.PREFIX + "/serviceworkers/fetchdummy/foo" assert await response.text() == "responseFromServiceWorker:foo" diff --git a/tests/sync/test_element_handle_wait_for_element_state.py b/tests/sync/test_element_handle_wait_for_element_state.py index b1f42c47a..c5604c2a7 100644 --- a/tests/sync/test_element_handle_wait_for_element_state.py +++ b/tests/sync/test_element_handle_wait_for_element_state.py @@ -20,7 +20,7 @@ def test_should_wait_for_visible(page): page.set_content('') div = page.query_selector("div") - page.evaluate('setTimeout(() => div.style.display = "block", 1000)') + page.evaluate('setTimeout(() => div.style.display = "block", 500)') assert div.is_visible() is False div.wait_for_element_state("visible") assert div.is_visible() @@ -43,7 +43,7 @@ def test_should_timeout_waiting_for_visible(page): def test_should_throw_waiting_for_visible_when_detached(page): page.set_content('') div = page.query_selector("div") - page.evaluate("setTimeout(() => div.remove(), 250)") + page.evaluate("setTimeout(() => div.remove(), 500)") with pytest.raises(Error) as exc_info: div.wait_for_element_state("visible") assert "Element is not attached to the DOM" in exc_info.value.message @@ -52,7 +52,7 @@ def test_should_throw_waiting_for_visible_when_detached(page): def test_should_wait_for_hidden(page): page.set_content("
content
") div = page.query_selector("div") - page.evaluate('setTimeout(() => div.style.display = "none", 250)') + page.evaluate('setTimeout(() => div.style.display = "none", 500)') assert div.is_hidden() is False div.wait_for_element_state("hidden") assert div.is_hidden() @@ -67,7 +67,7 @@ def test_should_wait_for_already_hidden(page): def test_should_wait_for_hidden_when_detached(page): page.set_content("
content
") div = page.query_selector("div") - page.evaluate("setTimeout(() => div.remove(), 250)") + page.evaluate("setTimeout(() => div.remove(), 500)") div.wait_for_element_state("hidden") assert div.is_hidden() @@ -76,7 +76,7 @@ def test_should_wait_for_enabled_button(page, server): page.set_content("") span = page.query_selector("text=Target") assert span.is_enabled() is False - page.evaluate("setTimeout(() => button.disabled = false, 250)") + page.evaluate("setTimeout(() => button.disabled = false, 500)") span.wait_for_element_state("enabled") assert span.is_enabled() @@ -84,7 +84,7 @@ def test_should_wait_for_enabled_button(page, server): def test_should_throw_waiting_for_enabled_when_detached(page): page.set_content("") button = page.query_selector("button") - page.evaluate("setTimeout(() => button.remove(), 250)") + page.evaluate("setTimeout(() => button.remove(), 500)") with pytest.raises(Error) as exc_info: button.wait_for_element_state("enabled") assert "Element is not attached to the DOM" in exc_info.value.message @@ -94,7 +94,7 @@ def test_should_wait_for_disabled_button(page): page.set_content("") span = page.query_selector("text=Target") assert span.is_disabled() is False - page.evaluate("setTimeout(() => button.disabled = true, 250)") + page.evaluate("setTimeout(() => button.disabled = true, 500)") span.wait_for_element_state("disabled") assert span.is_disabled() @@ -102,7 +102,7 @@ def test_should_wait_for_disabled_button(page): def test_should_wait_for_editable_input(page, server): page.set_content("") input = page.query_selector("input") - page.evaluate("setTimeout(() => input.readOnly = false, 250)") + page.evaluate("setTimeout(() => input.readOnly = false, 500)") assert input.is_editable() is False input.wait_for_element_state("editable") assert input.is_editable()