Skip to content

Commit 12165ce

Browse files
authored
fix: inherit context timeout correctly (#1889)
1 parent b9b8fed commit 12165ce

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

playwright/_impl/_helper.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ class HarLookupResult(TypedDict, total=False):
177177
class TimeoutSettings:
178178
def __init__(self, parent: Optional["TimeoutSettings"]) -> None:
179179
self._parent = parent
180-
self._timeout = 30000.0
181-
self._navigation_timeout = 30000.0
180+
self._timeout: Optional[float] = None
181+
self._navigation_timeout: Optional[float] = None
182182

183183
def set_timeout(self, timeout: float) -> None:
184184
self._timeout = timeout

tests/async/test_page.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import pytest
2020

21-
from playwright.async_api import Error, Page, Route, TimeoutError
21+
from playwright.async_api import BrowserContext, Error, Page, Route, TimeoutError
2222
from tests.server import Server
2323

2424

@@ -331,6 +331,19 @@ async def test_wait_for_response_should_work_with_no_timeout(page, server):
331331
assert response.url == server.PREFIX + "/digits/2.png"
332332

333333

334+
async def test_wait_for_response_should_use_context_timeout(
335+
page: Page, context: BrowserContext, server: Server
336+
) -> None:
337+
await page.goto(server.EMPTY_PAGE)
338+
339+
context.set_default_timeout(1_000)
340+
with pytest.raises(Error) as exc_info:
341+
async with page.expect_response("https://playwright.dev"):
342+
pass
343+
assert exc_info.type is TimeoutError
344+
assert "Timeout 1000ms exceeded" in exc_info.value.message
345+
346+
334347
async def test_expose_binding(page):
335348
binding_source = []
336349

tests/sync/test_sync.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,3 +277,16 @@ def test_expect_response_should_work(page: Page, server: Server) -> None:
277277
assert resp.value.status == 200
278278
assert resp.value.ok
279279
assert resp.value.request
280+
281+
282+
def test_expect_response_should_use_context_timeout(
283+
page: Page, context: BrowserContext, server: Server
284+
) -> None:
285+
page.goto(server.EMPTY_PAGE)
286+
287+
context.set_default_timeout(1_000)
288+
with pytest.raises(Error) as exc_info:
289+
with page.expect_response("https://playwright.dev"):
290+
pass
291+
assert exc_info.type is TimeoutError
292+
assert "Timeout 1000ms exceeded" in exc_info.value.message

0 commit comments

Comments
 (0)