diff --git a/playwright/page.py b/playwright/page.py index 3ceb1c0da..6cef049a1 100644 --- a/playwright/page.py +++ b/playwright/page.py @@ -812,7 +812,8 @@ async def pdf( def video( self, ) -> Optional[Video]: - if not self._browser_context._options.get("videosPath"): + context_options = self._browser_context._options + if "recordVideo" not in context_options: return None if not self._video: self._video = Video(self) diff --git a/playwright/video.py b/playwright/video.py index ec1700bfa..6af5b0fa3 100644 --- a/playwright/video.py +++ b/playwright/video.py @@ -31,7 +31,7 @@ async def path(self) -> str: def _set_relative_path(self, relative_path: str) -> None: self._path_future.set_result( os.path.join( - cast(str, self._page._browser_context._options.get("videosPath")), + cast(str, self._page._browser_context._options["recordVideo"]["dir"]), relative_path, ) ) diff --git a/tests/sync/conftest.py b/tests/sync/conftest.py index 84c719a5f..114755984 100644 --- a/tests/sync/conftest.py +++ b/tests/sync/conftest.py @@ -25,7 +25,7 @@ def playwright(): @pytest.fixture(scope="session") -def browser(playwright, browser_name, launch_arguments): +def browser_type(playwright, browser_name): browser_type = None if browser_name == "chromium": browser_type = playwright.chromium @@ -33,6 +33,11 @@ def browser(playwright, browser_name, launch_arguments): browser_type = playwright.firefox elif browser_name == "webkit": browser_type = playwright.webkit + yield browser_type + + +@pytest.fixture(scope="session") +def browser(browser_type, launch_arguments): browser = browser_type.launch(**launch_arguments) yield browser browser.close() diff --git a/tests/sync/test_video.py b/tests/sync/test_video.py index acb7cce05..410717520 100644 --- a/tests/sync/test_video.py +++ b/tests/sync/test_video.py @@ -30,3 +30,24 @@ def test_video_should_exist(browser, tmpdir, server): assert str(tmpdir) in path page.context.close() assert os.path.exists(path) + + +def test_record_video_to_path(browser, tmpdir, server): + page = browser.newPage(recordVideo={"dir": str(tmpdir)}) + page.goto(server.PREFIX + "/grid.html") + path = page.video.path() + assert str(tmpdir) in path + page.context.close() + assert os.path.exists(path) + + +def test_record_video_to_path_persistent(browser_type, tmpdir, server): + context = browser_type.launchPersistentContext( + tmpdir, recordVideo={"dir": str(tmpdir)} + ) + page = context.pages[0] + page.goto(server.PREFIX + "/grid.html") + path = page.video.path() + assert str(tmpdir) in path + context.close() + assert os.path.exists(path)