Skip to content

Commit 558941c

Browse files
committed
api
1 parent 75ceca0 commit 558941c

21 files changed

+582
-1029
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ Playwright is a Python library to automate [Chromium](https://www.chromium.org/H
44

55
| | Linux | macOS | Windows |
66
| :--- | :---: | :---: | :---: |
7-
| Chromium <!-- GEN:chromium-version -->141.0.7390.37<!-- GEN:stop --> ||||
7+
| Chromium <!-- GEN:chromium-version -->143.0.7499.4<!-- GEN:stop --> ||||
88
| WebKit <!-- GEN:webkit-version -->26.0<!-- GEN:stop --> ||||
9-
| Firefox <!-- GEN:firefox-version -->142.0.1<!-- GEN:stop --> ||||
9+
| Firefox <!-- GEN:firefox-version -->144.0.2<!-- GEN:stop --> ||||
1010

1111
## Documentation
1212

playwright/_impl/_accessibility.py

Lines changed: 0 additions & 69 deletions
This file was deleted.

playwright/_impl/_browser_context.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,10 +688,13 @@ def _on_request_finished(
688688

689689
def _on_console_message(self, event: Dict) -> None:
690690
message = ConsoleMessage(event, self._loop, self._dispatcher_fiber)
691-
self.emit(BrowserContext.Events.Console, message)
691+
worker = message.worker
692+
if worker:
693+
worker.emit(Worker.Events.Console, message)
692694
page = message.page
693695
if page:
694696
page.emit(Page.Events.Console, message)
697+
self.emit(BrowserContext.Events.Console, message)
695698

696699
def _on_dialog(self, dialog: Dialog) -> None:
697700
has_listeners = self.emit(BrowserContext.Events.Dialog, dialog)

playwright/_impl/_console_message.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
if TYPE_CHECKING: # pragma: no cover
2323
from playwright._impl._page import Page
24+
from playwright._impl._worker import Worker
2425

2526

2627
class ConsoleMessage:
@@ -31,6 +32,7 @@ def __init__(
3132
self._loop = loop
3233
self._dispatcher_fiber = dispatcher_fiber
3334
self._page: Optional["Page"] = from_nullable_channel(event.get("page"))
35+
self._worker: Optional["Worker"] = from_nullable_channel(event.get("worker"))
3436

3537
def __repr__(self) -> str:
3638
return f"<ConsoleMessage type={self.type} text={self.text}>"
@@ -76,3 +78,7 @@ def location(self) -> SourceLocation:
7678
@property
7779
def page(self) -> Optional["Page"]:
7880
return self._page
81+
82+
@property
83+
def worker(self) -> Optional["Worker"]:
84+
return self._worker

playwright/_impl/_element_handle.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ async def click(
138138
force: bool = None,
139139
noWaitAfter: bool = None,
140140
trial: bool = None,
141+
steps: int = None,
141142
) -> None:
142143
await self._channel.send(
143144
"click", self._frame._timeout, locals_to_params(locals())
@@ -153,6 +154,7 @@ async def dblclick(
153154
force: bool = None,
154155
noWaitAfter: bool = None,
155156
trial: bool = None,
157+
steps: int = None,
156158
) -> None:
157159
await self._channel.send(
158160
"dblclick", self._frame._timeout, locals_to_params(locals())

playwright/_impl/_frame.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,23 @@ async def click(
545545
noWaitAfter: bool = None,
546546
strict: bool = None,
547547
trial: bool = None,
548+
) -> None:
549+
await self._click(**locals_to_params(locals()))
550+
551+
async def _click(
552+
self,
553+
selector: str,
554+
modifiers: Sequence[KeyboardModifier] = None,
555+
position: Position = None,
556+
delay: float = None,
557+
button: MouseButton = None,
558+
clickCount: int = None,
559+
timeout: float = None,
560+
force: bool = None,
561+
noWaitAfter: bool = None,
562+
strict: bool = None,
563+
trial: bool = None,
564+
steps: int = None,
548565
) -> None:
549566
await self._channel.send("click", self._timeout, locals_to_params(locals()))
550567

@@ -734,6 +751,7 @@ async def drag_and_drop(
734751
strict: bool = None,
735752
timeout: float = None,
736753
trial: bool = None,
754+
steps: int = None,
737755
) -> None:
738756
await self._channel.send(
739757
"dragAndDrop", self._timeout, locals_to_params(locals())

playwright/_impl/_locator.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import json
1616
import pathlib
17+
import re
1718
from typing import (
1819
TYPE_CHECKING,
1920
Any,
@@ -155,9 +156,10 @@ async def click(
155156
force: bool = None,
156157
noWaitAfter: bool = None,
157158
trial: bool = None,
159+
steps: int = None,
158160
) -> None:
159161
params = locals_to_params(locals())
160-
return await self._frame.click(self._selector, strict=True, **params)
162+
return await self._frame._click(self._selector, strict=True, **params)
161163

162164
async def dblclick(
163165
self,
@@ -169,6 +171,7 @@ async def dblclick(
169171
force: bool = None,
170172
noWaitAfter: bool = None,
171173
trial: bool = None,
174+
steps: int = None,
172175
) -> None:
173176
params = locals_to_params(locals())
174177
return await self._frame.dblclick(self._selector, strict=True, **params)
@@ -343,6 +346,20 @@ def describe(self, description: str) -> "Locator":
343346
f"{self._selector} >> internal:describe={json.dumps(description)}",
344347
)
345348

349+
@property
350+
def description(self) -> Optional[str]:
351+
try:
352+
match = re.search(
353+
r' >> internal:describe=("(?:[^"\\]|\\.)*")$', self._selector
354+
)
355+
if match:
356+
description = json.loads(match.group(1))
357+
if isinstance(description, str):
358+
return description
359+
except (json.JSONDecodeError, ValueError):
360+
pass
361+
return None
362+
346363
def filter(
347364
self,
348365
hasText: Union[str, Pattern[str]] = None,
@@ -414,6 +431,7 @@ async def drag_to(
414431
trial: bool = None,
415432
sourcePosition: Position = None,
416433
targetPosition: Position = None,
434+
steps: int = None,
417435
) -> None:
418436
params = locals_to_params(locals())
419437
del params["target"]

playwright/_impl/_page.py

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
cast,
3434
)
3535

36-
from playwright._impl._accessibility import Accessibility
3736
from playwright._impl._api_structures import (
3837
AriaRole,
3938
FilePayload,
@@ -150,7 +149,6 @@ class Page(ChannelOwner):
150149
WebSocket="websocket",
151150
Worker="worker",
152151
)
153-
accessibility: Accessibility
154152
keyboard: Keyboard
155153
mouse: Mouse
156154
touchscreen: Touchscreen
@@ -160,7 +158,6 @@ def __init__(
160158
) -> None:
161159
super().__init__(parent, type, guid, initializer)
162160
self._browser_context = cast("BrowserContext", parent)
163-
self.accessibility = Accessibility(self._channel)
164161
self.keyboard = Keyboard(self._channel)
165162
self.mouse = Mouse(self._channel)
166163
self.touchscreen = Touchscreen(self._channel)
@@ -854,7 +851,7 @@ async def click(
854851
trial: bool = None,
855852
strict: bool = None,
856853
) -> None:
857-
return await self._main_frame.click(**locals_to_params(locals()))
854+
return await self._main_frame._click(**locals_to_params(locals()))
858855

859856
async def dblclick(
860857
self,
@@ -1017,6 +1014,7 @@ async def drag_and_drop(
10171014
timeout: float = None,
10181015
strict: bool = None,
10191016
trial: bool = None,
1017+
steps: int = None,
10201018
) -> None:
10211019
return await self._main_frame.drag_and_drop(**locals_to_params(locals()))
10221020

@@ -1452,12 +1450,13 @@ async def page_errors(self) -> List[Error]:
14521450

14531451

14541452
class Worker(ChannelOwner):
1455-
Events = SimpleNamespace(Close="close")
1453+
Events = SimpleNamespace(Close="close", Console="console")
14561454

14571455
def __init__(
14581456
self, parent: ChannelOwner, type: str, guid: str, initializer: Dict
14591457
) -> None:
14601458
super().__init__(parent, type, guid, initializer)
1459+
self._set_event_to_subscription_mapping({Worker.Events.Console: "console"})
14611460
self._channel.on("close", lambda _: self._on_close())
14621461
self._page: Optional[Page] = None
14631462
self._context: Optional["BrowserContext"] = None
@@ -1502,6 +1501,31 @@ async def evaluate_handle(
15021501
)
15031502
)
15041503

1504+
def expect_event(
1505+
self,
1506+
event: str,
1507+
predicate: Callable = None,
1508+
timeout: float = None,
1509+
) -> EventContextManagerImpl:
1510+
if timeout is None:
1511+
if self._page:
1512+
timeout = self._page._timeout_settings.timeout()
1513+
elif self._context:
1514+
timeout = self._context._timeout_settings.timeout()
1515+
else:
1516+
timeout = 30000
1517+
waiter = Waiter(self, f"worker.expect_event({event})")
1518+
waiter.reject_on_timeout(
1519+
cast(float, timeout),
1520+
f'Timeout {timeout}ms exceeded while waiting for event "{event}"',
1521+
)
1522+
if event != Worker.Events.Close:
1523+
waiter.reject_on_event(
1524+
self, Worker.Events.Close, lambda: TargetClosedError()
1525+
)
1526+
waiter.wait_for_event(self, event, predicate)
1527+
return EventContextManagerImpl(waiter.result())
1528+
15051529

15061530
class BindingCall(ChannelOwner):
15071531
def __init__(

playwright/async_api/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
from playwright._impl._assertions import PageAssertions as PageAssertionsImpl
3131
from playwright.async_api._context_manager import PlaywrightContextManager
3232
from playwright.async_api._generated import (
33-
Accessibility,
3433
APIRequest,
3534
APIRequestContext,
3635
APIResponse,
@@ -150,7 +149,6 @@ def __call__(
150149
__all__ = [
151150
"expect",
152151
"async_playwright",
153-
"Accessibility",
154152
"APIRequest",
155153
"APIRequestContext",
156154
"APIResponse",

0 commit comments

Comments
 (0)