From 1a9f7401eb13e974ef199d8616dea6545af586c1 Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Thu, 10 Nov 2022 18:02:45 -0800 Subject: [PATCH 1/3] chore(roll): roll Playwright to 1.28.0-alpha-nov-11-2022 --- README.md | 2 +- playwright/_impl/_browser_context.py | 8 +++++ playwright/_impl/_connection.py | 20 +++++++++++++ playwright/_impl/_element_handle.py | 8 ----- playwright/_impl/_frame.py | 17 ----------- playwright/_impl/_page.py | 45 ++++++++-------------------- playwright/async_api/_generated.py | 6 ++-- playwright/sync_api/_generated.py | 6 ++-- scripts/documentation_provider.py | 2 -- setup.py | 2 +- tests/async/test_element_handle.py | 10 ------- tests/async/test_fill.py | 30 ------------------- tests/async/test_locators.py | 2 +- tests/async/test_page.py | 8 ----- tests/async/test_video.py | 1 + tests/sync/test_element_handle.py | 10 ------- tests/sync/test_fill.py | 29 +----------------- tests/sync/test_locators.py | 2 +- tests/sync/test_page.py | 8 ----- tests/sync/test_video.py | 3 +- 20 files changed, 55 insertions(+), 164 deletions(-) diff --git a/README.md b/README.md index 2731c3a28..93a5011bb 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Playwright is a Python library to automate [Chromium](https://www.chromium.org/H | | Linux | macOS | Windows | | :--- | :---: | :---: | :---: | -| Chromium 108.0.5359.22 | ✅ | ✅ | ✅ | +| Chromium 108.0.5359.29 | ✅ | ✅ | ✅ | | WebKit 16.0 | ✅ | ✅ | ✅ | | Firefox 106.0 | ✅ | ✅ | ✅ | diff --git a/playwright/_impl/_browser_context.py b/playwright/_impl/_browser_context.py index 2afbab914..07c9ae79e 100644 --- a/playwright/_impl/_browser_context.py +++ b/playwright/_impl/_browser_context.py @@ -163,6 +163,14 @@ def __init__( self.once( self.Events.Close, lambda context: self._closed_future.set_result(True) ) + self._set_event_to_subscription_mapping( + { + BrowserContext.Events.Request: "request", + BrowserContext.Events.Response: "response", + BrowserContext.Events.RequestFinished: "requestFinished", + BrowserContext.Events.RequestFailed: "requestFailed", + } + ) def __repr__(self) -> str: return f"" diff --git a/playwright/_impl/_connection.py b/playwright/_impl/_connection.py index fd15bc6e4..a22792b78 100644 --- a/playwright/_impl/_connection.py +++ b/playwright/_impl/_connection.py @@ -119,6 +119,8 @@ def __init__( if self._parent: self._parent._objects[guid] = self + self._event_to_subscription_mapping: Dict[str, str] = {} + def _dispose(self) -> None: # Clean up from parent and connection. if self._parent: @@ -135,6 +137,24 @@ def _adopt(self, child: "ChannelOwner") -> None: self._objects[child._guid] = child child._parent = self + def _set_event_to_subscription_mapping(self, mapping: Dict[str, str]) -> None: + self._event_to_subscription_mapping = mapping + + def _update_subscription(self, event: str, enabled: bool) -> None: + protocol_event = self._event_to_subscription_mapping.get(event) + if protocol_event: + self._channel.send_no_reply( + "updateSubscription", {"event": protocol_event, "enabled": enabled} + ) + + def _add_event_handler(self, event: str, k: Any, v: Any) -> None: + self._update_subscription(event, True) + super()._add_event_handler(event, k, v) + + def remove_listener(self, event: str, f: Any) -> None: + super().remove_listener(event, f) + self._update_subscription(event, len(self.listeners(event)) > 0) + class ProtocolCallback: def __init__(self, loop: asyncio.AbstractEventLoop) -> None: diff --git a/playwright/_impl/_element_handle.py b/playwright/_impl/_element_handle.py index 7e20dac1d..0cf33a160 100644 --- a/playwright/_impl/_element_handle.py +++ b/playwright/_impl/_element_handle.py @@ -218,14 +218,6 @@ async def type( ) -> None: await self._channel.send("type", locals_to_params(locals())) - async def clear( - self, - timeout: float = None, - noWaitAfter: bool = None, - force: bool = None, - ) -> None: - await self.fill("", **locals_to_params(locals())) - async def press( self, key: str, diff --git a/playwright/_impl/_frame.py b/playwright/_impl/_frame.py index 0f446b6f3..2ccb8da6c 100644 --- a/playwright/_impl/_frame.py +++ b/playwright/_impl/_frame.py @@ -794,22 +794,5 @@ async def set_checked( trial=trial, ) - async def clear( - self, - selector: str, - timeout: float = None, - noWaitAfter: bool = None, - force: bool = None, - strict: bool = None, - ) -> None: - await self.fill( - selector, - "", - timeout=timeout, - noWaitAfter=noWaitAfter, - force=force, - strict=strict, - ) - async def _highlight(self, selector: str) -> None: await self._channel.send("highlight", {"selector": selector}) diff --git a/playwright/_impl/_page.py b/playwright/_impl/_page.py index 2e4c27c7e..31b058f64 100644 --- a/playwright/_impl/_page.py +++ b/playwright/_impl/_page.py @@ -221,6 +221,16 @@ def __init__( else None, ) + self._set_event_to_subscription_mapping( + { + Page.Events.Request: "request", + Page.Events.Response: "response", + Page.Events.RequestFinished: "requestFinished", + Page.Events.RequestFailed: "requestFailed", + Page.Events.FileChooser: "fileChooser", + } + ) + def __repr__(self) -> str: return f"" @@ -294,20 +304,6 @@ def _on_video(self, params: Any) -> None: artifact = from_channel(params["artifact"]) cast(Video, self.video)._artifact_ready(artifact) - def _add_event_handler(self, event: str, k: Any, v: Any) -> None: - if event == Page.Events.FileChooser and len(self.listeners(event)) == 0: - self._channel.send_no_reply( - "setFileChooserInterceptedNoReply", {"intercepted": True} - ) - super()._add_event_handler(event, k, v) - - def remove_listener(self, event: str, f: Any) -> None: - super().remove_listener(event, f) - if event == Page.Events.FileChooser and len(self.listeners(event)) == 0: - self._channel.send_no_reply( - "setFileChooserInterceptedNoReply", {"intercepted": False} - ) - @property def context(self) -> "BrowserContext": return self._browser_context @@ -545,12 +541,14 @@ async def go_forward( async def emulate_media( self, - media: Literal["print", "screen"] = None, + media: Literal["null", "print", "screen"] = None, colorScheme: ColorScheme = None, reducedMotion: ReducedMotion = None, forcedColors: ForcedColors = None, ) -> None: params = locals_to_params(locals()) + if "media" in params: + params["media"] = "no-override" if params["media"] == "null" else media if "colorScheme" in params: params["colorScheme"] = ( "no-override" if params["colorScheme"] == "null" else colorScheme @@ -741,23 +739,6 @@ async def fill( ) -> None: return await self._main_frame.fill(**locals_to_params(locals())) - async def clear( - self, - selector: str, - timeout: float = None, - noWaitAfter: bool = None, - force: bool = None, - strict: bool = None, - ) -> None: - await self.fill( - selector, - "", - timeout=timeout, - noWaitAfter=noWaitAfter, - force=force, - strict=strict, - ) - def locator( self, selector: str, diff --git a/playwright/async_api/_generated.py b/playwright/async_api/_generated.py index 842544448..6a2b85aef 100644 --- a/playwright/async_api/_generated.py +++ b/playwright/async_api/_generated.py @@ -8499,7 +8499,7 @@ async def go_forward( async def emulate_media( self, *, - media: typing.Optional[Literal["print", "screen"]] = None, + media: typing.Optional[Literal["null", "print", "screen"]] = None, color_scheme: typing.Optional[ Literal["dark", "light", "no-preference", "null"] ] = None, @@ -8544,8 +8544,8 @@ async def emulate_media( Parameters ---------- - media : Union["print", "screen", None] - Changes the CSS media type of the page. The only allowed values are `'screen'`, `'print'` and `null`. Passing `null` + media : Union["null", "print", "screen", None] + Changes the CSS media type of the page. The only allowed values are `'Screen'`, `'Print'` and `'Null'`. Passing `'Null'` disables CSS media emulation. color_scheme : Union["dark", "light", "no-preference", "null", None] Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'`, `'dark'`, `'no-preference'`. Passing diff --git a/playwright/sync_api/_generated.py b/playwright/sync_api/_generated.py index 9fd929303..895a8c9cb 100644 --- a/playwright/sync_api/_generated.py +++ b/playwright/sync_api/_generated.py @@ -8534,7 +8534,7 @@ def go_forward( def emulate_media( self, *, - media: typing.Optional[Literal["print", "screen"]] = None, + media: typing.Optional[Literal["null", "print", "screen"]] = None, color_scheme: typing.Optional[ Literal["dark", "light", "no-preference", "null"] ] = None, @@ -8578,8 +8578,8 @@ def emulate_media( Parameters ---------- - media : Union["print", "screen", None] - Changes the CSS media type of the page. The only allowed values are `'screen'`, `'print'` and `null`. Passing `null` + media : Union["null", "print", "screen", None] + Changes the CSS media type of the page. The only allowed values are `'Screen'`, `'Print'` and `'Null'`. Passing `'Null'` disables CSS media emulation. color_scheme : Union["dark", "light", "no-preference", "null", None] Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'`, `'dark'`, `'no-preference'`. Passing diff --git a/scripts/documentation_provider.py b/scripts/documentation_provider.py index 6512965f7..0b3f0dc92 100644 --- a/scripts/documentation_provider.py +++ b/scripts/documentation_provider.py @@ -122,8 +122,6 @@ def print_entry( ) -> None: if class_name in ["BindingCall"] or method_name in [ "pid", - "_add_event_handler", - "remove_listener", ]: return original_method_name = method_name diff --git a/setup.py b/setup.py index d90f5c6c6..5f6d82c91 100644 --- a/setup.py +++ b/setup.py @@ -30,7 +30,7 @@ InWheel = None from wheel.bdist_wheel import bdist_wheel as BDistWheelCommand -driver_version = "1.28.0-alpha-1667504282000" +driver_version = "1.28.0-alpha-nov-11-2022" def extractall(zip: zipfile.ZipFile, path: str) -> None: diff --git a/tests/async/test_element_handle.py b/tests/async/test_element_handle.py index f900197b4..d47e6a78c 100644 --- a/tests/async/test_element_handle.py +++ b/tests/async/test_element_handle.py @@ -442,16 +442,6 @@ async def test_fill_input_when_Node_is_removed(page, server): assert await page.evaluate("result") == "some value" -async def test_clear_input(page: Page, server: Server) -> None: - await page.goto(server.PREFIX + "/input/textarea.html") - handle = await page.query_selector("input") - assert handle - await handle.fill("some value") - assert await page.evaluate("result") == "some value" - await handle.clear() - assert await page.evaluate("result") == "" - - async def test_select_textarea(page, server, is_firefox): await page.goto(server.PREFIX + "/input/textarea.html") textarea = await page.query_selector("textarea") diff --git a/tests/async/test_fill.py b/tests/async/test_fill.py index 03357e42b..9e5d252f0 100644 --- a/tests/async/test_fill.py +++ b/tests/async/test_fill.py @@ -12,11 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import pytest - -from playwright.async_api import Error, Page -from tests.server import Server - async def test_fill_textarea(page, server): await page.goto(f"{server.PREFIX}/input/textarea.html") @@ -28,28 +23,3 @@ async def test_fill_input(page, server): await page.goto(f"{server.PREFIX}/input/textarea.html") await page.fill("input", "some value") assert await page.evaluate("result") == "some value" - - -async def test_should_throw_on_unsupported_inputs_when_clear( - page: Page, server: Server -): - await page.goto(f"{server.PREFIX}/input/textarea.html") - for type in ["button", "checkbox", "file", "image", "radio", "reset", "submit"]: - await page.eval_on_selector( - "input", "(input, type) => input.setAttribute('type', type)", type - ) - with pytest.raises(Error) as exc_info: - await page.clear("input") - assert f'Input of type "{type}" cannot be filled' in exc_info.value.message - - -async def test_it_should_throw_nice_error_without_injected_script_stack_when_element_is_not_an_input_when_clear( - page: Page, server: Server -): - await page.goto(server.PREFIX + "/input/textarea.html") - with pytest.raises(Error) as exc_info: - await page.clear("body") - assert ( - "Element is not an ,