Skip to content

Error when saving video recording files using recordVideo context param #334

@strozzapreti

Description

@strozzapreti

The following error is being logged when attempting to save videos from my pytest-based Playwright tests in both headless and headful mode:

Error dispatching the event Traceback (most recent call last):
  File "venv/lib/python3.8/site-packages/playwright/connection.py", line 204, in _dispatch
    g.switch(self._replace_guids_with_channels(params))
  File "venv/lib/python3.8/site-packages/playwright/page.py", line 214, in <lambda>
    lambda params: cast(Video, self.video)._set_relative_path(
AttributeError: 'NoneType' object has no attribute '_set_relative_path'

The videos are still saved successfully, however, so as far as I can tell the error is only cosmetic. This only happens when using the recordVideo parameter of browser.newContext(). If I set videosPath instead, there is no error.

According to the docstrings for videosPath and videoSize, recordVideo takes precedence and should be used instead, e.g.:

NOTE Use recordVideo instead, it takes precedence over videoSize. Specifies dimensions of the automatically recorded video. Can only be used if videosPath is set. If not specified the size will be equal to viewport. If viewport is not configured explicitly the video size defaults to 1280x720. Actual picture of the page will be scaled down if necessary to fit specified size.

For now, I can just use videosPath to avoid errors and replace it with recordVideo if this issue is resolved. Here's the fixture where I created the new context:

@fixture(scope='function')
def context(browser: Browser) -> Generator[BrowserContext, None, None]:
    context = browser.newContext(ignoreHTTPSErrors=True, acceptDownloads=True, recordVideo={'dir': 'playwrightvids'})
    context.setDefaultTimeout(10000)
    yield context
    context.close()

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions