Skip to content

Videos ​

Introduction ​

With Playwright you can record videos for your tests.

Record video ​

Videos are saved upon browser context closure at the end of a test. If you create a browser context manually, make sure to await browser_context.close().

python
context = await browser.new_context(record_video_dir="videos/")
# Make sure to await close, so that videos are saved.
await context.close()
python
context = browser.new_context(record_video_dir="videos/")
# Make sure to close, so that videos are saved.
context.close()

You can also specify video size. The video size defaults to the viewport size scaled down to fit 800x800. The video of the viewport is placed in the top-left corner of the output video, scaled down to fit if necessary. You may need to set the viewport size to match your desired video size.

python
context = await browser.new_context(
    record_video_dir="videos/",
    record_video_size={"width": 640, "height": 480}
)
python
context = browser.new_context(
    record_video_dir="videos/",
    record_video_size={"width": 640, "height": 480}
)

Saved video files will appear in the specified folder. They all have generated unique names. For the multi-page scenarios, you can access the video file associated with the page via the page.video().

python
path = await page.video.path()
python
path = page.video.path()

INFO

Note that the video is only available after the page or browser context is closed.

Released under the Apache 2.0 License.