Skip to content

Commit e756233

Browse files
authored
feat(roll): roll Playwright to v1.44.0 (#2433)
1 parent 8dc3978 commit e756233

27 files changed

+1816
-346
lines changed

README.md

+2-2
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 -->124.0.6367.29<!-- GEN:stop --> ||||
7+
| Chromium <!-- GEN:chromium-version -->125.0.6422.26<!-- GEN:stop --> ||||
88
| WebKit <!-- GEN:webkit-version -->17.4<!-- GEN:stop --> ||||
9-
| Firefox <!-- GEN:firefox-version -->124.0<!-- GEN:stop --> ||||
9+
| Firefox <!-- GEN:firefox-version -->125.0.1<!-- GEN:stop --> ||||
1010

1111
## Documentation
1212

ROLLING.md

+7
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,10 @@
1414
* generate API: `./scripts/update_api.sh`
1515
* commit changes & send PR
1616
* wait for bots to pass & merge the PR
17+
18+
19+
## Fix typing issues with Playwright ToT
20+
21+
1. `cd playwright`
22+
1. `API_JSON_MODE=1 node utils/doclint/generateApiJson.js > ../playwright-python/playwright/driver/package/api.json`
23+
1. `./scripts/update_api.sh`

playwright/_impl/_assertions.py

+80-6
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@
1616
from typing import Any, List, Optional, Pattern, Sequence, Union
1717
from urllib.parse import urljoin
1818

19-
from playwright._impl._api_structures import ExpectedTextValue, FrameExpectOptions
19+
from playwright._impl._api_structures import (
20+
AriaRole,
21+
ExpectedTextValue,
22+
FrameExpectOptions,
23+
)
2024
from playwright._impl._connection import format_call_log
2125
from playwright._impl._errors import Error
2226
from playwright._impl._fetch import APIResponse
@@ -92,10 +96,10 @@ def _not(self) -> "PageAssertions":
9296
async def to_have_title(
9397
self, titleOrRegExp: Union[Pattern[str], str], timeout: float = None
9498
) -> None:
99+
__tracebackhide__ = True
95100
expected_values = to_expected_text_values(
96101
[titleOrRegExp], normalize_white_space=True
97102
)
98-
__tracebackhide__ = True
99103
await self._expect_impl(
100104
"to.have.title",
101105
FrameExpectOptions(expectedText=expected_values, timeout=timeout),
@@ -110,13 +114,16 @@ async def not_to_have_title(
110114
await self._not.to_have_title(titleOrRegExp, timeout)
111115

112116
async def to_have_url(
113-
self, urlOrRegExp: Union[str, Pattern[str]], timeout: float = None
117+
self,
118+
urlOrRegExp: Union[str, Pattern[str]],
119+
timeout: float = None,
120+
ignoreCase: bool = None,
114121
) -> None:
115122
__tracebackhide__ = True
116123
base_url = self._actual_page.context._options.get("baseURL")
117124
if isinstance(urlOrRegExp, str) and base_url:
118125
urlOrRegExp = urljoin(base_url, urlOrRegExp)
119-
expected_text = to_expected_text_values([urlOrRegExp])
126+
expected_text = to_expected_text_values([urlOrRegExp], ignoreCase=ignoreCase)
120127
await self._expect_impl(
121128
"to.have.url",
122129
FrameExpectOptions(expectedText=expected_text, timeout=timeout),
@@ -125,10 +132,13 @@ async def to_have_url(
125132
)
126133

127134
async def not_to_have_url(
128-
self, urlOrRegExp: Union[Pattern[str], str], timeout: float = None
135+
self,
136+
urlOrRegExp: Union[Pattern[str], str],
137+
timeout: float = None,
138+
ignoreCase: bool = None,
129139
) -> None:
130140
__tracebackhide__ = True
131-
await self._not.to_have_url(urlOrRegExp, timeout)
141+
await self._not.to_have_url(urlOrRegExp, timeout, ignoreCase)
132142

133143

134144
class LocatorAssertions(AssertionsBase):
@@ -704,6 +714,70 @@ async def not_to_be_in_viewport(
704714
__tracebackhide__ = True
705715
await self._not.to_be_in_viewport(ratio=ratio, timeout=timeout)
706716

717+
async def to_have_accessible_description(
718+
self,
719+
description: Union[str, Pattern[str]],
720+
ignoreCase: bool = None,
721+
timeout: float = None,
722+
) -> None:
723+
__tracebackhide__ = True
724+
expected_values = to_expected_text_values([description], ignoreCase=ignoreCase)
725+
await self._expect_impl(
726+
"to.have.accessible.description",
727+
FrameExpectOptions(expectedText=expected_values, timeout=timeout),
728+
None,
729+
"Locator expected to have accessible description",
730+
)
731+
732+
async def not_to_have_accessible_description(
733+
self,
734+
name: Union[str, Pattern[str]],
735+
ignoreCase: bool = None,
736+
timeout: float = None,
737+
) -> None:
738+
__tracebackhide__ = True
739+
await self._not.to_have_accessible_description(name, ignoreCase, timeout)
740+
741+
async def to_have_accessible_name(
742+
self,
743+
name: Union[str, Pattern[str]],
744+
ignoreCase: bool = None,
745+
timeout: float = None,
746+
) -> None:
747+
__tracebackhide__ = True
748+
expected_values = to_expected_text_values([name], ignoreCase=ignoreCase)
749+
await self._expect_impl(
750+
"to.have.accessible.name",
751+
FrameExpectOptions(expectedText=expected_values, timeout=timeout),
752+
None,
753+
"Locator expected to have accessible name",
754+
)
755+
756+
async def not_to_have_accessible_name(
757+
self,
758+
name: Union[str, Pattern[str]],
759+
ignoreCase: bool = None,
760+
timeout: float = None,
761+
) -> None:
762+
__tracebackhide__ = True
763+
await self._not.to_have_accessible_name(name, ignoreCase, timeout)
764+
765+
async def to_have_role(self, role: AriaRole, timeout: float = None) -> None:
766+
__tracebackhide__ = True
767+
if isinstance(role, Pattern):
768+
raise Error('"role" argument in to_have_role must be a string')
769+
expected_values = to_expected_text_values([role])
770+
await self._expect_impl(
771+
"to.have.role",
772+
FrameExpectOptions(expectedText=expected_values, timeout=timeout),
773+
None,
774+
"Locator expected to have accessible role",
775+
)
776+
777+
async def not_to_have_role(self, role: AriaRole, timeout: float = None) -> None:
778+
__tracebackhide__ = True
779+
await self._not.to_have_role(role, timeout)
780+
707781

708782
class APIResponseAssertions:
709783
def __init__(

playwright/_impl/_browser_context.py

+1
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,7 @@ def _on_close(self) -> None:
510510
self._browser._contexts.remove(self)
511511

512512
self._dispose_har_routers()
513+
self._tracing._reset_stack_counter()
513514
self.emit(BrowserContext.Events.Close, self)
514515

515516
async def close(self, reason: str = None) -> None:

playwright/_impl/_browser_type.py

+14-10
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,20 @@ async def connect(
218218
local_utils=self._connection.local_utils,
219219
)
220220
connection.mark_as_remote()
221+
222+
browser = None
223+
224+
def handle_transport_close(reason: Optional[str]) -> None:
225+
if browser:
226+
for context in browser.contexts:
227+
for page in context.pages:
228+
page._on_close()
229+
context._on_close()
230+
browser._on_close()
231+
connection.cleanup(reason)
232+
233+
transport.once("close", handle_transport_close)
234+
221235
connection._is_sync = self._connection._is_sync
222236
connection._loop.create_task(connection.run())
223237
playwright_future = connection.playwright_future
@@ -240,16 +254,6 @@ async def connect(
240254
self._did_launch_browser(browser)
241255
browser._should_close_connection_on_close = True
242256

243-
def handle_transport_close() -> None:
244-
for context in browser.contexts:
245-
for page in context.pages:
246-
page._on_close()
247-
context._on_close()
248-
browser._on_close()
249-
connection.cleanup()
250-
251-
transport.once("close", handle_transport_close)
252-
253257
return browser
254258

255259
def _did_create_context(

playwright/_impl/_connection.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -284,10 +284,8 @@ async def stop_async(self) -> None:
284284
await self._transport.wait_until_stopped()
285285
self.cleanup()
286286

287-
def cleanup(self, cause: Exception = None) -> None:
288-
self._closed_error = (
289-
TargetClosedError(str(cause)) if cause else TargetClosedError()
290-
)
287+
def cleanup(self, cause: str = None) -> None:
288+
self._closed_error = TargetClosedError(cause) if cause else TargetClosedError()
291289
if self._init_task and not self._init_task.done():
292290
self._init_task.cancel()
293291
for ws_connection in self._child_ws_connections:
@@ -305,7 +303,7 @@ def call_on_object_with_known_name(
305303
) -> None:
306304
self._waiting_for_object[guid] = callback
307305

308-
def set_in_tracing(self, is_tracing: bool) -> None:
306+
def set_is_tracing(self, is_tracing: bool) -> None:
309307
if is_tracing:
310308
self._tracing_count += 1
311309
else:

playwright/_impl/_fetch.py

+1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ def __init__(
9696

9797
async def dispose(self) -> None:
9898
await self._channel.send("dispose")
99+
self._tracing._reset_stack_counter()
99100

100101
async def delete(
101102
self,

playwright/_impl/_helper.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
ForcedColors = Literal["active", "none", "null"]
5858
ReducedMotion = Literal["no-preference", "null", "reduce"]
5959
DocumentLoadState = Literal["commit", "domcontentloaded", "load", "networkidle"]
60-
KeyboardModifier = Literal["Alt", "Control", "Meta", "Shift"]
60+
KeyboardModifier = Literal["Alt", "Control", "ControlOrMeta", "Meta", "Shift"]
6161
MouseButton = Literal["left", "middle", "right"]
6262
ServiceWorkersPolicy = Literal["allow", "block"]
6363
HarMode = Literal["full", "minimal"]

playwright/_impl/_json_pipe.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@
1313
# limitations under the License.
1414

1515
import asyncio
16-
from typing import Dict, cast
16+
from typing import Dict, Optional, cast
1717

1818
from pyee.asyncio import AsyncIOEventEmitter
1919

2020
from playwright._impl._connection import Channel
21+
from playwright._impl._errors import TargetClosedError
2122
from playwright._impl._helper import Error, ParsedMessagePayload
2223
from playwright._impl._transport import Transport
2324

@@ -53,8 +54,10 @@ def handle_message(message: Dict) -> None:
5354
return
5455
self.on_message(cast(ParsedMessagePayload, message))
5556

56-
def handle_closed() -> None:
57-
self.emit("close")
57+
def handle_closed(reason: Optional[str]) -> None:
58+
self.emit("close", reason)
59+
if reason:
60+
self.on_error_future.set_exception(TargetClosedError(reason))
5861
self._stopped_future.set_result(None)
5962

6063
self._pipe_channel.on(
@@ -63,7 +66,7 @@ def handle_closed() -> None:
6366
)
6467
self._pipe_channel.on(
6568
"closed",
66-
lambda _: handle_closed(),
69+
lambda params: handle_closed(params.get("reason")),
6770
)
6871

6972
async def run(self) -> None:

playwright/_impl/_locator.py

+3
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ async def _with_element(
116116
finally:
117117
await handle.dispose()
118118

119+
def _equals(self, locator: "Locator") -> bool:
120+
return self._frame == locator._frame and self._selector == locator._selector
121+
119122
@property
120123
def page(self) -> "Page":
121124
return self._frame.page

0 commit comments

Comments
 (0)