You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Optimizes Playwright test execution by implementing storage state to reuse authentication sessions across tests, eliminating redundant login operations.
Key Changes:
Add session-scoped authenticated_state fixture that saves browser auth state
Modify all page fixtures to reuse saved authentication
Add @pytest.mark.no_auth support for tests requiring fresh login
Add .auth/ directory to gitignore
Benefits:
~9% faster test execution (~2.5 min savings on full suite)
Reduced server load from fewer login requests
More reliable tests with less network dependency
Backward compatible - no breaking changes
Thanks for this, @madrian13! Using Playwright's storage state for auth reuse is the right approach here.
A few observations:
Overly broad .gitignore - Adding *.json will ignore ALL JSON files in tests/playwright/. This could hide legitimate test fixtures or config. Consider narrowing to just:
.auth/
That already covers admin_state.json.
context fixture change - The original used new_context from pytest-playwright, which integrates with artifact collection (screenshots on failure, video recording). The new implementation creates contexts directly via browser.new_context(), which may bypass those hooks. Worth verifying screenshot-on-failure still works.
Repeated boilerplate - Every page fixture now has the same if no_auth: login else: goto+wait pattern, duplicated ~12 times. Consider extracting into a helper like _ensure_page_ready(page, base_url, request).
Documentation - storage-state-optimization.md is clear with before/after metrics. The 9% improvement should scale as more tests are added.
Edge case - The 1-hour TTL uses time.time() - stat().st_mtime. If the system clock shifts (NTP sync in CI), this could cause unexpected behavior. Minor, but worth noting.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Optimizes Playwright test execution by implementing storage state to reuse authentication sessions across tests, eliminating redundant login operations.
Key Changes:
Add session-scoped authenticated_state fixture that saves browser auth state
Modify all page fixtures to reuse saved authentication
Add @pytest.mark.no_auth support for tests requiring fresh login
Add .auth/ directory to gitignore
Benefits:
~9% faster test execution (~2.5 min savings on full suite)
Reduced server load from fewer login requests
More reliable tests with less network dependency
Backward compatible - no breaking changes