Skip to content

Commit

Permalink
fix: inherit context timeout correctly (#1889)
Browse files Browse the repository at this point in the history
  • Loading branch information
mxschmitt authored May 2, 2023
1 parent b9b8fed commit 12165ce
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
4 changes: 2 additions & 2 deletions playwright/_impl/_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ class HarLookupResult(TypedDict, total=False):
class TimeoutSettings:
def __init__(self, parent: Optional["TimeoutSettings"]) -> None:
self._parent = parent
self._timeout = 30000.0
self._navigation_timeout = 30000.0
self._timeout: Optional[float] = None
self._navigation_timeout: Optional[float] = None

def set_timeout(self, timeout: float) -> None:
self._timeout = timeout
Expand Down
15 changes: 14 additions & 1 deletion tests/async/test_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import pytest

from playwright.async_api import Error, Page, Route, TimeoutError
from playwright.async_api import BrowserContext, Error, Page, Route, TimeoutError
from tests.server import Server


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


async def test_wait_for_response_should_use_context_timeout(
page: Page, context: BrowserContext, server: Server
) -> None:
await page.goto(server.EMPTY_PAGE)

context.set_default_timeout(1_000)
with pytest.raises(Error) as exc_info:
async with page.expect_response("https://playwright.dev"):
pass
assert exc_info.type is TimeoutError
assert "Timeout 1000ms exceeded" in exc_info.value.message


async def test_expose_binding(page):
binding_source = []

Expand Down
13 changes: 13 additions & 0 deletions tests/sync/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,3 +277,16 @@ def test_expect_response_should_work(page: Page, server: Server) -> None:
assert resp.value.status == 200
assert resp.value.ok
assert resp.value.request


def test_expect_response_should_use_context_timeout(
page: Page, context: BrowserContext, server: Server
) -> None:
page.goto(server.EMPTY_PAGE)

context.set_default_timeout(1_000)
with pytest.raises(Error) as exc_info:
with page.expect_response("https://playwright.dev"):
pass
assert exc_info.type is TimeoutError
assert "Timeout 1000ms exceeded" in exc_info.value.message

0 comments on commit 12165ce

Please sign in to comment.