Skip to content

Commit 4674d1b

Browse files
authored
fix(video): fix the new recordVideo API (microsoft#336)
1 parent 548b552 commit 4674d1b

File tree

4 files changed

+30
-3
lines changed

4 files changed

+30
-3
lines changed

playwright/page.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,8 @@ async def pdf(
812812
def video(
813813
self,
814814
) -> Optional[Video]:
815-
if not self._browser_context._options.get("videosPath"):
815+
context_options = self._browser_context._options
816+
if "recordVideo" not in context_options:
816817
return None
817818
if not self._video:
818819
self._video = Video(self)

playwright/video.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ async def path(self) -> str:
3131
def _set_relative_path(self, relative_path: str) -> None:
3232
self._path_future.set_result(
3333
os.path.join(
34-
cast(str, self._page._browser_context._options.get("videosPath")),
34+
cast(str, self._page._browser_context._options["recordVideo"]["dir"]),
3535
relative_path,
3636
)
3737
)

tests/sync/conftest.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,19 @@ def playwright():
2525

2626

2727
@pytest.fixture(scope="session")
28-
def browser(playwright, browser_name, launch_arguments):
28+
def browser_type(playwright, browser_name):
2929
browser_type = None
3030
if browser_name == "chromium":
3131
browser_type = playwright.chromium
3232
elif browser_name == "firefox":
3333
browser_type = playwright.firefox
3434
elif browser_name == "webkit":
3535
browser_type = playwright.webkit
36+
yield browser_type
37+
38+
39+
@pytest.fixture(scope="session")
40+
def browser(browser_type, launch_arguments):
3641
browser = browser_type.launch(**launch_arguments)
3742
yield browser
3843
browser.close()

tests/sync/test_video.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,24 @@ def test_video_should_exist(browser, tmpdir, server):
3030
assert str(tmpdir) in path
3131
page.context.close()
3232
assert os.path.exists(path)
33+
34+
35+
def test_record_video_to_path(browser, tmpdir, server):
36+
page = browser.newPage(recordVideo={"dir": str(tmpdir)})
37+
page.goto(server.PREFIX + "/grid.html")
38+
path = page.video.path()
39+
assert str(tmpdir) in path
40+
page.context.close()
41+
assert os.path.exists(path)
42+
43+
44+
def test_record_video_to_path_persistent(browser_type, tmpdir, server):
45+
context = browser_type.launchPersistentContext(
46+
tmpdir, recordVideo={"dir": str(tmpdir)}
47+
)
48+
page = context.pages[0]
49+
page.goto(server.PREFIX + "/grid.html")
50+
path = page.video.path()
51+
assert str(tmpdir) in path
52+
context.close()
53+
assert os.path.exists(path)

0 commit comments

Comments
 (0)