Recommended Test Strategy
Use a layered approach:- Run one dedicated auth smoke test that proves Google Auth + 2FA still works.
- Save
storageStateafter login and reuse it for the rest of your suite. - Keep shared auth accounts stable and isolated from personal accounts.
Use Stably Auth with Google Helper (Recommended)
If you use the Stably SDK, prefercontext.authWithGoogle() over driving Google’s UI directly. It is purpose-built for automated runs and supports OTP via otpSecret.
auth/google-auth.spec.ts
Fallback: UI Auth Setup Project
Create a setup project that logs in once and stores session state.auth/setup-google-auth.ts
Handling 2FA Reliably
Pick one method and standardize it:Option 1: Test-only bypass (most stable)
Option 1: Test-only bypass (most stable)
If your IdP supports conditional policies, allow a test account to bypass the second factor in non-production environments.
Keep one real 2FA smoke test in CI and run all other tests with bypass.
Option 2: TOTP code generation
Option 2: TOTP code generation
Store the test account’s TOTP seed in a secret manager and generate the current code in setup.
This is stable and does not require inbox/SMS polling.
Option 3: Email/SMS OTP retrieval
Option 3: Email/SMS OTP retrieval
Poll your test inbox or SMS provider API for the OTP, then submit it in Playwright.
This matches production behavior but is slower and typically more flaky.
Example: TOTP in Setup
auth/setup-google-auth-with-totp.ts
CI/CD Auth Checklist
- Use dedicated Google workspace test users.
- Store auth variables in Stably Environments and run with
npx stably test --env=Staging. - Store credentials and TOTP seed as secrets.
- Rotate shared test credentials on a schedule.
- Fail fast if auth setup fails instead of retrying all tests.
- Keep auth smoke tests small and isolated.
Stably Features to Use for Auth Stability
- Run auth smoke checks on Stably Cloud with isolated auth projects.
- Add Scheduled Test Runs to continuously validate sign-in health.
- Configure Alerts & Notifications for immediate auth failure signals in Slack/email.
- Use Environments sensitive variables to protect Google credentials and OTP secrets.