Skip to content

Add local/Sauce Labs native Playwright session support to examples/playwright - #197

Merged
diemol merged 7 commits into
mainfrom
playwright-sauce-native-local-sessions
Jul 27, 2026
Merged

Add local/Sauce Labs native Playwright session support to examples/playwright#197
diemol merged 7 commits into
mainfrom
playwright-sauce-native-local-sessions

Conversation

@diemol

@diemol diemol commented Jul 27, 2026

Copy link
Copy Markdown
Member

Summary

  • Ports demo-csharp PR #115's design into examples/playwright: tests run against a locally launched browser (default) or Sauce Labs' native Playwright WebSocket endpoint by setting TARGET=sauce, with GROUPING=module|test controlling session reuse and failure-recycling (a passed test's session is kept for reuse, a failed one is closed immediately).
  • Only the browser fixture is overridden - pytest-playwright's native context/page, --browser/--headed/--slowmo/--tracing/--video/--screenshot flags, and markers (browser_context_args, skip_browser/only_browser) all keep working unmodified for both targets.
  • examples/playwright/Pipfile's playwright-tests script runs with --dist=loadfile, required for GROUPING=module reuse to work correctly under pytest-xdist (its default scheduling can otherwise split one file's tests across worker processes).
  • Added examples/playwright/README.md documenting TARGET, GROUPING, session lifecycle, and usage (mirrors the demo-csharp/demo-js Playwright READMEs).
  • Added .github/workflows/playwright.yml, scoped to examples/playwright/**, running TARGET=sauce against real Sauce Labs with the org's CI secrets. No local browser install step needed - TARGET=sauce only ever calls browser_type.connect(), never .launch().
  • Rebased on top of Split root Pipfile per test suite for true CI path-filter isolation #199 (per-suite Pipfile split) - examples/playwright now has its own Pipfile/Pipfile.lock instead of a shared root one.

Test plan

  • TARGET=local verified: all 3 browser engines (chromium/firefox/webkit), GROUPING=module and GROUPING=test, and the failure-recycling lifecycle (failed test evicts+closes its session, passed test keeps it for reuse) all pass locally.
  • Native pytest-playwright flags verified end-to-end: --browser=firefox, multi-engine runs (--browser=chromium --browser=firefox), and --tracing=on --screenshot=on (produced real trace.zip/screenshot artifacts).
  • pytest -n8 --dist=loadfile examples/playwright/ verified to keep each file's tests on the same xdist worker (required for GROUPING=module reuse).
  • TARGET=sauce verified end-to-end in CI: the new playwright.yml workflow ran on this PR using the org's actual SAUCE_USERNAME/SAUCE_ACCESS_KEY secrets and passed (3 passed in 22.92s - https://github.com/saucelabs-training/demo-python/actions/runs/30308827632). The earlier 500 Infrastructure Error only reproduced with a personal Sauce account during local development; it wasn't a bug in this code.

🤖 Generated with Claude Code

diemol and others added 7 commits July 27, 2026 22:19
…aywright

Ports demo-csharp PR #115's TARGET=local|sauce design: tests can run against a
locally launched browser or Sauce Labs' native Playwright WebSocket endpoint by
flipping one env var, with GROUPING=module|test controlling session reuse and
failure-recycling. Only the `browser` fixture is overridden, so pytest-playwright's
native --browser/--headed/--tracing/--screenshot flags and markers keep working
unmodified for both targets.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Resolves conflicts in Pipfile/Pipfile.lock: keeps this branch's
playwright-tests --dist=loadfile fix alongside main's playwright==1.61.0
pin and certifi bump. Pipfile.lock regenerated via `pipenv lock`.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Resolves the root Pipfile modify/delete conflict from #199's per-suite
Pipfile split: the root Pipfile is gone, and this branch's only real
delta (playwright-tests' --dist=loadfile flag) is ported into the new
examples/playwright/Pipfile instead. Verified the suite still passes
with GROUPING=module reuse working correctly post-merge.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Runs TARGET=sauce against real Sauce Labs using the org's CI secrets,
scoped to examples/playwright/**. No local browser install step needed -
TARGET=sauce only ever calls browser_type.connect(), never .launch().

This is the first live run of the TARGET=sauce path outside personal
credentials - the earlier 500 error was reproduced only with a personal
Sauce account, so this run will show whether the org's CI secrets behave
differently.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…ng tests

Adds test_cart.py, test_checkout.py, test_navigation.py, and
test_sorting.py, each getting its own Sauce session under
GROUPING=module since they're separate files. Also fixes test_login.py:
the old "invalid" test used a locked-out username with a wrong password,
which never actually exercised the locked-out error message - split
into four scenarios (valid login, locked-out user, invalid credentials,
logout).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
SAUCE_BUILD_NAME was computed from datetime.now() at module import
time. Under pytest-xdist each worker is a separate process that
imports conftest.py independently at its own slightly different
startup moment, so different workers ended up with different
timestamps and split one test run across multiple Sauce builds.

Fixed via pytest-xdist's controller/worker data-sharing hooks:
pytest_configure_node stashes the controller's build name for each
worker before it starts, and pytest_configure overrides the worker's
own value with it. Verified with 6 worker processes all reporting the
identical build name.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
pytest now writes a JUnit XML report (--junitxml), which
dorny/test-reporter publishes as a check run and job summary
(reporter: python-xunit, matching pytest's xunit2-style output).
Runs with if: always() so failures still get reported.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@diemol
diemol merged commit a697e1f into main Jul 27, 2026
1 check passed
@diemol
diemol deleted the playwright-sauce-native-local-sessions branch July 27, 2026 22:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant