Skip to content

Commit

Permalink
fix(video): fix the new recordVideo API (#336)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelfeldman committed Dec 2, 2020
1 parent 2e5c300 commit d400411
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
3 changes: 2 additions & 1 deletion playwright/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion playwright/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
)
7 changes: 6 additions & 1 deletion tests/sync/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,19 @@ 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
elif browser_name == "firefox":
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()
Expand Down
21 changes: 21 additions & 0 deletions tests/sync/test_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit d400411

Please sign in to comment.