From 2861312f192067570d97b4cfc5854ae4e3eb1eef Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Thu, 27 Aug 2020 01:45:08 +0200 Subject: [PATCH 1/2] feat(roll): roll Playwright 1.3.0-next.1598476714110 --- README.md | 4 +- driver/main.js | 2 +- driver/package.json | 2 +- playwright/async_api.py | 121 +---------------- playwright/browser_server.py | 43 ------ playwright/browser_type.py | 27 ---- playwright/cdp_session.py | 8 +- playwright/connection.py | 4 +- playwright/drivers/browsers.json | 4 +- playwright/network.py | 2 +- playwright/object_factory.py | 3 - playwright/page.py | 14 ++ playwright/sync_api.py | 123 +----------------- scripts/documentation_provider.py | 8 +- scripts/generate_api.py | 3 - .../async/test_browsercontext_add_cookies.py | 6 +- tests/async/test_browsercontext_cookies.py | 8 +- tests/async/test_click.py | 4 +- tests/async/test_defaultbrowsercontext.py | 6 +- tests/async/test_headful.py | 6 +- tests/async/test_input.py | 3 +- tests/async/test_launcher.py | 14 +- tests/async/test_network.py | 4 +- 23 files changed, 75 insertions(+), 344 deletions(-) delete mode 100644 playwright/browser_server.py diff --git a/README.md b/README.md index ff59c042d..5d6464716 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # 🎭 [Playwright](https://github.com/microsoft/playwright) for Python -[![PyPI version](https://badge.fury.io/py/playwright.svg)](https://pypi.python.org/pypi/playwright/) [![PyPI pyversions](https://img.shields.io/pypi/pyversions/playwright.svg)](https://pypi.python.org/pypi/playwright/) [![Join Slack](https://img.shields.io/badge/join-slack-infomational)](https://join.slack.com/t/playwright/shared_invite/enQtOTEyMTUxMzgxMjIwLThjMDUxZmIyNTRiMTJjNjIyMzdmZDA3MTQxZWUwZTFjZjQwNGYxZGM5MzRmNzZlMWI5ZWUyOTkzMjE5Njg1NDg) [![Chromium version](https://img.shields.io/badge/chromium-86.0.4217.0-blue.svg?logo=google-chrome)](https://www.chromium.org/Home) [![Firefox version](https://img.shields.io/badge/firefox-79.0a1-blue.svg?logo=mozilla-firefox)](https://www.mozilla.org/en-US/firefox/new/) [![WebKit version](https://img.shields.io/badge/webkit-14.0-blue.svg?logo=safari)](https://webkit.org/) +[![PyPI version](https://badge.fury.io/py/playwright.svg)](https://pypi.python.org/pypi/playwright/) [![PyPI pyversions](https://img.shields.io/pypi/pyversions/playwright.svg)](https://pypi.python.org/pypi/playwright/) [![Join Slack](https://img.shields.io/badge/join-slack-infomational)](https://join.slack.com/t/playwright/shared_invite/enQtOTEyMTUxMzgxMjIwLThjMDUxZmIyNTRiMTJjNjIyMzdmZDA3MTQxZWUwZTFjZjQwNGYxZGM5MzRmNzZlMWI5ZWUyOTkzMjE5Njg1NDg) [![Chromium version](https://img.shields.io/badge/chromium-86.0.4217.0-blue.svg?logo=google-chrome)](https://www.chromium.org/Home) [![Firefox version](https://img.shields.io/badge/firefox-80.0b8-blue.svg?logo=mozilla-firefox)](https://www.mozilla.org/en-US/firefox/new/) [![WebKit version](https://img.shields.io/badge/webkit-14.0-blue.svg?logo=safari)](https://webkit.org/) ##### [Docs](#documentation) | [API reference](https://playwright.dev/#?path=docs/api.md) | [Docstrings](https://github.com/microsoft/playwright-python/blob/master/playwright/sync_api.py) @@ -10,7 +10,7 @@ Playwright is a Python library to automate [Chromium](https://www.chromium.org/H | :--- | :---: | :---: | :---: | | Chromium 86.0.4217.0 | ✅ | ✅ | ✅ | | WebKit 14.0 | ✅ | ✅ | ✅ | -| Firefox 79.0a1 | ✅ | ✅ | ✅ | +| Firefox 80.0b8 | ✅ | ✅ | ✅ | Headless execution is supported for all the browsers on all platforms. diff --git a/driver/main.js b/driver/main.js index 6b5ef07e2..2b675e199 100644 --- a/driver/main.js +++ b/driver/main.js @@ -35,5 +35,5 @@ const util = require('util'); return; } - require('playwright/lib/rpc/server'); + require('playwright/lib/server'); })(); diff --git a/driver/package.json b/driver/package.json index 810f564f2..424f12fc7 100644 --- a/driver/package.json +++ b/driver/package.json @@ -13,7 +13,7 @@ }, "license": "Apache-2.0", "dependencies": { - "playwright": "1.3.0-next.1596843106133" + "playwright": "1.3.0-next.1598476714110" }, "devDependencies": { "pkg": "^4.4.9" diff --git a/playwright/async_api.py b/playwright/async_api.py index e6ae2d60a..a5a03b722 100644 --- a/playwright/async_api.py +++ b/playwright/async_api.py @@ -26,7 +26,6 @@ from playwright.async_base import AsyncBase, AsyncEventContextManager, mapping from playwright.browser import Browser as BrowserImpl from playwright.browser_context import BrowserContext as BrowserContextImpl -from playwright.browser_server import BrowserServer as BrowserServerImpl from playwright.browser_type import BrowserType as BrowserTypeImpl from playwright.cdp_session import CDPSession as CDPSessionImpl from playwright.chromium_browser_context import ( @@ -3070,6 +3069,11 @@ def workers(self) -> typing.List["Worker"]: """ return mapping.from_impl_list(self._impl_obj.workers) + def remove_listener(self, event: str, f: typing.Any) -> NoneType: + return mapping.from_maybe_impl( + self._impl_obj.remove_listener(event=event, f=mapping.to_impl(f)) + ) + async def opener(self) -> typing.Union["Page", NoneType]: """Page.opener @@ -5518,45 +5522,6 @@ async def close(self) -> NoneType: mapping.register(BrowserImpl, Browser) -class BrowserServer(AsyncBase): - def __init__(self, obj: BrowserServerImpl): - super().__init__(obj) - - @property - def pid(self) -> str: - return mapping.from_maybe_impl(self._impl_obj.pid) - - @property - def wsEndpoint(self) -> str: - """BrowserServer.wsEndpoint - - Browser websocket endpoint which can be used as an argument to browserType.connect(options) to establish connection to the browser. - - Returns - ------- - str - Browser websocket url. - """ - return mapping.from_maybe_impl(self._impl_obj.wsEndpoint) - - async def kill(self) -> NoneType: - """BrowserServer.kill - - Kills the browser process and waits for the process to exit. - """ - return mapping.from_maybe_impl(await self._impl_obj.kill()) - - async def close(self) -> NoneType: - """BrowserServer.close - - Closes the browser gracefully and makes sure the process is terminated. - """ - return mapping.from_maybe_impl(await self._impl_obj.close()) - - -mapping.register(BrowserServerImpl, BrowserServer) - - class BrowserType(AsyncBase): def __init__(self, obj: BrowserTypeImpl): super().__init__(obj) @@ -5665,82 +5630,6 @@ async def launch( ) ) - async def launchServer( - self, - executablePath: typing.Union[str, pathlib.Path] = None, - args: typing.List[str] = None, - ignoreDefaultArgs: typing.Union[bool, typing.List[str]] = None, - handleSIGINT: bool = None, - handleSIGTERM: bool = None, - handleSIGHUP: bool = None, - timeout: int = None, - env: typing.Union[typing.Dict[str, typing.Union[str, int, bool]]] = None, - headless: bool = None, - devtools: bool = None, - proxy: ProxyServer = None, - downloadsPath: typing.Union[str, pathlib.Path] = None, - port: int = None, - chromiumSandbox: bool = None, - ) -> "BrowserServer": - """BrowserType.launchServer - - Launches browser server that client can connect to. An example of launching a browser executable and connecting to it later: - - Parameters - ---------- - executablePath : Union[str, pathlib.Path, NoneType] - Path to a browser executable to run instead of the bundled one. If `executablePath` is a relative path, then it is resolved relative to current working directory. **BEWARE**: Playwright is only guaranteed to work with the bundled Chromium, Firefox or WebKit, use at your own risk. - args : Optional[List[str]] - Additional arguments to pass to the browser instance. The list of Chromium flags can be found here. - ignoreDefaultArgs : Union[bool, List[str], NoneType] - If `true`, then do not use any of the default arguments. If an array is given, then filter out the given default arguments. Dangerous option; use with care. Defaults to `false`. - handleSIGINT : Optional[bool] - Close the browser process on Ctrl-C. Defaults to `true`. - handleSIGTERM : Optional[bool] - Close the browser process on SIGTERM. Defaults to `true`. - handleSIGHUP : Optional[bool] - Close the browser process on SIGHUP. Defaults to `true`. - timeout : Optional[int] - Maximum time in milliseconds to wait for the browser instance to start. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. - env : Optional[Dict[str, Union[str, int, bool]]] - Specify environment variables that will be visible to the browser. Defaults to `process.env`. - headless : Optional[bool] - Whether to run browser in headless mode. More details for Chromium and Firefox. Defaults to `true` unless the `devtools` option is `true`. - devtools : Optional[bool] - **Chromium-only** Whether to auto-open a Developer Tools panel for each tab. If this option is `true`, the `headless` option will be set `false`. - proxy : Optional[{"server": str, "bypass": Optional[str], "username": Optional[str], "password": Optional[str]}] - Network proxy settings. - downloadsPath : Union[str, pathlib.Path, NoneType] - If specified, accepted downloads are downloaded into this folder. Otherwise, temporary folder is created and is deleted when browser is closed. - port : Optional[int] - Port to use for the web socket. Defaults to 0 that picks any available port. - chromiumSandbox : Optional[bool] - Enable Chromium sandboxing. Defaults to `true`. - - Returns - ------- - BrowserServer - Promise which resolves to the browser app instance. - """ - return mapping.from_impl( - await self._impl_obj.launchServer( - executablePath=executablePath, - args=args, - ignoreDefaultArgs=ignoreDefaultArgs, - handleSIGINT=handleSIGINT, - handleSIGTERM=handleSIGTERM, - handleSIGHUP=handleSIGHUP, - timeout=timeout, - env=mapping.to_impl(env), - headless=headless, - devtools=devtools, - proxy=proxy, - downloadsPath=downloadsPath, - port=port, - chromiumSandbox=chromiumSandbox, - ) - ) - async def launchPersistentContext( self, userDataDir: typing.Union[str, pathlib.Path], diff --git a/playwright/browser_server.py b/playwright/browser_server.py deleted file mode 100644 index a1c55803d..000000000 --- a/playwright/browser_server.py +++ /dev/null @@ -1,43 +0,0 @@ -# Copyright (c) Microsoft Corporation. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from types import SimpleNamespace -from typing import Dict - -from playwright.connection import ChannelOwner - - -class BrowserServer(ChannelOwner): - - Events = SimpleNamespace(Close="close",) - - def __init__( - self, parent: ChannelOwner, type: str, guid: str, initializer: Dict - ) -> None: - super().__init__(parent, type, guid, initializer) - self._channel.on("close", lambda _: self.emit(BrowserServer.Events.Close)) - - @property - def pid(self) -> str: - return self._initializer["pid"] - - @property - def wsEndpoint(self) -> str: - return self._initializer["wsEndpoint"] - - async def kill(self) -> None: - await self._channel.send("kill") - - async def close(self) -> None: - await self._channel.send("close") diff --git a/playwright/browser_type.py b/playwright/browser_type.py index cf7075c57..9592caf4d 100644 --- a/playwright/browser_type.py +++ b/playwright/browser_type.py @@ -17,7 +17,6 @@ from playwright.browser import Browser from playwright.browser_context import BrowserContext -from playwright.browser_server import BrowserServer from playwright.connection import ChannelOwner, from_channel from playwright.helper import ( ColorScheme, @@ -72,32 +71,6 @@ async def launch( raise not_installed_error(f'"{self.name}" browser was not found.') raise e - async def launchServer( - self, - executablePath: Union[str, Path] = None, - args: List[str] = None, - ignoreDefaultArgs: Union[bool, List[str]] = None, - handleSIGINT: bool = None, - handleSIGTERM: bool = None, - handleSIGHUP: bool = None, - timeout: int = None, - env: Env = None, - headless: bool = None, - devtools: bool = None, - proxy: ProxyServer = None, - downloadsPath: Union[str, Path] = None, - port: int = None, - chromiumSandbox: bool = None, - ) -> BrowserServer: - params = locals_to_params(locals()) - normalize_launch_params(params) - try: - return from_channel(await self._channel.send("launchServer", params)) - except Exception as e: - if f"{self.name}-" in str(e): - raise not_installed_error(f'"{self.name}" browser was not found.') - raise e - async def launchPersistentContext( self, userDataDir: Union[str, Path], diff --git a/playwright/cdp_session.py b/playwright/cdp_session.py index 0aad85106..6d7ca6b2a 100644 --- a/playwright/cdp_session.py +++ b/playwright/cdp_session.py @@ -15,7 +15,8 @@ from typing import Any, Dict from playwright.connection import ChannelOwner -from playwright.js_handle import parse_result, serialize_argument +from playwright.helper import locals_to_params +from playwright.js_handle import parse_result class CDPSession(ChannelOwner): @@ -29,10 +30,7 @@ def _on_event(self, params: Any) -> None: self.emit(params["method"], parse_result(params["params"])) async def send(self, method: str, params: Dict = None) -> Dict: - payload = {"method": method} - if params: - payload["params"] = serialize_argument(params)["value"] - result = await self._channel.send("send", payload) + result = await self._channel.send("send", locals_to_params(locals())) return parse_result(result) async def detach(self) -> None: diff --git a/playwright/connection.py b/playwright/connection.py index c275a11ea..e964cf011 100644 --- a/playwright/connection.py +++ b/playwright/connection.py @@ -32,7 +32,7 @@ def __init__(self, connection: "Connection", guid: str) -> None: self._guid = guid self._object: Optional[ChannelOwner] = None - async def send(self, method: str, params: dict = None) -> Any: + async def send(self, method: str, params: Dict = None) -> Any: if params is None: params = {} callback = self._connection._send_message_to_server(self._guid, method, params) @@ -48,7 +48,7 @@ async def send(self, method: str, params: dict = None) -> Any: key = next(iter(result)) return result[key] - def send_no_reply(self, method: str, params: dict = None) -> None: + def send_no_reply(self, method: str, params: Dict = None) -> None: if params is None: params = {} self._connection._send_message_to_server(self._guid, method, params) diff --git a/playwright/drivers/browsers.json b/playwright/drivers/browsers.json index f6ac44fb9..c49bc1f37 100644 --- a/playwright/drivers/browsers.json +++ b/playwright/drivers/browsers.json @@ -8,12 +8,12 @@ }, { "name": "firefox", - "revision": "1154", + "revision": "1167", "download": true }, { "name": "webkit", - "revision": "1322", + "revision": "1332", "download": true } ] diff --git a/playwright/network.py b/playwright/network.py index b4e6e986e..83fc8c203 100644 --- a/playwright/network.py +++ b/playwright/network.py @@ -234,4 +234,4 @@ def serialize_headers(headers: Dict[str, str]) -> List[Header]: def parse_headers(headers: List[Header]) -> Dict[str, str]: - return {header["name"]: header["value"] for header in headers} + return {header["name"].lower(): header["value"] for header in headers} diff --git a/playwright/object_factory.py b/playwright/object_factory.py index d4cd118ce..09df39a45 100644 --- a/playwright/object_factory.py +++ b/playwright/object_factory.py @@ -16,7 +16,6 @@ from playwright.browser import Browser from playwright.browser_context import BrowserContext -from playwright.browser_server import BrowserServer from playwright.browser_type import BrowserType from playwright.cdp_session import CDPSession from playwright.chromium_browser_context import ChromiumBrowserContext @@ -47,8 +46,6 @@ def create_remote_object( return BindingCall(parent, type, guid, initializer) if type == "Browser": return Browser(cast(BrowserType, parent), type, guid, initializer) - if type == "BrowserServer": - return BrowserServer(parent, type, guid, initializer) if type == "BrowserType": return BrowserType(parent, type, guid, initializer) if type == "BrowserContext": diff --git a/playwright/page.py b/playwright/page.py index 9a19baafd..62da22161 100644 --- a/playwright/page.py +++ b/playwright/page.py @@ -255,6 +255,20 @@ def _reject_pending_operations(self, is_crash: bool) -> None: for pending_event in self._pending_wait_for_events: pending_event.reject(is_crash, "Page") + 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 diff --git a/playwright/sync_api.py b/playwright/sync_api.py index e8ec9f16b..3ab2b617c 100644 --- a/playwright/sync_api.py +++ b/playwright/sync_api.py @@ -25,7 +25,6 @@ from playwright.accessibility import Accessibility as AccessibilityImpl from playwright.browser import Browser as BrowserImpl from playwright.browser_context import BrowserContext as BrowserContextImpl -from playwright.browser_server import BrowserServer as BrowserServerImpl from playwright.browser_type import BrowserType as BrowserTypeImpl from playwright.cdp_session import CDPSession as CDPSessionImpl from playwright.chromium_browser_context import ( @@ -3196,6 +3195,11 @@ def workers(self) -> typing.List["Worker"]: """ return mapping.from_impl_list(self._impl_obj.workers) + def remove_listener(self, event: str, f: typing.Any) -> NoneType: + return mapping.from_maybe_impl( + self._impl_obj.remove_listener(event=event, f=mapping.to_impl(f)) + ) + def opener(self) -> typing.Union["Page", NoneType]: """Page.opener @@ -5750,45 +5754,6 @@ def close(self) -> NoneType: mapping.register(BrowserImpl, Browser) -class BrowserServer(SyncBase): - def __init__(self, obj: BrowserServerImpl): - super().__init__(obj) - - @property - def pid(self) -> str: - return mapping.from_maybe_impl(self._impl_obj.pid) - - @property - def wsEndpoint(self) -> str: - """BrowserServer.wsEndpoint - - Browser websocket endpoint which can be used as an argument to browserType.connect(options) to establish connection to the browser. - - Returns - ------- - str - Browser websocket url. - """ - return mapping.from_maybe_impl(self._impl_obj.wsEndpoint) - - def kill(self) -> NoneType: - """BrowserServer.kill - - Kills the browser process and waits for the process to exit. - """ - return mapping.from_maybe_impl(self._sync(self._impl_obj.kill())) - - def close(self) -> NoneType: - """BrowserServer.close - - Closes the browser gracefully and makes sure the process is terminated. - """ - return mapping.from_maybe_impl(self._sync(self._impl_obj.close())) - - -mapping.register(BrowserServerImpl, BrowserServer) - - class BrowserType(SyncBase): def __init__(self, obj: BrowserTypeImpl): super().__init__(obj) @@ -5899,84 +5864,6 @@ def launch( ) ) - def launchServer( - self, - executablePath: typing.Union[str, pathlib.Path] = None, - args: typing.List[str] = None, - ignoreDefaultArgs: typing.Union[bool, typing.List[str]] = None, - handleSIGINT: bool = None, - handleSIGTERM: bool = None, - handleSIGHUP: bool = None, - timeout: int = None, - env: typing.Union[typing.Dict[str, typing.Union[str, int, bool]]] = None, - headless: bool = None, - devtools: bool = None, - proxy: ProxyServer = None, - downloadsPath: typing.Union[str, pathlib.Path] = None, - port: int = None, - chromiumSandbox: bool = None, - ) -> "BrowserServer": - """BrowserType.launchServer - - Launches browser server that client can connect to. An example of launching a browser executable and connecting to it later: - - Parameters - ---------- - executablePath : Union[str, pathlib.Path, NoneType] - Path to a browser executable to run instead of the bundled one. If `executablePath` is a relative path, then it is resolved relative to current working directory. **BEWARE**: Playwright is only guaranteed to work with the bundled Chromium, Firefox or WebKit, use at your own risk. - args : Optional[List[str]] - Additional arguments to pass to the browser instance. The list of Chromium flags can be found here. - ignoreDefaultArgs : Union[bool, List[str], NoneType] - If `true`, then do not use any of the default arguments. If an array is given, then filter out the given default arguments. Dangerous option; use with care. Defaults to `false`. - handleSIGINT : Optional[bool] - Close the browser process on Ctrl-C. Defaults to `true`. - handleSIGTERM : Optional[bool] - Close the browser process on SIGTERM. Defaults to `true`. - handleSIGHUP : Optional[bool] - Close the browser process on SIGHUP. Defaults to `true`. - timeout : Optional[int] - Maximum time in milliseconds to wait for the browser instance to start. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. - env : Optional[Dict[str, Union[str, int, bool]]] - Specify environment variables that will be visible to the browser. Defaults to `process.env`. - headless : Optional[bool] - Whether to run browser in headless mode. More details for Chromium and Firefox. Defaults to `true` unless the `devtools` option is `true`. - devtools : Optional[bool] - **Chromium-only** Whether to auto-open a Developer Tools panel for each tab. If this option is `true`, the `headless` option will be set `false`. - proxy : Optional[{"server": str, "bypass": Optional[str], "username": Optional[str], "password": Optional[str]}] - Network proxy settings. - downloadsPath : Union[str, pathlib.Path, NoneType] - If specified, accepted downloads are downloaded into this folder. Otherwise, temporary folder is created and is deleted when browser is closed. - port : Optional[int] - Port to use for the web socket. Defaults to 0 that picks any available port. - chromiumSandbox : Optional[bool] - Enable Chromium sandboxing. Defaults to `true`. - - Returns - ------- - BrowserServer - Promise which resolves to the browser app instance. - """ - return mapping.from_impl( - self._sync( - self._impl_obj.launchServer( - executablePath=executablePath, - args=args, - ignoreDefaultArgs=ignoreDefaultArgs, - handleSIGINT=handleSIGINT, - handleSIGTERM=handleSIGTERM, - handleSIGHUP=handleSIGHUP, - timeout=timeout, - env=mapping.to_impl(env), - headless=headless, - devtools=devtools, - proxy=proxy, - downloadsPath=downloadsPath, - port=port, - chromiumSandbox=chromiumSandbox, - ) - ) - ) - def launchPersistentContext( self, userDataDir: typing.Union[str, pathlib.Path], diff --git a/scripts/documentation_provider.py b/scripts/documentation_provider.py index 0cb259c34..0452d1364 100644 --- a/scripts/documentation_provider.py +++ b/scripts/documentation_provider.py @@ -62,9 +62,11 @@ def __init__(self) -> None: def print_entry( self, class_name: str, method_name: str, signature: Dict[str, Any] = None ) -> None: - if class_name == "Playwright": - return - if class_name == "BindingCall" or method_name == "pid": + if class_name in ["BindingCall", "Playwright"] or method_name in [ + "pid", + "_add_event_handler", + "remove_listener", + ]: return original_method_name = method_name if method_name in self.method_name_rewrites: diff --git a/scripts/generate_api.py b/scripts/generate_api.py index 30e1f25a0..30970495d 100644 --- a/scripts/generate_api.py +++ b/scripts/generate_api.py @@ -28,7 +28,6 @@ from playwright.accessibility import Accessibility from playwright.browser import Browser from playwright.browser_context import BrowserContext -from playwright.browser_server import BrowserServer from playwright.browser_type import BrowserType from playwright.cdp_session import CDPSession from playwright.chromium_browser_context import ChromiumBrowserContext @@ -154,7 +153,6 @@ def return_value(value: Any) -> List[str]: from playwright.accessibility import Accessibility as AccessibilityImpl from playwright.browser import Browser as BrowserImpl from playwright.browser_context import BrowserContext as BrowserContextImpl -from playwright.browser_server import BrowserServer as BrowserServerImpl from playwright.browser_type import BrowserType as BrowserTypeImpl from playwright.cdp_session import CDPSession as CDPSessionImpl from playwright.chromium_browser_context import ChromiumBrowserContext as ChromiumBrowserContextImpl @@ -195,7 +193,6 @@ def return_value(value: Any) -> List[str]: CDPSession, ChromiumBrowserContext, Browser, - BrowserServer, BrowserType, Playwright, ] diff --git a/tests/async/test_browsercontext_add_cookies.py b/tests/async/test_browsercontext_add_cookies.py index 63d7dd855..19e026cfc 100644 --- a/tests/async/test_browsercontext_add_cookies.py +++ b/tests/async/test_browsercontext_add_cookies.py @@ -349,7 +349,9 @@ async def test_should_set_cookies_for_a_frame(context, page, server): assert await page.frames[1].evaluate("document.cookie") == "frame-cookie=value" -async def test_should_not_block_third_party_cookies(context, page, server, is_chromium): +async def test_should_not_block_third_party_cookies( + context, page, server, is_chromium, is_firefox +): await page.goto(server.EMPTY_PAGE) await page.evaluate( """src => { @@ -365,7 +367,7 @@ async def test_should_not_block_third_party_cookies(context, page, server, is_ch ) await page.frames[1].evaluate("document.cookie = 'username=John Doe'") await page.waitForTimeout(2000) - allows_third_party = is_chromium + allows_third_party = is_chromium or is_firefox cookies = await context.cookies(server.CROSS_PROCESS_PREFIX + "/grid.html") if allows_third_party: diff --git a/tests/async/test_browsercontext_cookies.py b/tests/async/test_browsercontext_cookies.py index d2e868208..1537d6c3f 100644 --- a/tests/async/test_browsercontext_cookies.py +++ b/tests/async/test_browsercontext_cookies.py @@ -39,7 +39,7 @@ async def test_should_get_a_cookie(context, page, server, is_firefox): "expires": -1, "httpOnly": False, "secure": False, - "sameSite": "Lax" if is_firefox else "None", + "sameSite": "None", } ] @@ -66,7 +66,7 @@ async def test_should_get_a_non_session_cookie(context, page, server, is_firefox "expires": date / 1000, "httpOnly": False, "secure": False, - "sameSite": "Lax" if is_firefox else "None", + "sameSite": "None", } ] @@ -142,7 +142,7 @@ async def test_should_get_multiple_cookies(context, page, server, is_firefox): "expires": -1, "httpOnly": False, "secure": False, - "sameSite": "Lax" if is_firefox else "None", + "sameSite": "None", }, { "name": "username", @@ -152,7 +152,7 @@ async def test_should_get_multiple_cookies(context, page, server, is_firefox): "expires": -1, "httpOnly": False, "secure": False, - "sameSite": "Lax" if is_firefox else "None", + "sameSite": "None", }, ] diff --git a/tests/async/test_click.py b/tests/async/test_click.py index dce5aeb57..de1b80371 100644 --- a/tests/async/test_click.py +++ b/tests/async/test_click.py @@ -581,6 +581,7 @@ async def test_timeout_waiting_for_hit_target(page, server): """() => { document.body.style.position = 'relative' blocker = document.createElement('div') + blocker.id = 'blocker'; blocker.style.position = 'absolute' blocker.style.width = '400px' blocker.style.height = '20px' @@ -595,7 +596,8 @@ async def test_timeout_waiting_for_hit_target(page, server): except TimeoutError as e: error = e assert "Timeout 5000ms exceeded." in error.message - assert "element does not receive pointer events" in error.message + assert '
intercepts pointer events' in error.message + assert "retrying click action" in error.message async def test_fail_when_obscured_and_not_waiting_for_hit_target(page, server): diff --git a/tests/async/test_defaultbrowsercontext.py b/tests/async/test_defaultbrowsercontext.py index 99af57582..eeec24a41 100644 --- a/tests/async/test_defaultbrowsercontext.py +++ b/tests/async/test_defaultbrowsercontext.py @@ -57,7 +57,7 @@ async def test_context_cookies_should_work(server, launch_persistent, is_firefox "expires": -1, "httpOnly": False, "secure": False, - "sameSite": "Lax" if is_firefox else "None", + "sameSite": "None", } ] @@ -100,7 +100,7 @@ async def test_context_clear_cookies_should_work(server, launch_persistent): async def test_should_not_block_third_party_cookies( - server, launch_persistent, is_chromium + server, launch_persistent, is_chromium, is_firefox ): (page, context) = await launch_persistent() await page.goto(server.EMPTY_PAGE) @@ -124,7 +124,7 @@ async def test_should_not_block_third_party_cookies( ) await page.waitForTimeout(2000) - allows_third_party = is_chromium + allows_third_party = is_chromium or is_firefox assert document_cookie == ("username=John Doe" if allows_third_party else "") cookies = await context.cookies(server.CROSS_PROCESS_PREFIX + "/grid.html") if allows_third_party: diff --git a/tests/async/test_headful.py b/tests/async/test_headful.py index 2a8e8f4c3..66d09af07 100644 --- a/tests/async/test_headful.py +++ b/tests/async/test_headful.py @@ -131,10 +131,10 @@ async def test_should_not_block_third_party_cookies( ) await page.waitForTimeout(2000) - allowsThirdParty = is_chromium - assert document_cookie == ("username=John Doe" if allowsThirdParty else "") + allows_third_party = is_chromium or is_firefox + assert document_cookie == ("username=John Doe" if allows_third_party else "") cookies = await page.context.cookies(server.CROSS_PROCESS_PREFIX + "/grid.html") - if allowsThirdParty: + if allows_third_party: assert cookies == [ { "domain": "127.0.0.1", diff --git a/tests/async/test_input.py b/tests/async/test_input.py index c75838e17..c106a805e 100644 --- a/tests/async/test_input.py +++ b/tests/async/test_input.py @@ -84,6 +84,7 @@ async def test_should_work_when_file_input_is_attached_to_DOM(page: Page, server async def test_should_work_when_file_input_is_not_attached_to_DOM(page, server): + file_chooser = asyncio.create_task(page.waitForEvent("filechooser")) await page.evaluate( """() => { el = document.createElement('input') @@ -91,7 +92,7 @@ async def test_should_work_when_file_input_is_not_attached_to_DOM(page, server): el.click() }""" ) - assert await page.waitForEvent("filechooser") + assert await file_chooser async def test_should_return_the_same_file_chooser_when_there_are_many_watchdogs_simultaneously( diff --git a/tests/async/test_launcher.py b/tests/async/test_launcher.py index 476c30b94..e847b21b0 100644 --- a/tests/async/test_launcher.py +++ b/tests/async/test_launcher.py @@ -66,6 +66,7 @@ async def test_browser_type_launch_should_reject_if_executable_path_is_invalid( assert "Failed to launch" in exc.value.message +@pytest.mark.skip() async def test_browser_type_launch_server_should_return_child_process_instance( browser_type, launch_arguments ): @@ -74,6 +75,7 @@ async def test_browser_type_launch_server_should_return_child_process_instance( await browser_server.close() +@pytest.mark.skip() async def test_browser_type_launch_server_should_fire_close_event( browser_type, launch_arguments ): @@ -102,6 +104,7 @@ async def test_browser_type_name_should_work( raise ValueError("Unknown browser") +@pytest.mark.skip() async def test_browser_is_connected_should_set_connected_state( browser_type, launch_arguments ): @@ -113,6 +116,7 @@ async def test_browser_is_connected_should_set_connected_state( await browser_server.close() +@pytest.mark.skip() async def test_browser_is_connected_should_throw_when_used_after_isConnected_returns_false( browser_type, launch_arguments ): @@ -128,7 +132,7 @@ async def test_browser_is_connected_should_throw_when_used_after_isConnected_ret assert "has been closed" in exc.value.message -@pytest.mark.skip("currently flaky") # TODO: should be removed +@pytest.mark.skip() async def test_browser_disconnect_should_reject_navigation_when_browser_closes( browser_type, launch_arguments, server ): @@ -150,6 +154,7 @@ async def handle_goto(): await browser_server.close() +@pytest.mark.skip() async def test_browser_disconnect_should_reject_waitForSelector_when_browser_closes( browser_type, launch_arguments, server ): @@ -176,6 +181,7 @@ async def handle_wait_for_selector(): await browser_server.close() +@pytest.mark.skip() async def test_browser_disconnect_should_throw_if_used_after_disconnect( browser_type, launch_arguments ): @@ -189,6 +195,7 @@ async def test_browser_disconnect_should_throw_if_used_after_disconnect( await browser_server.close() +@pytest.mark.skip() async def test_browser_disconnect_should_emit_close_events_on_pages_and_contexts( browser_type, launch_arguments ): @@ -204,6 +211,7 @@ async def test_browser_disconnect_should_emit_close_events_on_pages_and_contexts assert len(pages_closed) == 1 +@pytest.mark.skip() async def test_browser_close_should_terminate_network_waiters( browser_type, launch_arguments, server ): @@ -257,6 +265,7 @@ async def test_browser_close_should_be_callable_twice(browser_type, launch_argum await browser.close() +@pytest.mark.skip() async def test_browser_type_launch_server_should_work(browser_type, launch_arguments): browser_server = await browser_type.launchServer(**launch_arguments) browser = await browser_type.connect(wsEndpoint=browser_server.wsEndpoint) @@ -270,6 +279,7 @@ async def test_browser_type_launch_server_should_work(browser_type, launch_argum await browser_server.close() +@pytest.mark.skip() async def test_browser_type_launch_server_should_fire_disconnected_when_closing_the_server( browser_type, launch_arguments ): @@ -288,6 +298,7 @@ async def test_browser_type_launch_server_should_fire_disconnected_when_closing_ ) +@pytest.mark.skip() async def test_browser_type_launch_server_should_fire_close_event_during_kill( browser_type, launch_arguments ): @@ -307,6 +318,7 @@ async def kill_with_order(): assert order == ["closed", "killed"] +@pytest.mark.skip() async def test_browser_type_connect_should_be_able_to_reconnect_to_a_browser( browser_type, launch_arguments, server ): diff --git a/tests/async/test_network.py b/tests/async/test_network.py index 8d7c24a16..aa9e7d6b0 100644 --- a/tests/async/test_network.py +++ b/tests/async/test_network.py @@ -23,7 +23,7 @@ from playwright.async_api import Page, Request -async def test_request_fulfill(page): +async def test_request_fulfill(page, server): async def handle_request(route, request): assert route.request == request assert "empty.html" in request.url @@ -41,7 +41,7 @@ async def handle_request(route, request): lambda route, request: asyncio.create_task(handle_request(route, request)), ) - response = await page.goto("http://www.non-existent.com/empty.html") + response = await page.goto(server.EMPTY_PAGE) assert response.ok assert await response.text() == "Text" From 0e07dda8d73d32ca17e2ccb35ab06bbf44ed01be Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Thu, 27 Aug 2020 01:58:16 +0200 Subject: [PATCH 2/2] fix: nit --- tests/async/test_input.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/async/test_input.py b/tests/async/test_input.py index c106a805e..eddc46ec0 100644 --- a/tests/async/test_input.py +++ b/tests/async/test_input.py @@ -84,15 +84,17 @@ async def test_should_work_when_file_input_is_attached_to_DOM(page: Page, server async def test_should_work_when_file_input_is_not_attached_to_DOM(page, server): - file_chooser = asyncio.create_task(page.waitForEvent("filechooser")) - await page.evaluate( - """() => { + [file_chooser, _] = await asyncio.gather( + page.waitForEvent("filechooser"), + page.evaluate( + """() => { el = document.createElement('input') el.type = 'file' el.click() }""" + ), ) - assert await file_chooser + assert file_chooser async def test_should_return_the_same_file_chooser_when_there_are_many_watchdogs_simultaneously(