From 757645b7f57aaa0c6fea1838369e6b6e732de6b2 Mon Sep 17 00:00:00 2001 From: "microsoft-playwright-automation[bot]" <203992400+microsoft-playwright-automation[bot]@users.noreply.github.com> Date: Wed, 2 Dec 2026 10:03:59 +0000 Subject: [PATCH] chore: roll Playwright to 1.66.0-next (469ba81b64) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- DRIVER_VERSION | 2 +- NODE_VERSION | 2 +- playwright/_impl/_protocol.py | 20 ++- playwright/_impl/browser.py | 4 +- playwright/_impl/browser_context.py | 12 +- playwright/_impl/browser_type.py | 2 +- playwright/_impl/element_handle.py | 4 +- playwright/_impl/page.py | 1 + playwright/_impl/protocol/validator.py | 10 +- playwright/_impl/protocol_channels.py | 16 +- playwright/_impl/protocol_types.py | 2 +- playwright/async_api/_generated.py | 62 ++++++-- playwright/sync_api/_generated.py | 58 +++++-- .../library/chromium/test_connect_over_cdp.py | 18 ++- .../library/test_browsercontext_basic.py | 35 +++++ tests/async/library/test_headful.py | 95 ++++++++++++ tests/async/library/test_tracing.py | 11 ++ tests/async/page/test_page_goto.py | 131 +++++++++++++++- .../library/chromium/test_connect_over_cdp.py | 18 ++- .../sync/library/test_browsercontext_basic.py | 35 +++++ tests/sync/library/test_headful.py | 94 ++++++++++++ tests/sync/library/test_tracing.py | 11 ++ tests/sync/page/test_page_goto.py | 141 ++++++++++++++++++ tests/upstream_not_ported.txt | 1 + tests/upstream_registry.md | 17 +++ 25 files changed, 751 insertions(+), 51 deletions(-) diff --git a/DRIVER_VERSION b/DRIVER_VERSION index 5f86dfacc..633052765 100644 --- a/DRIVER_VERSION +++ b/DRIVER_VERSION @@ -1 +1 @@ -a804c193562095b0da20e5d4679fa87e4c8e5563 +469ba81b64feb6da82d3e4ecbc2d0435c84f98f4 diff --git a/NODE_VERSION b/NODE_VERSION index a2e8115a7..dfc0d2a8a 100644 --- a/NODE_VERSION +++ b/NODE_VERSION @@ -1 +1 @@ -26.13.1 +26.14.0 diff --git a/playwright/_impl/_protocol.py b/playwright/_impl/_protocol.py index fdc32f4fd..e5091a256 100644 --- a/playwright/_impl/_protocol.py +++ b/playwright/_impl/_protocol.py @@ -528,11 +528,14 @@ "inputSwipe": {"segments": {"type": "array", "items": "Point"}, "steps": "int"}, "inputDrag": {"from": "Point", "to": "Point", "steps": "int"}, "launchBrowser": { - "noDefaultViewport": "boolean?", "viewport": { "type": "object?", "properties": {"width": "int", "height": "int"}, }, + "viewportMode": { + "type": "enum?", + "literals": ["none", "maximized", "fixed"], + }, "screen": { "type": "object?", "properties": {"width": "int", "height": "int"}, @@ -716,11 +719,14 @@ "killForTests": {}, "defaultUserAgentForTest": {}, "newContext": { - "noDefaultViewport": "boolean?", "viewport": { "type": "object?", "properties": {"width": "int", "height": "int"}, }, + "viewportMode": { + "type": "enum?", + "literals": ["none", "maximized", "fixed"], + }, "screen": { "type": "object?", "properties": {"width": "int", "height": "int"}, @@ -845,11 +851,14 @@ }, }, "newContextForReuse": { - "noDefaultViewport": "boolean?", "viewport": { "type": "object?", "properties": {"width": "int", "height": "int"}, }, + "viewportMode": { + "type": "enum?", + "literals": ["none", "maximized", "fixed"], + }, "screen": { "type": "object?", "properties": {"width": "int", "height": "int"}, @@ -1182,11 +1191,14 @@ "chromiumSandbox": "boolean?", "firefoxUserPrefs": "json?", "cdpPort": "int?", - "noDefaultViewport": "boolean?", "viewport": { "type": "object?", "properties": {"width": "int", "height": "int"}, }, + "viewportMode": { + "type": "enum?", + "literals": ["none", "maximized", "fixed"], + }, "screen": { "type": "object?", "properties": {"width": "int", "height": "int"}, diff --git a/playwright/_impl/browser.py b/playwright/_impl/browser.py index a843667c3..5842032d8 100644 --- a/playwright/_impl/browser.py +++ b/playwright/_impl/browser.py @@ -119,7 +119,7 @@ def browser_type(self) -> "BrowserType": async def new_context( self, - viewport: Optional[ViewportSize], + viewport: Optional[Union[ViewportSize, Literal["maximized"]]], screen: Optional[ScreenSize], no_viewport: Optional[bool], ignore_https_errors: Optional[bool], @@ -316,7 +316,7 @@ async def unbind(self) -> None: @api_call(title="Create page") async def new_page( self, - viewport: Optional[ViewportSize], + viewport: Optional[Union[ViewportSize, Literal["maximized"]]], screen: Optional[ScreenSize], no_viewport: Optional[bool], ignore_https_errors: Optional[bool], diff --git a/playwright/_impl/browser_context.py b/playwright/_impl/browser_context.py index 958ecdfb5..51d009343 100644 --- a/playwright/_impl/browser_context.py +++ b/playwright/_impl/browser_context.py @@ -950,8 +950,16 @@ async def prepare_browser_context_params(options: Dict[str, Any]) -> Dict[str, A "testIdAttributeName": options.get("testIdAttributeName"), "proxy": options.get("proxy"), # Python: `viewport: null` is no_viewport=True. - "viewport": None if options.get("no_viewport") else options.get("viewport"), - "noDefaultViewport": bool(options.get("no_viewport")), + "viewport": ( + None + if options.get("no_viewport") or options.get("viewport") == "maximized" + else options.get("viewport") + ), + "viewportMode": ( + "none" + if options.get("no_viewport") + else "maximized" if options.get("viewport") == "maximized" else "fixed" + ), "extraHTTPHeaders": ( headers_object_to_array(options["extra_http_headers"]) if options.get("extra_http_headers") is not None diff --git a/playwright/_impl/browser_type.py b/playwright/_impl/browser_type.py index 4e4edcbe0..ae710f98c 100644 --- a/playwright/_impl/browser_type.py +++ b/playwright/_impl/browser_type.py @@ -188,7 +188,7 @@ async def launch_persistent_context( proxy: Optional[ProxySettings], downloads_path: Optional[Union[str, Path]], slow_mo: Optional[float], - viewport: Optional[ViewportSize], + viewport: Optional[Union[ViewportSize, Literal["maximized"]]], screen: Optional[ScreenSize], no_viewport: Optional[bool], ignore_https_errors: Optional[bool], diff --git a/playwright/_impl/element_handle.py b/playwright/_impl/element_handle.py index 516c49cda..200fe72ff 100644 --- a/playwright/_impl/element_handle.py +++ b/playwright/_impl/element_handle.py @@ -313,7 +313,9 @@ async def set_input_files( timeout: Optional[float], no_wait_after: Optional[bool], ) -> None: - frame = await self.owner_frame() + frame = await self._wrap_api_call( + lambda _: self.owner_frame(), ApiCallOptions(internal=True) + ) if not frame: raise Error("Cannot set input files to detached element") converted = await convert_input_files(files, frame.page.context) diff --git a/playwright/_impl/page.py b/playwright/_impl/page.py index 6e6bb55ef..0d7399852 100644 --- a/playwright/_impl/page.py +++ b/playwright/_impl/page.py @@ -674,6 +674,7 @@ async def _on_locator_handler_triggered(self, uid: int) -> None: ) ) + @api_call() async def remove_locator_handler(self, locator: "Locator") -> None: # Python: a dict can not change while it is iterated; a Map can. for uid, data in list(self._locator_handlers.items()): diff --git a/playwright/_impl/protocol/validator.py b/playwright/_impl/protocol/validator.py index ea4d28ef2..6a01ae9f1 100644 --- a/playwright/_impl/protocol/validator.py +++ b/playwright/_impl/protocol/validator.py @@ -233,13 +233,13 @@ scheme["AndroidDeviceLaunchBrowserParams"] = t_object( {}, { - "noDefaultViewport": t_boolean, "viewport": t_object( { "width": t_int, "height": t_int, } ), + "viewportMode": t_enum(["none", "maximized", "fixed"]), "screen": t_object( { "width": t_int, @@ -697,13 +697,13 @@ scheme["BrowserNewContextParams"] = t_object( {}, { - "noDefaultViewport": t_boolean, "viewport": t_object( { "width": t_int, "height": t_int, } ), + "viewportMode": t_enum(["none", "maximized", "fixed"]), "screen": t_object( { "width": t_int, @@ -823,13 +823,13 @@ scheme["BrowserNewContextForReuseParams"] = t_object( {}, { - "noDefaultViewport": t_boolean, "viewport": t_object( { "width": t_int, "height": t_int, } ), + "viewportMode": t_enum(["none", "maximized", "fixed"]), "screen": t_object( { "width": t_int, @@ -981,13 +981,13 @@ "options": t_object( {}, { - "noDefaultViewport": t_boolean, "viewport": t_object( { "width": t_int, "height": t_int, } ), + "viewportMode": t_enum(["none", "maximized", "fixed"]), "screen": t_object( { "width": t_int, @@ -1633,13 +1633,13 @@ "chromiumSandbox": t_boolean, "firefoxUserPrefs": t_any, "cdpPort": t_int, - "noDefaultViewport": t_boolean, "viewport": t_object( { "width": t_int, "height": t_int, } ), + "viewportMode": t_enum(["none", "maximized", "fixed"]), "screen": t_object( { "width": t_int, diff --git a/playwright/_impl/protocol_channels.py b/playwright/_impl/protocol_channels.py index 4603975e0..6c8910402 100644 --- a/playwright/_impl/protocol_channels.py +++ b/playwright/_impl/protocol_channels.py @@ -302,8 +302,8 @@ def inputDrag( def launchBrowser( self, - noDefaultViewport: Optional[bool], viewport: Optional[channels.AndroidDeviceLaunchBrowserParamsViewport], + viewportMode: Optional[Literal["none", "maximized", "fixed"]], screen: Optional[channels.AndroidDeviceLaunchBrowserParamsScreen], ignoreHTTPSErrors: Optional[bool], clientCertificates: Optional[ @@ -344,8 +344,8 @@ def launchBrowser( return self._call( "launchBrowser", { - "noDefaultViewport": noDefaultViewport, "viewport": viewport, + "viewportMode": viewportMode, "screen": screen, "ignoreHTTPSErrors": ignoreHTTPSErrors, "clientCertificates": clientCertificates, @@ -788,8 +788,8 @@ def defaultUserAgentForTest( def newContext( self, - noDefaultViewport: Optional[bool], viewport: Optional[channels.BrowserNewContextParamsViewport], + viewportMode: Optional[Literal["none", "maximized", "fixed"]], screen: Optional[channels.BrowserNewContextParamsScreen], ignoreHTTPSErrors: Optional[bool], clientCertificates: Optional[ @@ -829,8 +829,8 @@ def newContext( return self._call( "newContext", { - "noDefaultViewport": noDefaultViewport, "viewport": viewport, + "viewportMode": viewportMode, "screen": screen, "ignoreHTTPSErrors": ignoreHTTPSErrors, "clientCertificates": clientCertificates, @@ -868,8 +868,8 @@ def newContext( def newContextForReuse( self, - noDefaultViewport: Optional[bool], viewport: Optional[channels.BrowserNewContextForReuseParamsViewport], + viewportMode: Optional[Literal["none", "maximized", "fixed"]], screen: Optional[channels.BrowserNewContextForReuseParamsScreen], ignoreHTTPSErrors: Optional[bool], clientCertificates: Optional[ @@ -909,8 +909,8 @@ def newContextForReuse( return self._call( "newContextForReuse", { - "noDefaultViewport": noDefaultViewport, "viewport": viewport, + "viewportMode": viewportMode, "screen": screen, "ignoreHTTPSErrors": ignoreHTTPSErrors, "clientCertificates": clientCertificates, @@ -1774,8 +1774,8 @@ def launchPersistentContext( chromiumSandbox: Optional[bool], firefoxUserPrefs: Optional[Any], cdpPort: Optional[int], - noDefaultViewport: Optional[bool], viewport: Optional[channels.BrowserTypeLaunchPersistentContextParamsViewport], + viewportMode: Optional[Literal["none", "maximized", "fixed"]], screen: Optional[channels.BrowserTypeLaunchPersistentContextParamsScreen], ignoreHTTPSErrors: Optional[bool], clientCertificates: Optional[ @@ -1838,8 +1838,8 @@ def launchPersistentContext( "chromiumSandbox": chromiumSandbox, "firefoxUserPrefs": firefoxUserPrefs, "cdpPort": cdpPort, - "noDefaultViewport": noDefaultViewport, "viewport": viewport, + "viewportMode": viewportMode, "screen": screen, "ignoreHTTPSErrors": ignoreHTTPSErrors, "clientCertificates": clientCertificates, diff --git a/playwright/_impl/protocol_types.py b/playwright/_impl/protocol_types.py index f1884c7ed..4225577f1 100644 --- a/playwright/_impl/protocol_types.py +++ b/playwright/_impl/protocol_types.py @@ -542,8 +542,8 @@ class BrowserContextInitializerOptionsRecordVideo(TypedDict): class BrowserContextInitializerOptions(TypedDict): - noDefaultViewport: NotRequired[bool] viewport: NotRequired[BrowserContextInitializerOptionsViewport] + viewportMode: NotRequired[Literal["none", "maximized", "fixed"]] screen: NotRequired[BrowserContextInitializerOptionsScreen] ignoreHTTPSErrors: NotRequired[bool] clientCertificates: NotRequired[ diff --git a/playwright/async_api/_generated.py b/playwright/async_api/_generated.py index 6b8435c84..482a8ff9b 100644 --- a/playwright/async_api/_generated.py +++ b/playwright/async_api/_generated.py @@ -1429,7 +1429,9 @@ async def new_context( strict_selectors: typing.Optional[bool] = None, timezone_id: typing.Optional[str] = None, user_agent: typing.Optional[str] = None, - viewport: typing.Optional[ViewportSize] = None, + viewport: typing.Optional[ + typing.Union[Literal["maximized"], ViewportSize] + ] = None, ) -> "BrowserContext": """Browser.new_context @@ -1589,9 +1591,19 @@ async def new_context( for a list of supported timezone IDs. Defaults to the system timezone. user_agent : Union[str, None] Specific user agent to use in this context. - viewport : Union[{width: int, height: int}, None] + viewport : Union["maximized", {width: int, height: int}, None] Sets a consistent viewport for each page. Defaults to an 1280x720 viewport. `no_viewport` disables the fixed - viewport. Learn more about [viewport emulation](../emulation.md#viewport). + viewport. Learn more about [viewport emulation](../emulation.md#viewport). Use `viewport="maximized"` to disable + viewport emulation and maximize native browser windows. This is only supported in headed mode and does not enter + fullscreen mode or trigger the web Fullscreen API. + + On Linux with X11, native window maximization requires a window manager. Xvfb alone does not provide one. Use a + fixed viewport if you need consistent page dimensions without a window manager. + + **NOTE** The `no_viewport=True` and `viewport="maximized"` values opt out from the default presets and make + viewport depend on the host window size defined by the operating system. It makes the execution of the tests + non-deterministic. + Returns ------- @@ -1689,7 +1701,9 @@ async def new_page( strict_selectors: typing.Optional[bool] = None, timezone_id: typing.Optional[str] = None, user_agent: typing.Optional[str] = None, - viewport: typing.Optional[ViewportSize] = None, + viewport: typing.Optional[ + typing.Union[Literal["maximized"], ViewportSize] + ] = None, ) -> "Page": """Browser.new_page @@ -1833,9 +1847,19 @@ async def new_page( for a list of supported timezone IDs. Defaults to the system timezone. user_agent : Union[str, None] Specific user agent to use in this context. - viewport : Union[{width: int, height: int}, None] + viewport : Union["maximized", {width: int, height: int}, None] Sets a consistent viewport for each page. Defaults to an 1280x720 viewport. `no_viewport` disables the fixed - viewport. Learn more about [viewport emulation](../emulation.md#viewport). + viewport. Learn more about [viewport emulation](../emulation.md#viewport). Use `viewport="maximized"` to disable + viewport emulation and maximize native browser windows. This is only supported in headed mode and does not enter + fullscreen mode or trigger the web Fullscreen API. + + On Linux with X11, native window maximization requires a window manager. Xvfb alone does not provide one. Use a + fixed viewport if you need consistent page dimensions without a window manager. + + **NOTE** The `no_viewport=True` and `viewport="maximized"` values opt out from the default presets and make + viewport depend on the host window size defined by the operating system. It makes the execution of the tests + non-deterministic. + Returns ------- @@ -4052,6 +4076,8 @@ async def connect_over_cdp( - `x-playwright-extension-tab-group-color` - the color of the tab group: `green`, `blue`, `purple`, `orange`, `pink`, `cyan`, `yellow` or `red`. - `x-playwright-extension-background` - pass `true` to keep the tabs from becoming active. + - `x-playwright-extension-close-tabs-on-disconnect` - pass `true` to close the tabs of the connection when the + client disconnects. This includes the tabs that the user picked for the connection. is_local : Union[bool, None] Tells Playwright that it runs on the same host as the CDP server. It will enable certain optimizations that rely upon the file system being the same between Playwright and the Browser. @@ -4304,7 +4330,9 @@ async def launch_persistent_context( timezone_id: typing.Optional[str] = None, traces_dir: typing.Optional[typing.Union[str, pathlib.Path]] = None, user_agent: typing.Optional[str] = None, - viewport: typing.Optional[ViewportSize] = None, + viewport: typing.Optional[ + typing.Union[Literal["maximized"], ViewportSize] + ] = None, ) -> "BrowserContext": """BrowserType.launch_persistent_context @@ -4514,9 +4542,19 @@ async def launch_persistent_context( If specified, traces are saved into this directory. user_agent : Union[str, None] Specific user agent to use in this context. - viewport : Union[{width: int, height: int}, None] + viewport : Union["maximized", {width: int, height: int}, None] Sets a consistent viewport for each page. Defaults to an 1280x720 viewport. `no_viewport` disables the fixed - viewport. Learn more about [viewport emulation](../emulation.md#viewport). + viewport. Learn more about [viewport emulation](../emulation.md#viewport). Use `viewport="maximized"` to disable + viewport emulation and maximize native browser windows. This is only supported in headed mode and does not enter + fullscreen mode or trigger the web Fullscreen API. + + On Linux with X11, native window maximization requires a window manager. Xvfb alone does not provide one. Use a + fixed viewport if you need consistent page dimensions without a window manager. + + **NOTE** The `no_viewport=True` and `viewport="maximized"` values opt out from the default presets and make + viewport depend on the host window size defined by the operating system. It makes the execution of the tests + non-deterministic. + Returns ------- @@ -12707,7 +12745,7 @@ def last(self) -> "Locator": **Usage** ```py - banana = await page.get_by_role(\"listitem\").last + banana = page.get_by_role(\"listitem\").last ``` Returns @@ -12812,7 +12850,7 @@ def nth(self, index: int) -> "Locator": **Usage** ```py - banana = await page.get_by_role(\"listitem\").nth(2) + banana = page.get_by_role(\"listitem\").nth(2) ``` Parameters @@ -17079,7 +17117,7 @@ def expect_event( ```py async with page.expect_event(\"framenavigated\") as event_info: - await page.get_by_role(\"button\") + await page.get_by_role(\"button\").click() frame = await event_info.value ``` diff --git a/playwright/sync_api/_generated.py b/playwright/sync_api/_generated.py index f2379b503..1888cd1c2 100644 --- a/playwright/sync_api/_generated.py +++ b/playwright/sync_api/_generated.py @@ -1450,7 +1450,9 @@ def new_context( strict_selectors: typing.Optional[bool] = None, timezone_id: typing.Optional[str] = None, user_agent: typing.Optional[str] = None, - viewport: typing.Optional[ViewportSize] = None, + viewport: typing.Optional[ + typing.Union[Literal["maximized"], ViewportSize] + ] = None, ) -> "BrowserContext": """Browser.new_context @@ -1610,9 +1612,19 @@ def new_context( for a list of supported timezone IDs. Defaults to the system timezone. user_agent : Union[str, None] Specific user agent to use in this context. - viewport : Union[{width: int, height: int}, None] + viewport : Union["maximized", {width: int, height: int}, None] Sets a consistent viewport for each page. Defaults to an 1280x720 viewport. `no_viewport` disables the fixed - viewport. Learn more about [viewport emulation](../emulation.md#viewport). + viewport. Learn more about [viewport emulation](../emulation.md#viewport). Use `viewport="maximized"` to disable + viewport emulation and maximize native browser windows. This is only supported in headed mode and does not enter + fullscreen mode or trigger the web Fullscreen API. + + On Linux with X11, native window maximization requires a window manager. Xvfb alone does not provide one. Use a + fixed viewport if you need consistent page dimensions without a window manager. + + **NOTE** The `no_viewport=True` and `viewport="maximized"` values opt out from the default presets and make + viewport depend on the host window size defined by the operating system. It makes the execution of the tests + non-deterministic. + Returns ------- @@ -1712,7 +1724,9 @@ def new_page( strict_selectors: typing.Optional[bool] = None, timezone_id: typing.Optional[str] = None, user_agent: typing.Optional[str] = None, - viewport: typing.Optional[ViewportSize] = None, + viewport: typing.Optional[ + typing.Union[Literal["maximized"], ViewportSize] + ] = None, ) -> "Page": """Browser.new_page @@ -1856,9 +1870,19 @@ def new_page( for a list of supported timezone IDs. Defaults to the system timezone. user_agent : Union[str, None] Specific user agent to use in this context. - viewport : Union[{width: int, height: int}, None] + viewport : Union["maximized", {width: int, height: int}, None] Sets a consistent viewport for each page. Defaults to an 1280x720 viewport. `no_viewport` disables the fixed - viewport. Learn more about [viewport emulation](../emulation.md#viewport). + viewport. Learn more about [viewport emulation](../emulation.md#viewport). Use `viewport="maximized"` to disable + viewport emulation and maximize native browser windows. This is only supported in headed mode and does not enter + fullscreen mode or trigger the web Fullscreen API. + + On Linux with X11, native window maximization requires a window manager. Xvfb alone does not provide one. Use a + fixed viewport if you need consistent page dimensions without a window manager. + + **NOTE** The `no_viewport=True` and `viewport="maximized"` values opt out from the default presets and make + viewport depend on the host window size defined by the operating system. It makes the execution of the tests + non-deterministic. + Returns ------- @@ -3976,6 +4000,8 @@ def connect_over_cdp( - `x-playwright-extension-tab-group-color` - the color of the tab group: `green`, `blue`, `purple`, `orange`, `pink`, `cyan`, `yellow` or `red`. - `x-playwright-extension-background` - pass `true` to keep the tabs from becoming active. + - `x-playwright-extension-close-tabs-on-disconnect` - pass `true` to close the tabs of the connection when the + client disconnects. This includes the tabs that the user picked for the connection. is_local : Union[bool, None] Tells Playwright that it runs on the same host as the CDP server. It will enable certain optimizations that rely upon the file system being the same between Playwright and the Browser. @@ -4232,7 +4258,9 @@ def launch_persistent_context( timezone_id: typing.Optional[str] = None, traces_dir: typing.Optional[typing.Union[str, pathlib.Path]] = None, user_agent: typing.Optional[str] = None, - viewport: typing.Optional[ViewportSize] = None, + viewport: typing.Optional[ + typing.Union[Literal["maximized"], ViewportSize] + ] = None, ) -> "BrowserContext": """BrowserType.launch_persistent_context @@ -4442,9 +4470,19 @@ def launch_persistent_context( If specified, traces are saved into this directory. user_agent : Union[str, None] Specific user agent to use in this context. - viewport : Union[{width: int, height: int}, None] + viewport : Union["maximized", {width: int, height: int}, None] Sets a consistent viewport for each page. Defaults to an 1280x720 viewport. `no_viewport` disables the fixed - viewport. Learn more about [viewport emulation](../emulation.md#viewport). + viewport. Learn more about [viewport emulation](../emulation.md#viewport). Use `viewport="maximized"` to disable + viewport emulation and maximize native browser windows. This is only supported in headed mode and does not enter + fullscreen mode or trigger the web Fullscreen API. + + On Linux with X11, native window maximization requires a window manager. Xvfb alone does not provide one. Use a + fixed viewport if you need consistent page dimensions without a window manager. + + **NOTE** The `no_viewport=True` and `viewport="maximized"` values opt out from the default presets and make + viewport depend on the host window size defined by the operating system. It makes the execution of the tests + non-deterministic. + Returns ------- @@ -17242,7 +17280,7 @@ def expect_event( ```py with page.expect_event(\"framenavigated\") as event_info: - page.get_by_role(\"button\") + page.get_by_role(\"button\").click() frame = event_info.value ``` diff --git a/tests/async/library/chromium/test_connect_over_cdp.py b/tests/async/library/chromium/test_connect_over_cdp.py index 6e2f0e14f..3b9ecddad 100644 --- a/tests/async/library/chromium/test_connect_over_cdp.py +++ b/tests/async/library/chromium/test_connect_over_cdp.py @@ -17,6 +17,7 @@ import asyncio import json import os +import re import signal import sys import urllib.parse @@ -98,7 +99,22 @@ async def test_CD_001_should_connect_to_an_existing_cdp_session( user_data_dir, **launch_arguments, args=["--remote-debugging-port=0"] ) try: - port = (user_data_dir / "DevToolsActivePort").read_text().splitlines()[0] + # The browser writes this file some time after the launch, and not atomically. + active_port = "" + # Python: expect.poll() with the upstream expectation timeout. + deadline = asyncio.get_running_loop().time() + 10 + while ( + not re.match(r"^\d+\n/devtools/browser/.+", active_port) + and asyncio.get_running_loop().time() < deadline + ): + try: + active_port = (user_data_dir / "DevToolsActivePort").read_text() + except OSError: + active_port = "" + if not re.match(r"^\d+\n/devtools/browser/.+", active_port): + await asyncio.sleep(0.1) + assert re.match(r"^\d+\n/devtools/browser/.+", active_port) + port = active_port.split("\n")[0] cdp_browser = await browser_type.connect_over_cdp( endpoint_url=f"http://127.0.0.1:{port}/", ) diff --git a/tests/async/library/test_browsercontext_basic.py b/tests/async/library/test_browsercontext_basic.py index 9e0c8d321..345c0e680 100644 --- a/tests/async/library/test_browsercontext_basic.py +++ b/tests/async/library/test_browsercontext_basic.py @@ -254,6 +254,41 @@ async def test_BC_010_should_not_allow_is_mobile_with_null_viewport( ) +async def test_BC_085_should_not_allow_device_scale_factor_with_maximized_viewport( + browser: Browser, +) -> None: + with pytest.raises(Error) as exc_info: + await browser.new_context(viewport="maximized", device_scale_factor=1) + assert ( + '"deviceScaleFactor" option is not supported with "maximized" viewport' + in exc_info.value.message + ) + + +async def test_BC_086_should_not_allow_is_mobile_with_maximized_viewport( + browser: Browser, +) -> None: + with pytest.raises(Error) as exc_info: + await browser.new_context(viewport="maximized", is_mobile=True) + assert ( + '"isMobile" option is not supported with "maximized" viewport' + in exc_info.value.message + ) + + +async def test_BC_087_should_not_allow_maximized_viewport_in_headless_mode( + browser: Browser, headless: bool +) -> None: + if not headless: + pytest.skip("requires a headless browser") + with pytest.raises(Error) as exc_info: + await browser.new_context(viewport="maximized") + assert ( + '"maximized" viewport is not supported in headless mode' + in exc_info.value.message + ) + + async def test_BC_011_close_should_work_for_empty_context(browser: Browser) -> None: context = await browser.new_context() await context.close() diff --git a/tests/async/library/test_headful.py b/tests/async/library/test_headful.py index 815cc1c65..6d8f45195 100644 --- a/tests/async/library/test_headful.py +++ b/tests/async/library/test_headful.py @@ -20,6 +20,8 @@ """ import asyncio +import os +import sys from pathlib import Path from typing import ( Any, @@ -341,6 +343,99 @@ async def test_HE_011_should_not_override_viewport_size_when_passed_null( await context.close() +async def window_is_maximized(page: Page, browser_name: str) -> bool: + use_screen_height = browser_name == "firefox" and sys.platform == "darwin" + return await page.evaluate( + """useScreenHeight => { + // Firefox maximizes behind the macOS Dock, beyond screen.availHeight. + const expectedHeight = useScreenHeight ? screen.height - screenY : screen.availHeight; + return Math.abs(outerWidth - screen.availWidth) <= 20 && Math.abs(outerHeight - expectedHeight) <= 20; + }""", + use_screen_height, + ) + + +async def test_HE_017_maximized_viewport_should_create_context_in_maximized_window_without_entering_fullscreen( + browser: Browser, browser_name: str +) -> None: + if os.environ.get("PWTEST_NO_WINDOW_MANAGER") == "1": + pytest.skip("native maximization requires a window manager") + context = await browser.new_context(viewport="maximized") + page = await context.new_page() + assert await window_is_maximized(page, browser_name) + assert await page.evaluate("() => document.fullscreenElement") is None + await context.close() + + +async def test_HE_018_maximized_viewport_should_open_shift_clicked_links_in_maximized_windows( + browser: Browser, browser_name: str, server: Server +) -> None: + if os.environ.get("PWTEST_NO_WINDOW_MANAGER") == "1": + pytest.skip("native maximization requires a window manager") + context = await browser.new_context(viewport="maximized") + page = await context.new_page() + await page.set_content(f'link') + async with context.expect_page() as popup_info: + await page.click("a", modifiers=["Shift"]) + popup = await popup_info.value + assert await window_is_maximized(popup, browser_name) + await context.close() + + +async def test_HE_019_maximized_viewport_should_respect_explicitly_sized_popup_geometry( + browser: Browser, browser_name: str, server: Server +) -> None: + context = await browser.new_context(viewport="maximized") + page = await context.new_page() + await page.goto(server.EMPTY_PAGE) + async with page.expect_popup() as popup_info: + await page.evaluate( + "() => window.open('', '_blank', 'left=100,top=100,width=320,height=320')" + ) + popup = await popup_info.value + assert await popup.evaluate( + "() => ({ width: innerWidth, height: innerHeight })" + ) == {"width": 320, "height": 320} + assert not await window_is_maximized(popup, browser_name) + await context.close() + + +async def test_HE_020_maximized_viewport_should_override_maximized_viewport_when_resizing_a_page( + browser: Browser, browser_name: str +) -> None: + if os.environ.get("PWTEST_NO_WINDOW_MANAGER") == "1": + pytest.skip("native maximization requires a window manager") + context = await browser.new_context(viewport="maximized") + page = await context.new_page() + assert await window_is_maximized(page, browser_name) + outer_size = await page.evaluate( + "() => ({ width: outerWidth, height: outerHeight })" + ) + await page.set_viewport_size({"width": 567, "height": 345}) + assert page.viewport_size == {"width": 567, "height": 345} + assert await page.evaluate( + "() => ({ width: window.innerWidth, height: window.innerHeight })" + ) == {"width": 567, "height": 345} + assert await page.evaluate( + "size => outerWidth < size.width && outerHeight < size.height", outer_size + ) + assert not await window_is_maximized(page, browser_name) + new_page = await context.new_page() + assert new_page.viewport_size is None + assert await window_is_maximized(new_page, browser_name) + assert page.viewport_size == {"width": 567, "height": 345} + await context.close() + + +async def test_HE_021_maximized_viewport_should_launch_persistent_context_in_maximized_window( + browser_name: str, launch_persistent: LaunchPersistent +) -> None: + if os.environ.get("PWTEST_NO_WINDOW_MANAGER") == "1": + pytest.skip("native maximization requires a window manager") + _, page = await launch_persistent(viewport="maximized") + assert await window_is_maximized(page, browser_name) + + async def test_HE_012_page_bring_to_front_should_work(browser: Browser) -> None: page1 = await browser.new_page() await page1.set_content("Page1") diff --git a/tests/async/library/test_tracing.py b/tests/async/library/test_tracing.py index a6e7a71ec..0d4bb77aa 100644 --- a/tests/async/library/test_tracing.py +++ b/tests/async/library/test_tracing.py @@ -151,6 +151,12 @@ async def test_TR_001_should_collect_trace_with_resources_but_no_js( await page.locator('input[type="file"]').set_input_files( assetdir / "file-to-upload.txt" ) + input = await page.query_selector('input[type="file"]') + assert input + await input.set_input_files(assetdir / "file-to-upload.txt") + await page.add_locator_handler(page.locator("dialog"), lambda: None) + await page.add_locator_handler(page.locator("dialog"), lambda: None) + await page.remove_locator_handler(page.locator("dialog")) await page.wait_for_timeout(2000) # Give it some time to produce screenshots. await page.close() await context.tracing.stop(path=tmp_path / "trace.zip") @@ -167,6 +173,11 @@ async def test_TR_001_should_collect_trace_with_resources_but_no_js( 'Insert "abc"', f"Navigate {server.HOST}/input/fileupload.html", """Set input files locator('input[type="file"]')""", + """Query selector locator('input[type="file"]')""", + "Set input files", + """Register locator handler locator('dialog')""", + """Register locator handler locator('dialog')""", + "Unregister locator handler", "Wait for timeout", "Close page", ] diff --git a/tests/async/page/test_page_goto.py b/tests/async/page/test_page_goto.py index 9c8a3e74d..f29088b6f 100644 --- a/tests/async/page/test_page_goto.py +++ b/tests/async/page/test_page_goto.py @@ -16,9 +16,10 @@ import asyncio import contextlib +import os import warnings from pathlib import Path -from typing import Any, Callable, List, Optional, Set, cast +from typing import Any, Awaitable, Callable, List, Optional, Set, cast import pytest @@ -147,6 +148,134 @@ async def test_NA_007_should_work_with_cross_process_that_fails_before_committin await page.goto(server.EMPTY_PAGE) +async def test_NA_098_should_work_with_redirect_chain_through_visited_sites( + page: Page, server: Server, browser_channel: Optional[str] +) -> None: + if os.environ.get("INSIDE_DOCKER"): + pytest.skip("docker does not support IPv6 by default") + if browser_channel == "webkit-wsl": + pytest.skip( + "WebKit on WSL does not support IPv6: https://github.com/microsoft/WSL/issues/10803" + ) + third_site = f"http://[::1]:{server.PORT}" + server.set_redirect("/redirect1", server.CROSS_PROCESS_PREFIX + "/redirect2") + server.set_redirect("/redirect2", server.EMPTY_PAGE) + # WebKit reuses the processes of the previously visited sites for the redirects. + for site in [server.PREFIX, server.CROSS_PROCESS_PREFIX, third_site]: + await must(await page.goto(site + "/empty.html")).finished() + response = must(await page.goto(third_site + "/redirect1")) + assert response.status == 200 + assert page.url == server.EMPTY_PAGE + + +async def test_NA_099_should_fail_request_of_a_canceled_cross_process_navigation( + page: Page, server: Server +) -> None: + server.set_route("/hang.html", lambda request: None) + await page.goto(server.EMPTY_PAGE) + async with page.expect_event("requestfailed") as request_failed_info: + # Python: keep the rejected navigation task handled until it is awaited. + async def navigate() -> Error: + with pytest.raises(Error) as exc_info: + await page.goto(server.CROSS_PROCESS_PREFIX + "/hang.html") + return exc_info.value + + error = asyncio.create_task(navigate()) + await server.wait_for_request("/hang.html") + await page.goto(server.PREFIX + "/title.html") + assert ( + await request_failed_info.value + ).url == server.CROSS_PROCESS_PREFIX + "/hang.html" + assert isinstance(await error, Error) + + +async def expect_redirect_chain( + page: Page, navigate: Callable[[], Awaitable[Optional[Response]]], urls: List[str] +) -> None: + finished: List[str] = [] + failed: List[str] = [] + page.on("requestfinished", lambda request: finished.append(request.url)) + page.on("requestfailed", lambda request: failed.append(request.url)) + response = must(await navigate()) + chain: List[Request] = [] + request: Optional[Request] = response.request + while request: + chain.insert(0, request) + request = request.redirected_from + assert [request.url for request in chain] == urls + + async def status(request: Request) -> int: + return must(await request.response()).status + + statuses = await asyncio.gather(*(status(request) for request in chain)) + assert statuses == [302 for _ in urls[1:]] + [200] + # Python: expect.poll() with the upstream expectation timeout. + deadline = asyncio.get_running_loop().time() + 10 + while [ + url for url in urls if url not in finished + ] and asyncio.get_running_loop().time() < deadline: + await asyncio.sleep(0.1) + assert [url for url in urls if url not in finished] == [] + assert failed == [] + + +async def test_NA_100_should_report_cross_process_redirect_chain_back_to_the_initial_site( + page: Page, server: Server +) -> None: + server.set_redirect("/redirect1", server.CROSS_PROCESS_PREFIX + "/redirect2") + server.set_redirect("/redirect2", server.EMPTY_PAGE) + # WebKit reuses the process of the previously visited site for the redirect. + await must(await page.goto(server.CROSS_PROCESS_PREFIX + "/empty.html")).finished() + await must(await page.goto(server.PREFIX + "/title.html")).finished() + await expect_redirect_chain( + page, + lambda: page.goto(server.PREFIX + "/redirect1"), + [ + server.PREFIX + "/redirect1", + server.CROSS_PROCESS_PREFIX + "/redirect2", + server.EMPTY_PAGE, + ], + ) + + +@pytest.mark.parametrize("with_route", [False, True]) +async def test_NA_101_should_report_cross_process_redirect_chain_through_visited( + page: Page, server: Server, browser_channel: Optional[str], with_route: bool +) -> None: + if os.environ.get("INSIDE_DOCKER"): + pytest.skip("docker does not support IPv6 by default") + if browser_channel == "webkit-wsl": + pytest.skip( + "WebKit on WSL does not support IPv6: https://github.com/microsoft/WSL/issues/10803" + ) + third_site = f"http://[::1]:{server.PORT}" + server.set_redirect("/redirect1", server.CROSS_PROCESS_PREFIX + "/redirect2") + server.set_redirect("/redirect2", server.EMPTY_PAGE) + # WebKit reuses the processes of the previously visited sites for the redirects. + for site in [server.PREFIX, server.CROSS_PROCESS_PREFIX, third_site]: + await must(await page.goto(site + "/empty.html")).finished() + routed: List[str] = [] + if with_route: + + async def handle(route: Route) -> None: + routed.append(route.request.url) + await route.continue_() + + await page.route("**/*", handle) + await expect_redirect_chain( + page, + lambda: page.goto(third_site + "/redirect1"), + [ + third_site + "/redirect1", + server.CROSS_PROCESS_PREFIX + "/redirect2", + server.EMPTY_PAGE, + ], + ) + # Redirects are not intercepted. + if with_route: + assert routed == [third_site + "/redirect1"] + + def serve_coop_page(request: TestServerRequest) -> None: request.setHeader("Cross-Origin-Opener-Policy", "same-origin") # Note: without 'onload', Firefox sometimes does not fire the load event diff --git a/tests/sync/library/chromium/test_connect_over_cdp.py b/tests/sync/library/chromium/test_connect_over_cdp.py index 99a2b4ac1..c95bc4339 100644 --- a/tests/sync/library/chromium/test_connect_over_cdp.py +++ b/tests/sync/library/chromium/test_connect_over_cdp.py @@ -16,6 +16,7 @@ import json import os +import re import signal import sys import time @@ -110,7 +111,22 @@ def test_CD_001_should_connect_to_an_existing_cdp_session( user_data_dir, **launch_arguments, args=["--remote-debugging-port=0"] ) try: - port = (user_data_dir / "DevToolsActivePort").read_text().splitlines()[0] + # The browser writes this file some time after the launch, and not atomically. + active_port = "" + # Python: expect.poll() with the upstream expectation timeout. + deadline = time.monotonic() + 10 + while ( + not re.match(r"^\d+\n/devtools/browser/.+", active_port) + and time.monotonic() < deadline + ): + try: + active_port = (user_data_dir / "DevToolsActivePort").read_text() + except OSError: + active_port = "" + if not re.match(r"^\d+\n/devtools/browser/.+", active_port): + time.sleep(0.1) + assert re.match(r"^\d+\n/devtools/browser/.+", active_port) + port = active_port.split("\n")[0] cdp_browser = browser_type.connect_over_cdp( endpoint_url=f"http://127.0.0.1:{port}/", ) diff --git a/tests/sync/library/test_browsercontext_basic.py b/tests/sync/library/test_browsercontext_basic.py index bef778d40..f69ad0d25 100644 --- a/tests/sync/library/test_browsercontext_basic.py +++ b/tests/sync/library/test_browsercontext_basic.py @@ -257,6 +257,41 @@ def test_BC_010_should_not_allow_is_mobile_with_null_viewport( ) +def test_BC_085_should_not_allow_device_scale_factor_with_maximized_viewport( + browser: Browser, +) -> None: + with pytest.raises(Error) as exc_info: + browser.new_context(viewport="maximized", device_scale_factor=1) + assert ( + '"deviceScaleFactor" option is not supported with "maximized" viewport' + in exc_info.value.message + ) + + +def test_BC_086_should_not_allow_is_mobile_with_maximized_viewport( + browser: Browser, +) -> None: + with pytest.raises(Error) as exc_info: + browser.new_context(viewport="maximized", is_mobile=True) + assert ( + '"isMobile" option is not supported with "maximized" viewport' + in exc_info.value.message + ) + + +def test_BC_087_should_not_allow_maximized_viewport_in_headless_mode( + browser: Browser, headless: bool +) -> None: + if not headless: + pytest.skip("requires a headless browser") + with pytest.raises(Error) as exc_info: + browser.new_context(viewport="maximized") + assert ( + '"maximized" viewport is not supported in headless mode' + in exc_info.value.message + ) + + def test_BC_011_close_should_work_for_empty_context(browser: Browser) -> None: context = browser.new_context() context.close() diff --git a/tests/sync/library/test_headful.py b/tests/sync/library/test_headful.py index 9500c1ab7..af6a28642 100644 --- a/tests/sync/library/test_headful.py +++ b/tests/sync/library/test_headful.py @@ -19,6 +19,8 @@ when there is no display. """ +import os +import sys import time from pathlib import Path from typing import Any, Callable, Dict, Generator, List, Optional, Tuple @@ -332,6 +334,98 @@ def test_HE_011_should_not_override_viewport_size_when_passed_null( context.close() +def window_is_maximized(page: Page, browser_name: str) -> bool: + use_screen_height = browser_name == "firefox" and sys.platform == "darwin" + return page.evaluate( + """useScreenHeight => { + // Firefox maximizes behind the macOS Dock, beyond screen.availHeight. + const expectedHeight = useScreenHeight ? screen.height - screenY : screen.availHeight; + return Math.abs(outerWidth - screen.availWidth) <= 20 && Math.abs(outerHeight - expectedHeight) <= 20; + }""", + use_screen_height, + ) + + +def test_HE_017_maximized_viewport_should_create_context_in_maximized_window_without_entering_fullscreen( + browser: Browser, browser_name: str +) -> None: + if os.environ.get("PWTEST_NO_WINDOW_MANAGER") == "1": + pytest.skip("native maximization requires a window manager") + context = browser.new_context(viewport="maximized") + page = context.new_page() + assert window_is_maximized(page, browser_name) + assert page.evaluate("() => document.fullscreenElement") is None + context.close() + + +def test_HE_018_maximized_viewport_should_open_shift_clicked_links_in_maximized_windows( + browser: Browser, browser_name: str, server: Server +) -> None: + if os.environ.get("PWTEST_NO_WINDOW_MANAGER") == "1": + pytest.skip("native maximization requires a window manager") + context = browser.new_context(viewport="maximized") + page = context.new_page() + page.set_content(f'link') + with context.expect_page() as popup_info: + page.click("a", modifiers=["Shift"]) + popup = popup_info.value + assert window_is_maximized(popup, browser_name) + context.close() + + +def test_HE_019_maximized_viewport_should_respect_explicitly_sized_popup_geometry( + browser: Browser, browser_name: str, server: Server +) -> None: + context = browser.new_context(viewport="maximized") + page = context.new_page() + page.goto(server.EMPTY_PAGE) + with page.expect_popup() as popup_info: + page.evaluate( + "() => window.open('', '_blank', 'left=100,top=100,width=320,height=320')" + ) + popup = popup_info.value + assert popup.evaluate("() => ({ width: innerWidth, height: innerHeight })") == { + "width": 320, + "height": 320, + } + assert not window_is_maximized(popup, browser_name) + context.close() + + +def test_HE_020_maximized_viewport_should_override_maximized_viewport_when_resizing_a_page( + browser: Browser, browser_name: str +) -> None: + if os.environ.get("PWTEST_NO_WINDOW_MANAGER") == "1": + pytest.skip("native maximization requires a window manager") + context = browser.new_context(viewport="maximized") + page = context.new_page() + assert window_is_maximized(page, browser_name) + outer_size = page.evaluate("() => ({ width: outerWidth, height: outerHeight })") + page.set_viewport_size({"width": 567, "height": 345}) + assert page.viewport_size == {"width": 567, "height": 345} + assert page.evaluate( + "() => ({ width: window.innerWidth, height: window.innerHeight })" + ) == {"width": 567, "height": 345} + assert page.evaluate( + "size => outerWidth < size.width && outerHeight < size.height", outer_size + ) + assert not window_is_maximized(page, browser_name) + new_page = context.new_page() + assert new_page.viewport_size is None + assert window_is_maximized(new_page, browser_name) + assert page.viewport_size == {"width": 567, "height": 345} + context.close() + + +def test_HE_021_maximized_viewport_should_launch_persistent_context_in_maximized_window( + browser_name: str, launch_persistent: LaunchPersistent +) -> None: + if os.environ.get("PWTEST_NO_WINDOW_MANAGER") == "1": + pytest.skip("native maximization requires a window manager") + _, page = launch_persistent(viewport="maximized") + assert window_is_maximized(page, browser_name) + + def test_HE_012_page_bring_to_front_should_work(browser: Browser) -> None: page1 = browser.new_page() page1.set_content("Page1") diff --git a/tests/sync/library/test_tracing.py b/tests/sync/library/test_tracing.py index edcdfdede..c2e95aac0 100644 --- a/tests/sync/library/test_tracing.py +++ b/tests/sync/library/test_tracing.py @@ -163,6 +163,12 @@ def test_TR_001_should_collect_trace_with_resources_but_no_js( page.keyboard.insert_text("abc") page.goto(server.PREFIX + "/input/fileupload.html") page.locator('input[type="file"]').set_input_files(assetdir / "file-to-upload.txt") + input = page.query_selector('input[type="file"]') + assert input + input.set_input_files(assetdir / "file-to-upload.txt") + page.add_locator_handler(page.locator("dialog"), lambda: None) + page.add_locator_handler(page.locator("dialog"), lambda: None) + page.remove_locator_handler(page.locator("dialog")) page.wait_for_timeout(2000) # Give it some time to produce screenshots. page.close() context.tracing.stop(path=tmp_path / "trace.zip") @@ -179,6 +185,11 @@ def test_TR_001_should_collect_trace_with_resources_but_no_js( 'Insert "abc"', f"Navigate {server.HOST}/input/fileupload.html", """Set input files locator('input[type="file"]')""", + """Query selector locator('input[type="file"]')""", + "Set input files", + """Register locator handler locator('dialog')""", + """Register locator handler locator('dialog')""", + "Unregister locator handler", "Wait for timeout", "Close page", ] diff --git a/tests/sync/page/test_page_goto.py b/tests/sync/page/test_page_goto.py index f26c1f99d..94f17a45a 100644 --- a/tests/sync/page/test_page_goto.py +++ b/tests/sync/page/test_page_goto.py @@ -14,13 +14,17 @@ """Port of tests/page/page-goto.spec.ts.""" +import asyncio import contextlib +import os +import time import warnings from pathlib import Path from typing import Any, Callable, List, Optional, Set, cast import pytest +from playwright._impl._greenlets import wait_for_future from playwright.sync_api import ( Error, Frame, @@ -151,6 +155,143 @@ def test_NA_007_should_work_with_cross_process_that_fails_before_committing( page.goto(server.EMPTY_PAGE) +def test_NA_098_should_work_with_redirect_chain_through_visited_sites( + page: Page, server: Server, browser_channel: Optional[str] +) -> None: + if os.environ.get("INSIDE_DOCKER"): + pytest.skip("docker does not support IPv6 by default") + if browser_channel == "webkit-wsl": + pytest.skip( + "WebKit on WSL does not support IPv6: https://github.com/microsoft/WSL/issues/10803" + ) + third_site = f"http://[::1]:{server.PORT}" + server.set_redirect("/redirect1", server.CROSS_PROCESS_PREFIX + "/redirect2") + server.set_redirect("/redirect2", server.EMPTY_PAGE) + # WebKit reuses the processes of the previously visited sites for the redirects. + for site in [server.PREFIX, server.CROSS_PROCESS_PREFIX, third_site]: + must(page.goto(site + "/empty.html")).finished() + response = must(page.goto(third_site + "/redirect1")) + assert response.status == 200 + assert page.url == server.EMPTY_PAGE + + +def test_NA_099_should_fail_request_of_a_canceled_cross_process_navigation( + page: Page, server: Server, sync_gather: Callable[..., List[Any]] +) -> None: + server.set_route("/hang.html", lambda request: None) + page.goto(server.EMPTY_PAGE) + with page.expect_event("requestfailed") as request_failed_info: + + def navigate() -> Error: + with pytest.raises(Error) as exc_info: + page.goto(server.CROSS_PROCESS_PREFIX + "/hang.html") + return exc_info.value + + def navigate_again() -> None: + # Python: drive the sync event loop while awaiting the server request. + request = asyncio.ensure_future( + server.wait_for_request("/hang.html"), loop=page._loop + ) + wait_for_future(page._loop, page._dispatcher_fiber, request) + page.goto(server.PREFIX + "/title.html") + + error, _ = sync_gather(navigate, navigate_again) + assert request_failed_info.value.url == server.CROSS_PROCESS_PREFIX + "/hang.html" + assert isinstance(error, Error) + + +def expect_redirect_chain( + page: Page, + navigate: Callable[[], Optional[Response]], + urls: List[str], + sync_gather: Callable[..., List[Any]], +) -> None: + finished: List[str] = [] + failed: List[str] = [] + page.on("requestfinished", lambda request: finished.append(request.url)) + page.on("requestfailed", lambda request: failed.append(request.url)) + response = must(navigate()) + chain: List[Request] = [] + request: Optional[Request] = response.request + while request: + chain.insert(0, request) + request = request.redirected_from + assert [request.url for request in chain] == urls + statuses = sync_gather( + *(lambda request=request: must(request.response()).status for request in chain) + ) + assert statuses == [302 for _ in urls[1:]] + [200] + # Python: expect.poll() with the upstream expectation timeout. + deadline = time.monotonic() + 10 + while [url for url in urls if url not in finished] and time.monotonic() < deadline: + page.wait_for_timeout(100) + assert [url for url in urls if url not in finished] == [] + assert failed == [] + + +def test_NA_100_should_report_cross_process_redirect_chain_back_to_the_initial_site( + page: Page, server: Server, sync_gather: Callable[..., List[Any]] +) -> None: + server.set_redirect("/redirect1", server.CROSS_PROCESS_PREFIX + "/redirect2") + server.set_redirect("/redirect2", server.EMPTY_PAGE) + # WebKit reuses the process of the previously visited site for the redirect. + must(page.goto(server.CROSS_PROCESS_PREFIX + "/empty.html")).finished() + must(page.goto(server.PREFIX + "/title.html")).finished() + expect_redirect_chain( + page, + lambda: page.goto(server.PREFIX + "/redirect1"), + [ + server.PREFIX + "/redirect1", + server.CROSS_PROCESS_PREFIX + "/redirect2", + server.EMPTY_PAGE, + ], + sync_gather, + ) + + +@pytest.mark.parametrize("with_route", [False, True]) +def test_NA_101_should_report_cross_process_redirect_chain_through_visited( + page: Page, + server: Server, + browser_channel: Optional[str], + with_route: bool, + sync_gather: Callable[..., List[Any]], +) -> None: + if os.environ.get("INSIDE_DOCKER"): + pytest.skip("docker does not support IPv6 by default") + if browser_channel == "webkit-wsl": + pytest.skip( + "WebKit on WSL does not support IPv6: https://github.com/microsoft/WSL/issues/10803" + ) + third_site = f"http://[::1]:{server.PORT}" + server.set_redirect("/redirect1", server.CROSS_PROCESS_PREFIX + "/redirect2") + server.set_redirect("/redirect2", server.EMPTY_PAGE) + # WebKit reuses the processes of the previously visited sites for the redirects. + for site in [server.PREFIX, server.CROSS_PROCESS_PREFIX, third_site]: + must(page.goto(site + "/empty.html")).finished() + routed: List[str] = [] + if with_route: + + def handle(route: Route) -> None: + routed.append(route.request.url) + route.continue_() + + page.route("**/*", handle) + expect_redirect_chain( + page, + lambda: page.goto(third_site + "/redirect1"), + [ + third_site + "/redirect1", + server.CROSS_PROCESS_PREFIX + "/redirect2", + server.EMPTY_PAGE, + ], + sync_gather, + ) + # Redirects are not intercepted. + if with_route: + assert routed == [third_site + "/redirect1"] + + def serve_coop_page(request: TestServerRequest) -> None: request.setHeader("Cross-Origin-Opener-Policy", "same-origin") # Note: without 'onload', Firefox sometimes does not fire the load event diff --git a/tests/upstream_not_ported.txt b/tests/upstream_not_ported.txt index bdf755e1f..841b233fd 100644 --- a/tests/upstream_not_ported.txt +++ b/tests/upstream_not_ported.txt @@ -109,6 +109,7 @@ FE-046 Checks that the JavaScript client calls the data object's toJSON() s # library/har HA-066 tracing.startHar({ resourcesDir }) is not in the Python API (langs: js). HA-067 tracing.startHar({ resourcesDir }) is not in the Python API (langs: js). +HA-115 Replaces the server-side response.internalBody through toImpl(context) to hold response bodies during HAR flush; the Python client can not reach server internals. # library/launcher BT-018 playwright.errors is JavaScript-only (docs langs: js); Python exports TimeoutError from the module. BT-020 passes __testHookGracefullyClose, a JS function, as a launch option; only an in-process server can receive it. diff --git a/tests/upstream_registry.md b/tests/upstream_registry.md index 2e8c53808..2a92f44bc 100644 --- a/tests/upstream_registry.md +++ b/tests/upstream_registry.md @@ -478,6 +478,10 @@ subsystem, add a row to the Subsystems table. Then update this file: | `BC-082` | `library/browsercontext-reuse.spec.ts` | reuse {launch, connect} › should work with routeWebSocket *(2 copies)* | | `BC-083` | `library/browsercontext-reuse.spec.ts` | reuse {launch, connect} › should update viewport and media *(2 copies)* | | `BC-084` | `library/browsercontext-basic.spec.ts` | should locate only visible elements when configured | +| `BC-085` | `library/browsercontext-basic.spec.ts` | should not allow deviceScaleFactor with maximized viewport | +| `BC-086` | `library/browsercontext-basic.spec.ts` | should not allow isMobile with maximized viewport | +| `BC-087` | `library/browsercontext-basic.spec.ts` | should not allow maximized viewport in headless mode | +| `BC-088` | `library/browsercontext-reuse.spec.ts` | reuse {launch, connect} › should restore maximized viewport after reset *(2 copies)* | ### BP — Browsers path @@ -1230,6 +1234,7 @@ subsystem, add a row to the Subsystems table. Then update this file: | `CK-219` | `library/unit/clock.spec.ts` | works with slow setTimeout in busy embedder when not paused | | `CK-220` | `library/page-clock.spec.ts` | while on pause › should keep timers scheduled during load pending when paused | | `CK-221` | `library/unit/clock.spec.ts` | runFor › should wait for an in-progress timer after replay pauses the clock | +| `CK-222` | `library/unit/clock.spec.ts` | stubTimers › should keep EventTarget methods on performance | ### CL — Click @@ -3167,6 +3172,7 @@ subsystem, add a row to the Subsystems table. Then update this file: | `HA-112` | `library/har-websocket.spec.ts` | should respect PLAYWRIGHT\_HAR\_NO\_WEBSOCKET\_FRAMES | | `HA-113` | `library/har.spec.ts` | should store binary content with a textual mime type as base64 | | `HA-114` | `library/browsercontext-har.spec.ts` | should reject a malformed har.zip | +| `HA-115` | `library/har.spec.ts` | tracing.startHar › should wait for response bodies added while flushing | ### HE — Headful @@ -3188,6 +3194,11 @@ subsystem, add a row to the Subsystems table. Then update this file: | `HE-014` | `library/headful.spec.ts` | should click bottom row w/ infobar in OOPIF | | `HE-015` | `library/headful.spec.ts` | headless and headful should use same default fonts | | `HE-016` | `library/headful.spec.ts` | should have the same hyphen rendering on headless and headed | +| `HE-017` | `library/headful.spec.ts` | maximized viewport › should create context in maximized window without entering fullscreen | +| `HE-018` | `library/headful.spec.ts` | maximized viewport › should open shift-clicked links in maximized windows | +| `HE-019` | `library/headful.spec.ts` | maximized viewport › should respect explicitly sized popup geometry | +| `HE-020` | `library/headful.spec.ts` | maximized viewport › should override maximized viewport when resizing a page | +| `HE-021` | `library/headful.spec.ts` | maximized viewport › should launch persistent context in maximized window | ### HS — HTTP server @@ -3877,6 +3888,10 @@ subsystem, add a row to the Subsystems table. Then update this file: | `NA-095` | `library/browsercontext-base-url.spec.ts` | should be able to match a URL relative to its given URL with urlMatcher | | `NA-096` | `library/browsercontext-base-url.spec.ts` | should not construct a new URL with baseURL when a glob was used | | `NA-097` | `page/page-goto.spec.ts` | should navigate while a new service worker takes over | +| `NA-098` | `page/page-goto.spec.ts` | should work with redirect chain through visited sites | +| `NA-099` | `page/page-goto.spec.ts` | should fail request of a canceled cross-process navigation | +| `NA-100` | `page/page-goto.spec.ts` | should report cross-process redirect chain back to the initial site | +| `NA-101` | `page/page-goto.spec.ts` | should report cross-process redirect chain through visited {sites, sites with route} *(2 copies)* | ### NE — Network @@ -5261,6 +5276,8 @@ subsystem, add a row to the Subsystems table. Then update this file: | `TV-135` | `library/snapshot-renderer.spec.ts` | stripAnsiEscapes handles common ANSI sequences after fix | | `TV-136` | `library/snapshot-renderer.spec.ts` | snapshot renderer selects the nearest out-of-order screencast frame | | `TV-137` | `library/snapshot-renderer.spec.ts` | snapshot renderer neutralizes declarative shadow roots | +| `TV-138` | `library/snapshot-renderer.spec.ts` | snapshot renderer neutralizes link resource hints | +| `TV-139` | `library/trace-viewer.spec.ts` | should not render link resource hints | ### TZ — Timezone