Skip to content

Commit

Permalink
fix: page.pause() timeout reset
Browse files Browse the repository at this point in the history
  • Loading branch information
mxschmitt committed Nov 13, 2023
1 parent 9060038 commit 432dbeb
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 2 deletions.
7 changes: 5 additions & 2 deletions playwright/_impl/_browser_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,15 +248,18 @@ def set_default_navigation_timeout(self, timeout: float) -> None:
def _set_default_navigation_timeout_impl(self, timeout: Optional[float]) -> None:
self._timeout_settings.set_default_navigation_timeout(timeout)
self._channel.send_no_reply(
"setDefaultNavigationTimeoutNoReply", dict(timeout=timeout)
"setDefaultNavigationTimeoutNoReply",
{} if timeout is None else {"timeout": timeout},
)

def set_default_timeout(self, timeout: float) -> None:
return self._set_default_timeout_impl(timeout)

def _set_default_timeout_impl(self, timeout: Optional[float]) -> None:
self._timeout_settings.set_default_timeout(timeout)
self._channel.send_no_reply("setDefaultTimeoutNoReply", dict(timeout=timeout))
self._channel.send_no_reply(
"setDefaultTimeoutNoReply", {} if timeout is None else {"timeout": timeout}
)

@property
def pages(self) -> List[Page]:
Expand Down
30 changes: 30 additions & 0 deletions tests/async/test_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -1294,3 +1294,33 @@ def binding(source, o):
await page.expose_binding("log", lambda source, o: binding(source, o))
await page.evaluate("const a = {}; a.b = a; window.log(a)")
assert binding_values[0]["b"] == binding_values[0]


async def test_page_pause_should_reset_default_timeouts(
page: Page, headless: bool, server: Server
) -> None:
if not headless:
pytest.skip()

await page.goto(server.EMPTY_PAGE)
page.pause()
with pytest.raises(Error, match="Timeout 30000ms exceeded."):
await page.get_by_text("foo").click()


async def test_page_pause_should_reset_custom_timeouts(
page: Page, headless: bool, server: Server
) -> None:
if not headless:
pytest.skip()

page.set_default_timeout(123)
page.set_default_navigation_timeout(456)
await page.goto(server.EMPTY_PAGE)
page.pause()
with pytest.raises(Error, match="Timeout 123ms exceeded."):
await page.get_by_text("foo").click()

server.set_route("/empty.html", lambda route: None)
with pytest.raises(Error, match="Timeout 456ms exceeded."):
await page.goto(server.EMPTY_PAGE)
30 changes: 30 additions & 0 deletions tests/sync/test_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,33 @@ def test_emitted_for_domcontentloaded_and_load(page: Page, server: Server) -> No
page.goto(server.EMPTY_PAGE)
assert isinstance(dom_info.value, Page)
assert isinstance(load_info.value, Page)


def test_page_pause_should_reset_default_timeouts(
page: Page, headless: bool, server: Server
) -> None:
if not headless:
pytest.skip()

page.goto(server.EMPTY_PAGE)
page.pause()
with pytest.raises(Error, match="Timeout 30000ms exceeded."):
page.get_by_text("foo").click()


def test_page_pause_should_reset_custom_timeouts(
page: Page, headless: bool, server: Server
) -> None:
if not headless:
pytest.skip()

page.set_default_timeout(123)
page.set_default_navigation_timeout(456)
page.goto(server.EMPTY_PAGE)
page.pause()
with pytest.raises(Error, match="Timeout 123ms exceeded."):
page.get_by_text("foo").click()

server.set_route("/empty.html", lambda route: None)
with pytest.raises(Error, match="Timeout 456ms exceeded."):
page.goto(server.EMPTY_PAGE)

0 comments on commit 432dbeb

Please sign in to comment.