Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion playwright/_impl/_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from typing import Callable, Dict, Optional, Union

from playwright._impl._driver import compute_driver_executable, get_driver_env
from playwright._impl._errors import Error
from playwright._impl._helper import ParsedMessagePayload


Expand Down Expand Up @@ -75,7 +76,11 @@ def send(self, message: Dict) -> None:
pass

def serialize_message(self, message: Dict) -> bytes:
msg = json.dumps(message)
try:
# NaN and Infinity are not valid JSON and would crash the driver.
msg = json.dumps(message, allow_nan=False)
except ValueError as e:
raise Error(str(e)) from None
if "DEBUGP" in os.environ: # pragma: no cover
print("\x1b[32mSEND>\x1b[0m", json.dumps(message, indent=2))
return msg.encode()
Expand Down
10 changes: 10 additions & 0 deletions tests/async/test_assertions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1218,3 +1218,13 @@ async def test_assertions_should_include_aria_snapshot_in_separate_section(
actual_line = message.split("\n")[1]
assert 'heading "Page Heading"' not in actual_line
assert message.index('heading "Page Heading"') > message.index("Aria snapshot:")


@pytest.mark.parametrize("timeout", [float("inf"), float("-inf"), float("nan")])
async def test_assertions_should_reject_non_finite_timeout(
page: Page, timeout: float
) -> None:
with pytest.raises(Error, match="Out of range float values are not JSON"):
await expect(page.locator("div")).to_be_visible(timeout=timeout)
# The driver connection must survive the rejected call.
assert await page.evaluate("1 + 1") == 2
10 changes: 10 additions & 0 deletions tests/sync/test_assertions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1123,3 +1123,13 @@ def test_assertions_should_include_aria_snapshot_in_separate_section(
actual_line = message.split("\n")[1]
assert 'heading "Page Heading"' not in actual_line
assert message.index('heading "Page Heading"') > message.index("Aria snapshot:")


@pytest.mark.parametrize("timeout", [float("inf"), float("-inf"), float("nan")])
def test_assertions_should_reject_non_finite_timeout(
page: Page, timeout: float
) -> None:
with pytest.raises(Error, match="Out of range float values are not JSON"):
expect(page.locator("div")).to_be_visible(timeout=timeout)
# The driver connection must survive the rejected call.
assert page.evaluate("1 + 1") == 2
Loading