Just recipes for running Playwright tests

Plus the pytest header now reports selected Playwright browsers
This commit is contained in:
Simon Willison 2026-06-16 13:35:15 -07:00
commit 77fa49cf17
3 changed files with 55 additions and 11 deletions

View file

@ -11,6 +11,22 @@ export DATASETTE_SECRET := "not_a_secret"
@test *options: init
uv run pytest -n auto {{options}}
# Install Playwright browser support, Chromium by default
@playwright-install browser="chromium":
uv run --group playwright playwright install {{browser}}
# Install all Playwright browsers used by the test suite
@playwright-install-all:
uv run --group playwright playwright install chromium firefox webkit
# Run Playwright tests, Chromium by default
@playwright browser="chromium" *options:
uv run --group playwright pytest tests/test_playwright.py --playwright --browser {{browser}} {{options}}
# Run Playwright tests against all supported browsers
@playwright-all *options:
uv run --group playwright pytest tests/test_playwright.py --playwright --browser chromium --browser firefox --browser webkit {{options}}
@codespell:
uv run codespell README.md --ignore-words docs/codespell-ignore-words.txt
uv run codespell docs/*.rst --ignore-words docs/codespell-ignore-words.txt

View file

@ -71,24 +71,42 @@ These tests are skipped by default, so you can run the main test suite with
.. _Playwright: https://playwright.dev/python/
The Playwright tests use a separate dependency group. To run them, first install
the browser engine you want to test against, for example Chromium::
The Playwright tests use a separate dependency group. The easiest way to run
them is using ``just``. First install the browser engine you want to test
against. Chromium is used by default::
just playwright-install
Then run the Playwright test module::
just playwright
You can also run the same tests against Firefox or WebKit by installing that
browser engine and passing it to ``just playwright``::
just playwright-install firefox
just playwright firefox
just playwright-install webkit
just playwright webkit
To install every supported browser engine and run the tests against all of
them, use::
just playwright-install-all
just playwright-all
You can pass extra ``pytest`` options after the browser name::
just playwright chromium -k permissions
just playwright-all -x
If you are not using ``just``, the equivalent Chromium commands are::
uv run --group playwright playwright install chromium
Then run the Playwright test module with the explicit ``--playwright`` flag::
uv run --group playwright pytest tests/test_playwright.py --playwright --browser chromium
You can also run the same tests against Firefox or WebKit by installing that
browser engine and passing it to ``--browser``::
uv run --group playwright playwright install firefox
uv run --group playwright pytest tests/test_playwright.py --playwright --browser firefox
uv run --group playwright playwright install webkit
uv run --group playwright pytest tests/test_playwright.py --playwright --browser webkit
.. _contributing_using_fixtures:
Using fixtures

View file

@ -93,7 +93,17 @@ def pytest_report_header(config):
conn = sqlite3.connect(":memory:")
version = conn.execute("select sqlite_version()").fetchone()[0]
conn.close()
return "SQLite: {}".format(version)
headers = ["SQLite: {}".format(version)]
if config.getoption("--playwright"):
try:
browsers = config.getoption("--browser")
except ValueError:
browsers = None
if isinstance(browsers, str):
browsers = [browsers]
if browsers:
headers.append("Playwright browsers: {}".format(", ".join(browsers)))
return headers
def pytest_addoption(parser):