File tree Expand file tree Collapse file tree 3 files changed +38
-1
lines changed Expand file tree Collapse file tree 3 files changed +38
-1
lines changed Original file line number Diff line number Diff line change @@ -55,6 +55,10 @@ async def path(self) -> pathlib.Path:
55
55
return artifact .absolute_path
56
56
57
57
async def save_as (self , path : Union [str , pathlib .Path ]) -> None :
58
+ if self ._page ._connection ._is_sync and not self ._page ._is_closed :
59
+ raise Error (
60
+ "Page is not yet closed. Close the page prior to calling save_as"
61
+ )
58
62
artifact = await self ._artifact_future
59
63
if not artifact :
60
64
raise Error ("Page did not produce any video frames" )
Original file line number Diff line number Diff line change @@ -49,3 +49,16 @@ async def test_short_video_should_throw_persistent_context(
49
49
50
50
path = await page .video .path ()
51
51
assert str (tmpdir ) in str (path )
52
+
53
+
54
+ async def test_should_not_error_if_page_not_closed_before_save_as (
55
+ browser , tmpdir , server
56
+ ):
57
+ page = await browser .new_page (record_video_dir = tmpdir )
58
+ await page .goto (server .PREFIX + "/grid.html" )
59
+ out_path = tmpdir / "some-video.webm"
60
+ saved = page .video .save_as (out_path )
61
+ await page .close ()
62
+ await saved
63
+ await page .context .close ()
64
+ assert os .path .exists (out_path )
Original file line number Diff line number Diff line change 16
16
from pathlib import Path
17
17
from typing import Dict
18
18
19
- from playwright .sync_api import Browser , BrowserType
19
+ import pytest
20
+
21
+ from playwright .sync_api import Browser , BrowserType , Error
20
22
from tests .server import Server
21
23
22
24
@@ -91,3 +93,21 @@ def test_record_video_can_get_video_path_immediately(
91
93
page .wait_for_timeout (1000 )
92
94
context .close ()
93
95
assert os .path .exists (path )
96
+
97
+
98
+ def test_should_error_if_page_not_closed_before_save_as (
99
+ browser : Browser , tmpdir : Path , server : Server
100
+ ) -> None :
101
+ page = browser .new_page (record_video_dir = tmpdir )
102
+ page .goto (server .PREFIX + "/grid.html" )
103
+ out_path = tmpdir / "some-video.webm"
104
+ with pytest .raises (Error ) as err :
105
+ video = page .video
106
+ assert video
107
+ video .save_as (out_path )
108
+ assert "Page is not yet closed. Close the page prior to calling save_as" in str (err )
109
+ assert not os .path .exists (out_path )
110
+ page .context .close ()
111
+
112
+ video .save_as (out_path )
113
+ assert os .path .exists (out_path )
You can’t perform that action at this time.
0 commit comments