Skip to content

Commit 44911ec

Browse files
committed
test: add tests for TopLevelTargetRequired
1 parent b0c9a17 commit 44911ec

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

tests/test_browser/test_browser_tab.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
WaitElementTimeout,
2424
NetworkEventsNotEnabled,
2525
InvalidScriptWithElement,
26+
TopLevelTargetRequired,
2627
)
2728

2829
@pytest_asyncio.fixture
@@ -424,6 +425,14 @@ async def test_take_screenshot_beyond_viewport(self, tab):
424425
assert command['params']['captureBeyondViewport'] is True
425426
assert result == screenshot_data
426427

428+
@pytest.mark.asyncio
429+
async def test_take_screenshot_in_iframe_raises_top_level_required(self, tab):
430+
"""Tab.take_screenshot must be called on top-level targets; iframe Tab raises."""
431+
# Simulate CDP returning no image data (missing 'data' key) for non top-level target
432+
with patch.object(tab, '_execute_command', AsyncMock(return_value={'result': {}})):
433+
with pytest.raises(TopLevelTargetRequired):
434+
await tab.take_screenshot(path=None, as_base64=True)
435+
427436
@pytest.mark.asyncio
428437
async def test_print_to_pdf_to_file(self, tab, tmp_path):
429438
"""Test printing to PDF and saving to file."""

0 commit comments

Comments
 (0)