From d01d18085e756b5f5ff3f5aef9131f5a04808e6f Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Tue, 16 Apr 2024 22:25:11 +0200 Subject: [PATCH] fix: page.video should be None if not recording --- playwright/_impl/_page.py | 5 +++++ tests/async/test_video.py | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/playwright/_impl/_page.py b/playwright/_impl/_page.py index db6cf13b87..1b8a67cb2f 100644 --- a/playwright/_impl/_page.py +++ b/playwright/_impl/_page.py @@ -1068,6 +1068,11 @@ async def pdf( def video( self, ) -> Optional[Video]: + # Note: we are creating Video object lazily, because we do not know + # BrowserContextOptions when constructing the page - it is assigned + # too late during launchPersistentContext. + if not self._browser_context._options.get("recordVideoDir"): + return None if not self._video: self._video = Video(self) return self._video diff --git a/tests/async/test_video.py b/tests/async/test_video.py index 8575aabad6..b0ab4c5296 100644 --- a/tests/async/test_video.py +++ b/tests/async/test_video.py @@ -76,3 +76,11 @@ async def test_should_not_error_if_page_not_closed_before_save_as( await saved await page.context.close() assert os.path.exists(out_path) + + +async def test_should_be_None_if_not_recording( + browser: Browser, tmpdir: Path, server: Server +) -> None: + page = await browser.new_page() + assert page.video is None + await page.close()