microsoft / playwright-pytest

Pytest plugin to write end-to-end browser tests with Playwright.
https://playwright.dev/python/docs/test-runners
Apache License 2.0
427 stars 70 forks source link

pytest-playwirght uses --video="on" to record video,the recorded video only records the newly opened tab page #220

Closed crazy-yuzhao closed 4 months ago

crazy-yuzhao commented 5 months ago

pytest-playwirght uses --video="on" to record video. The use case steps will open multiple browser tabs. The recorded video only records the newly opened tab page, and does not record the content of the previous tab page. Whether it supports recording videos on multiple browser tabs, and you can control which tab to record videos for.

mxschmitt commented 5 months ago

Are you creating multiple contexts? Then it sounds like https://github.com/microsoft/playwright-pytest/issues/111.

This plugin records a video for every page which gets created during a test-run. Could you maybe provide us a code snippet of whats not working?

crazy-yuzhao commented 5 months ago
[pytest]

addopts = -vs
                  --screenshot="only-on-failure"
                  --video="on"

from playwright.sync_api import Page
def test_01(page: Page):
    page.goto('https://playwright.dev/')
    with page.expect_popup() as page2_info:
        page.locator('[href="https://github.com/microsoft/playwright"]').first.click()
    page2 = page2_info.value
    print(page2.title())

page uses @pytest.fixture(scope="session")

@pytest.fixture(scope="session")
def page(context: BrowserContext,
         pytestconfig: Any,
         request: pytest.FixtureRequest,
         ) -> Generator[Page, None, None]:
.........
mxschmitt commented 5 months ago

what is the exact implementation of your page fixture? We need more information to act on it, ideally something we can run locally with expected and actual outcome.

crazy-yuzhao commented 5 months ago
[pytest]

addopts = -vs
                  --screenshot="only-on-failure"
                  --video="on"

from playwright.sync_api import Page
def test_01(page: Page):
    page.goto('https://playwright.dev/')
    with page.expect_popup() as page2_info:
        page.locator('[href="https://github.com/microsoft/playwright"]').first.click()
    page2 = page2_info.value
    print(page2.title())

page uses @pytest.fixture(scope="session")

@pytest.fixture(scope="session")
def page(context: BrowserContext,
         pytestconfig: Any,
         request: pytest.FixtureRequest,
         ) -> Generator[Page, None, None]:
.........

I changed the scope of the fixture on the page to session, and this case(test_01) can be run locally.

mxschmitt commented 4 months ago

Closing as part of the triage process since it seemed stale. Please create a new issue with a detailed reproducible or feature request if you still face issues.