Skip to content

Implement storage state auth optimization#2812

Open
madrian13 wants to merge 3 commits intomainfrom
implement-storage-state-auth-optimization
Open

Implement storage state auth optimization#2812
madrian13 wants to merge 3 commits intomainfrom
implement-storage-state-auth-optimization

Conversation

@madrian13
Copy link
Collaborator

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

@crivetimihai
Copy link
Member

Thanks for this, @madrian13! Using Playwright's storage state for auth reuse is the right approach here.

A few observations:

  1. 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.

  2. 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.

  3. 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).

  4. Documentation - storage-state-optimization.md is clear with before/after metrics. The 9% improvement should scale as more tests are added.

  5. 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.

@crivetimihai crivetimihai added this to the Release 1.0.0-GA milestone Feb 11, 2026
@crivetimihai crivetimihai self-assigned this Feb 15, 2026
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.

2 participants