Most tests need to be logged in before they do anything useful. There are three ways to handle that. Reach for them in this order: stay with live login while it is fast enough, then add anDocumentation Index
Fetch the complete documentation index at: https://momentic.ai/docs/llms.txt
Use this file to discover all available pages before exploring further.
authSave / authLoad state file, and
only move to a cached auth module when you need it.
1. Live login (recommended default)
Wrap your login steps in a module and call it from thebefore section of each
test. It logs in for real on every run, so the session is never stale and there
is nothing to invalidate.
log-in.module.yaml
checkout.test.yaml
2. Save and restore a state file (authSave / authLoad)
The authSave and authLoad steps (the editor’s Save auth state / Load
auth state) write and read the browser’s cookies, localStorage, and
IndexedDB to a JSON file you manage yourself. This is the closest analog to
Playwright’s storageState, so it is the
natural next step if you are migrating from Playwright: log in once, save the
state, and load it instead of logging in again.
checkout.test.yaml
3. Cached auth module
When you want the speed-up without managing a file, let Momentic cache the session for you. Mark the login module as an auth module and enable caching: the first run logs in for real, and later runs (and parallel tests sharing the same cache key) restore the saved browser state server-side and skip the login steps entirely.log-in.module.yaml
before section exactly like the live-login module. This is
the fastest option at scale (parallel tests reuse one session) and Momentic
handles capture, storage, expiry, and per-key isolation for you. See
Cache authenticated sessions for the full
walkthrough and Modules for
every cache field.
Options and trade-offs
| Strategy | When it runs | Trade-offs |
|---|---|---|
| Live login (recommended) | Every run (whole-test runs only) | Most reliable, never stale. Logs in every run, so slower and can hit rate limits. |
authSave / authLoad state file | Whenever you place the steps | Portable JSON, like Playwright’s storageState. You own refreshing it when it stales. |
Cached auth module (autoAuth + caching) | Once per cache key, within the TTL | Fastest at scale; parallel tests reuse one session. Needs a cache key and expiry. |
In CI
Live login works in CI with no extra setup - just provide credentials as secrets (env.USERNAME, env.PASSWORD,
OTP secrets) rather than committed values. If logging in every run is too slow,
add an authSave / authLoad state file or a cached auth module; the module’s
session is stored server-side alongside the
step cache, so once one run logs in, other runs and
shards can reuse it within the TTL.