From b04f30e2b51a3569bbc5896457ad9cf3f06cd853 Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Wed, 15 Mar 2023 13:58:15 +0100 Subject: [PATCH 1/9] chore: roll Playwright to 1.32.0-alpha-mar-15-2023 --- README.md | 4 +- playwright/_impl/_browser_context.py | 16 +- playwright/_impl/_locator.py | 29 +- playwright/_impl/_page.py | 8 +- playwright/async_api/_generated.py | 482 ++++++++++++++------------- playwright/sync_api/_generated.py | 482 ++++++++++++++------------- scripts/expected_api_mismatch.txt | 1 - setup.py | 2 +- tests/async/test_element_handle.py | 8 +- tests/async/test_har.py | 21 ++ tests/async/test_locators.py | 69 +++- tests/sync/test_element_handle.py | 12 +- tests/sync/test_locators.py | 2 +- 13 files changed, 665 insertions(+), 471 deletions(-) diff --git a/README.md b/README.md index 3bd3ec79d..c7b9f0639 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,9 @@ Playwright is a Python library to automate [Chromium](https://www.chromium.org/H | | Linux | macOS | Windows | | :--- | :---: | :---: | :---: | -| Chromium 111.0.5563.19 | ✅ | ✅ | ✅ | +| Chromium 112.0.5615.20 | ✅ | ✅ | ✅ | | WebKit 16.4 | ✅ | ✅ | ✅ | -| Firefox 109.0 | ✅ | ✅ | ✅ | +| Firefox 110.0.1 | ✅ | ✅ | ✅ | ## Documentation diff --git a/playwright/_impl/_browser_context.py b/playwright/_impl/_browser_context.py index 4c1262e5f..7b4755237 100644 --- a/playwright/_impl/_browser_context.py +++ b/playwright/_impl/_browser_context.py @@ -61,6 +61,8 @@ locals_to_params, prepare_record_har_options, to_impl, + HarContentPolicy, + HarMode, ) from playwright._impl._network import Request, Response, Route, serialize_headers from playwright._impl._page import BindingCall, Page, Worker @@ -326,13 +328,15 @@ async def _record_into_har( har: Union[Path, str], page: Optional[Page] = None, url: Union[Pattern[str], str] = None, + content: HarContentPolicy = None, + mode: HarMode = None, ) -> None: params: Dict[str, Any] = { "options": prepare_record_har_options( { "recordHarPath": har, - "recordHarContent": "attach", - "recordHarMode": "minimal", + "recordHarContent": content or "attach", + "recordHarMode": mode or "minimal", "recordHarUrlFilter": url, } ) @@ -340,7 +344,7 @@ async def _record_into_har( if page: params["page"] = page._channel har_id = await self._channel.send("harStart", params) - self._har_recorders[har_id] = {"path": str(har), "content": "attach"} + self._har_recorders[har_id] = {"path": str(har), "content": content or "attach"} async def route_from_har( self, @@ -348,9 +352,13 @@ async def route_from_har( url: Union[Pattern[str], str] = None, not_found: RouteFromHarNotFoundPolicy = None, update: bool = None, + content: HarContentPolicy = None, + mode: HarMode = None, ) -> None: if update: - await self._record_into_har(har=har, page=None, url=url) + await self._record_into_har( + har=har, page=None, url=url, content=content, mode=mode + ) return router = await HarRouter.create( local_utils=self._connection.local_utils, diff --git a/playwright/_impl/_locator.py b/playwright/_impl/_locator.py index c70691c07..55b1df75a 100644 --- a/playwright/_impl/_locator.py +++ b/playwright/_impl/_locator.py @@ -44,6 +44,7 @@ MouseButton, locals_to_params, monotonic_time, + to_impl, ) from playwright._impl._js_handle import Serializable, parse_value, serialize_argument from playwright._impl._str_utils import ( @@ -207,13 +208,23 @@ async def clear( def locator( self, - selector: str, + selector_or_locator: Union[str, "Locator"], has_text: Union[str, Pattern[str]] = None, has: "Locator" = None, ) -> "Locator": + if isinstance(selector_or_locator, str): + return Locator( + self._frame, + f"{self._selector} >> {selector_or_locator}", + has_text=has_text, + has=has, + ) + selector_or_locator = to_impl(selector_or_locator) + if selector_or_locator._frame != self._frame: + raise Error("Locators must belong to the same frame.") return Locator( self._frame, - f"{self._selector} >> {selector}", + f"{self._selector} >> {selector_or_locator._selector}", has_text=has_text, has=has, ) @@ -663,13 +674,23 @@ def __init__(self, frame: "Frame", frame_selector: str) -> None: def locator( self, - selector: str, + selector_or_locator: Union["Locator", str], has_text: Union[str, Pattern[str]] = None, has: "Locator" = None, ) -> Locator: + if isinstance(selector_or_locator, str): + return Locator( + self._frame, + f"{self._frame_selector} >> internal:control=enter-frame >> {selector_or_locator}", + has_text=has_text, + has=has, + ) + selector_or_locator = to_impl(selector_or_locator) + if selector_or_locator._frame != self._frame: + raise ValueError("Locators must belong to the same frame.") return Locator( self._frame, - f"{self._frame_selector} >> internal:control=enter-frame >> {selector}", + f"{self._frame_selector} >> internal:control=enter-frame >> {selector_or_locator._selector}", has_text=has_text, has=has, ) diff --git a/playwright/_impl/_page.py b/playwright/_impl/_page.py index 22a8f72c6..897cfbc14 100644 --- a/playwright/_impl/_page.py +++ b/playwright/_impl/_page.py @@ -59,6 +59,8 @@ ColorScheme, DocumentLoadState, ForcedColors, + HarContentPolicy, + HarMode, KeyboardModifier, MouseButton, ReducedMotion, @@ -617,9 +619,13 @@ async def route_from_har( url: Union[Pattern[str], str] = None, not_found: RouteFromHarNotFoundPolicy = None, update: bool = None, + content: HarContentPolicy = None, + mode: HarMode = None, ) -> None: if update: - await self._browser_context._record_into_har(har=har, page=self, url=url) + await self._browser_context._record_into_har( + har=har, page=self, url=url, content=content, mode=mode + ) return router = await HarRouter.create( local_utils=self._connection.local_utils, diff --git a/playwright/async_api/_generated.py b/playwright/async_api/_generated.py index e8b8757ee..7dfcf336d 100644 --- a/playwright/async_api/_generated.py +++ b/playwright/async_api/_generated.py @@ -1943,8 +1943,8 @@ async def scroll_into_view_if_needed( Parameters ---------- timeout : Union[float, None] - Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed - by using the `browser_context.set_default_timeout()` or `page.set_default_timeout()` methods. + Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can + be changed by using the `browser_context.set_default_timeout()` or `page.set_default_timeout()` methods. """ return mapping.from_maybe_impl( @@ -1985,8 +1985,8 @@ async def hover( A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of the element. timeout : Union[float, None] - Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed - by using the `browser_context.set_default_timeout()` or `page.set_default_timeout()` methods. + Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can + be changed by using the `browser_context.set_default_timeout()` or `page.set_default_timeout()` methods. no_wait_after : Union[bool, None] Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as @@ -2052,8 +2052,8 @@ async def click( click_count : Union[int, None] defaults to 1. See [UIEvent.detail]. timeout : Union[float, None] - Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed - by using the `browser_context.set_default_timeout()` or `page.set_default_timeout()` methods. + Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can + be changed by using the `browser_context.set_default_timeout()` or `page.set_default_timeout()` methods. force : Union[bool, None] Whether to bypass the [actionability](../actionability.md) checks. Defaults to `false`. no_wait_after : Union[bool, None] @@ -2122,8 +2122,8 @@ async def dblclick( button : Union["left", "middle", "right", None] Defaults to `left`. timeout : Union[float, None] - Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed - by using the `browser_context.set_default_timeout()` or `page.set_default_timeout()` methods. + Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can + be changed by using the `browser_context.set_default_timeout()` or `page.set_default_timeout()` methods. force : Union[bool, None] Whether to bypass the [actionability](../actionability.md) checks. Defaults to `false`. no_wait_after : Union[bool, None] @@ -2208,8 +2208,8 @@ async def select_option( element : Union[ElementHandle, List[ElementHandle], None] Option elements to select. Optional. timeout : Union[float, None] - Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed - by using the `browser_context.set_default_timeout()` or `page.set_default_timeout()` methods. + Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can + be changed by using the `browser_context.set_default_timeout()` or `page.set_default_timeout()` methods. force : Union[bool, None] Whether to bypass the [actionability](../actionability.md) checks. Defaults to `false`. no_wait_after : Union[bool, None] @@ -2270,8 +2270,8 @@ async def tap( A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of the element. timeout : Union[float, None] - Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed - by using the `browser_context.set_default_timeout()` or `page.set_default_timeout()` methods. + Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can + be changed by using the `browser_context.set_default_timeout()` or `page.set_default_timeout()` methods. force : Union[bool, None] Whether to bypass the [actionability](../actionability.md) checks. Defaults to `false`. no_wait_after : Union[bool, None] @@ -2319,8 +2319,8 @@ async def fill( value : str Value to set for the ``, `