From 22b63ef418a5bf02f7635cd728166feb3d16873b Mon Sep 17 00:00:00 2001 From: Mohammed Alkindi Date: Wed, 7 Oct 2026 22:12:35 -0700 Subject: [PATCH] fix(locator): pass the timeout through in screenshot Fixes: https://github.com/microsoft/playwright/issues/43206 --- playwright/_impl/_locator.py | 1 + tests/async/test_locators.py | 7 +++++++ tests/sync/test_locators.py | 7 +++++++ 3 files changed, 15 insertions(+) diff --git a/playwright/_impl/_locator.py b/playwright/_impl/_locator.py index 2c973eba8..b8a0d78da 100644 --- a/playwright/_impl/_locator.py +++ b/playwright/_impl/_locator.py @@ -588,6 +588,7 @@ async def screenshot( lambda h, timeout: h.screenshot( **{**params, "timeout": timeout}, ), + timeout, ) async def aria_snapshot( diff --git a/tests/async/test_locators.py b/tests/async/test_locators.py index 45293e5e6..60a3a2402 100644 --- a/tests/async/test_locators.py +++ b/tests/async/test_locators.py @@ -411,6 +411,13 @@ async def test_locators_should_screenshot( ) +async def test_locators_screenshot_should_respect_timeout(page: Page) -> None: + page.set_default_timeout(5_000) + await page.set_content("
hello
") + with pytest.raises(Error, match="Locator.screenshot: Timeout 500ms exceeded."): + await page.locator("#missing").screenshot(timeout=500) + + async def test_locators_should_return_bounding_box(page: Page, server: Server) -> None: await page.set_viewport_size( { diff --git a/tests/sync/test_locators.py b/tests/sync/test_locators.py index 1c191f826..fbcfc55c9 100644 --- a/tests/sync/test_locators.py +++ b/tests/sync/test_locators.py @@ -394,6 +394,13 @@ def test_locators_should_screenshot( ) +def test_locators_screenshot_should_respect_timeout(page: Page) -> None: + page.set_default_timeout(5_000) + page.set_content("
hello
") + with pytest.raises(Error, match="Locator.screenshot: Timeout 500ms exceeded."): + page.locator("#missing").screenshot(timeout=500) + + def test_locators_should_return_bounding_box(page: Page, server: Server) -> None: page.set_viewport_size( {