Skip to content

Commit b52ec80

Browse files
authored
tests(video): Revert to page fixture that exists per session (not just function) (#1677)
1 parent b76a581 commit b52ec80

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

.github/py-shiny/pytest-browsers/action.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ runs:
3939
else
4040
echo "Using playwright diagnostics!"
4141
echo 'has-playwright-diagnostics=true' >> "$GITHUB_OUTPUT"
42-
echo 'playwright-diagnostic-args=--tracing=retain-on-failure --video=retain-on-failure --screenshot=only-on-failure --full-page-screenshot --output=test-results' >> "$GITHUB_OUTPUT"
42+
echo 'playwright-diagnostic-args=--tracing=retain-on-failure --screenshot=only-on-failure --full-page-screenshot --video off --output=test-results' >> "$GITHUB_OUTPUT"
4343
fi
4444
4545
if [ "${{ inputs.browser }}" != "" ]; then

tests/playwright/conftest.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
from pathlib import PurePath
66

7+
import pytest
8+
from playwright.sync_api import BrowserContext, Page
9+
710
from shiny.pytest import ScopeName as ScopeName
811
from shiny.pytest import create_app_fixture
912

@@ -19,6 +22,39 @@
1922
here_root = here.parent.parent
2023

2124

25+
# Make a single page fixture that can be used by all tests
26+
@pytest.fixture(scope="session")
27+
# By using a single page, the browser is only launched once and all tests run in the same tab / page.
28+
def session_page(browser: BrowserContext) -> Page:
29+
"""
30+
Create a new page within the given browser context.
31+
Parameters:
32+
browser (BrowserContext): The browser context in which to create the new page.
33+
Returns:
34+
Page: The newly created page.
35+
"""
36+
return browser.new_page()
37+
38+
39+
@pytest.fixture(scope="function")
40+
# By going to `about:blank`, we _reset_ the page to a known state before each test.
41+
# It is not perfect, but it is faster than making a new page for each test.
42+
# This must be done before each test
43+
def page(session_page: Page) -> Page:
44+
"""
45+
Reset the given page to a known state before each test.
46+
The page is built on the session_page, which is maintained over the full session.
47+
The page will visit "about:blank" to reset between apps.
48+
The default viewport size is set to 1920 x 1080 (1080p) for each test function.
49+
Parameters:
50+
session_page (Page): The page to reset.
51+
"""
52+
session_page.goto("about:blank")
53+
# Reset screen size to 1080p
54+
session_page.set_viewport_size({"width": 1920, "height": 1080})
55+
return session_page
56+
57+
2258
def create_example_fixture(
2359
example_name: str,
2460
example_file: str = "app.py",

tests/playwright/playwright-pytest.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ asyncio_mode=strict
1313
# # --headed: Headed browser testing
1414
# # -r P: Show extra test summary info: (f)ailed, (E)rror, (s)kipped, (x)failed, (X)passed, (p)assed, (P)assed with output, (a)ll except passed (p/P), or (A)ll. (w)arnings...
1515
# --maxfail=1: Stop after 1 failure has occurred
16-
addopts = --strict-markers --durations=6 --durations-min=5.0 --browser chromium --numprocesses auto -vvv --maxfail=1 --headed --tracing=on --video=on --slowmo=250
16+
addopts = --strict-markers --durations=6 --durations-min=5.0 --browser chromium --numprocesses auto -vvv --maxfail=1 --headed --tracing=on --slowmo=250

0 commit comments

Comments
 (0)