The pattern
Save the session once
Write a test whose only job is to hold a browser open while you log in manually, then save the state:tests/setup/capture-sso.test.yaml
sso-state.json.
The file holds the cookies, localStorage, and IndexedDB state the session
needs.
Load it in every test
tests/reports.test.yaml
authLoad injects the state before the first navigation, so the app sees an
already-authenticated browser.
Keeping the session fresh
State files expire with the IdP session. Two options keep the session valid:-
Refresh continuously. Add
authSaveto a test’safter:section so each run rolls the state forward:Continuous refresh works when the app slides session expiry on activity, but only where the file persists. In CI the save lands in the runner’s checkout and disappears when the job ends; to keep refreshed state across jobs, write it back yourself (upload it as an artifact a later job restores, or push it to your secret store from a scheduled workflow). - Re-capture on failure. When a run fails on the login wall, re-run the capture test. Put the capture step behind a weekly scheduled job or a manual workflow so staleness is a one-command fix.
autoAuth: true) instead: Momentic stores the session server-side and shares
it across parallel tests within a TTL. See
cache authenticated sessions.
Automating the IdP
Sometimes there is no state shortcut: for example, testing the login flow itself. If you must drive the provider’s UI:- Use a dedicated test account with 2FA that accepts TOTP, not SMS or push.
Generate codes in a
javascriptstep withOTPAuth; see authenticator-app codes. - Expect bot detection on Google and Microsoft. Okta and Keycloak are usually permissive on dedicated test accounts.
- Keep the login in one module so when it breaks, one file breaks.
Related
- Authentication strategies
- Cache authenticated sessions
- TOTP / 2FA codes
authLoadandauthSavereference