Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added playwright/_impl/__init__.py
Empty file.
2 changes: 1 addition & 1 deletion playwright/_impl/_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions playwright/_impl/_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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")
Expand Down
6 changes: 2 additions & 4 deletions playwright/_impl/_wait_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion tests/async/test_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions tests/async/test_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
16 changes: 8 additions & 8 deletions tests/sync/test_element_handle_wait_for_element_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
def test_should_wait_for_visible(page):
page.set_content('<div id=div style="display:none">content</div>')
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()
Expand All @@ -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 id=div style="display:none">content</div>')
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
Expand All @@ -52,7 +52,7 @@ def test_should_throw_waiting_for_visible_when_detached(page):
def test_should_wait_for_hidden(page):
page.set_content("<div id=div>content</div>")
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()
Expand All @@ -67,7 +67,7 @@ def test_should_wait_for_already_hidden(page):
def test_should_wait_for_hidden_when_detached(page):
page.set_content("<div id=div>content</div>")
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()

Expand All @@ -76,15 +76,15 @@ def test_should_wait_for_enabled_button(page, server):
page.set_content("<button id=button disabled><span>Target</span></button>")
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()


def test_should_throw_waiting_for_enabled_when_detached(page):
page.set_content("<button id=button disabled>Target</button>")
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
Expand All @@ -94,15 +94,15 @@ def test_should_wait_for_disabled_button(page):
page.set_content("<button id=button><span>Target</span></button>")
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()


def test_should_wait_for_editable_input(page, server):
page.set_content("<input id=input readonly>")
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()