> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.doc-detective.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.doc-detective.com/_mcp/server.

# Test pages behind a sign-in

> Find a sign-in that a test can run unattended, with or without MFA, then choose how your tests sign in and reuse the session.

Most product docs describe pages that a reader sees only after they sign in, or log in. To test those procedures or take their screenshots, your tests have to sign in too, often past multi-factor authentication (MFA). This page helps you find a sign-in that a test can complete on its own, every time. Then it helps you choose how your tests use it. Once a test is signed in, the `find`, `click`, `type`, and `screenshot` steps you use on other pages work on these pages too. For API calls that need credentials, see [Authenticate API requests](/docs/test-docs/api-authentication).

## What makes a sign-in testable

A test runs with nobody watching it, so the sign-in it uses has to work without a person. A sign-in is testable when it:

* **Runs unattended.** Every step is something a test can do: open a page, type, select, or compute a code.
* **Gives the same result every time.** The same steps sign in the same way on every run. No prompt appears on some runs and not others.
* **Works the same locally and in CI.** It doesn't depend on a particular laptop, browser profile, or network.
* **Uses a secret you can store and rotate.** A password, token, or authenticator key fits in an environment variable or a CI secret, and someone can replace it.
* **Uses a low-privilege account outside production.** The account can see the pages your docs show and can't do much harm if its secret leaks.

## Ask your engineering and QA teams

Your product's end-to-end tests already have to sign in, so your engineering or QA team has usually solved this problem. Reusing their method is often the fastest path, and it means that your docs tests break only when theirs do. Ask them:

* How do your end-to-end tests sign in, and can docs tests use the same method?
* Is there a staging or test tenant with seeded test users?
* Is there a test account with MFA off? Or one with an authenticator app enrolled, whose setup key you can store as a secret?
* Is there a test-only endpoint or API that creates a session or a token?
* Does the non-production environment accept a fixed one-time code?
* Does a Playwright suite already save a `storageState` file? [`loadState`](/docs/actions/loadstate) reads that format.
* Who approves the test account, and who rotates its secret?

## Match what your team has to a pattern

Use the answers to pick how your tests sign in:

| What your team has                                                                     | What to use in Doc Detective                                                                                                              |
| -------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
| A test account that signs in with a password                                           | Sign in once in a spec that runs before the others, then [reuse the session](/docs/test-docs/reuse-a-session)                             |
| A test account with an authenticator app enrolled                                      | Generate the code with `totp()`. See [Sign in with an authenticator app code](/docs/test-docs/authenticator-app-sign-in)                  |
| A fixed one-time code that works outside production                                    | Type it from an environment variable like a password, then [reuse the session](/docs/test-docs/reuse-a-session)                           |
| Single sign-on (SSO) through an identity provider that has a test tenant or test users | Sign in through the provider, then save the session on your app's site. See [Sign in through single sign-on](/docs/test-docs/sso-sign-in) |
| A Playwright suite that saves `storageState`                                           | Load that file with `loadState`. See [Reuse a Playwright session](/docs/test-docs/reuse-a-session#reuse-a-playwright-session)             |
| One session cookie, from a test-only endpoint or a sign-in                             | [Reuse the cookie](/docs/test-docs/reuse-a-cookie) with `saveCookie` and `loadCookie`                                                     |
| An API token or a sign-in request that returns one                                     | Send it in a header. See [Authenticate API requests](/docs/test-docs/api-authentication)                                                  |

## Agree on the account with your security owner

A test account is a real account with real access, so get your security owner's agreement on how your tests use it:

* Use an account made for testing, in a non-production environment, with only the access your docs need.
* Never turn off MFA on a real person's account so that a test can sign in.
* Never ship a sign-in bypass, such as a test-only endpoint or a fixed one-time code, to production.
* Store the account's secrets as CI secrets, and agree on who rotates them. See [Protect sign-in secrets and session files](/docs/test-docs/sign-in-secrets).

## Sign-ins a test can't complete

Doc Detective doesn't support a sign-in factor that needs a person or a second device. A test that waits for a person can't run in CI and doesn't give the same result twice. These factors can't be tested:

* Codes sent by SMS or a phone call.
* Push approval in a mobile app.
* Codes and magic links sent by email, which a person has to open.
* Hardware security keys and passkeys.
* CAPTCHA and other challenges that check for a human.

If your product's sign-in uses one of these, don't build the test around it. Go back to [your engineering and QA teams](#ask-your-engineering-and-qa-teams) and ask how their tests get past it. Most teams have a test account with a different factor, or a test tenant where the factor is off. Some can create a session directly. For CAPTCHA, ask whether the test environment turns it off or uses the CAPTCHA provider's test keys.

## Choose between session reuse and cookie reuse

Once a test can sign in, sign in once and reuse the result in every test. A test that signs in at the start of every procedure is slow. Every extra sign-in is also another chance to hit a rate limit or a CAPTCHA. Doc Detective can reuse a whole session or one cookie:

|                             | Session reuse                                                                               | Cookie reuse                                                                          |
| --------------------------- | ------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------- |
| Actions                     | [`saveState`](/docs/actions/savestate) and [`loadState`](/docs/actions/loadstate)           | [`saveCookie`](/docs/actions/savecookie) and [`loadCookie`](/docs/actions/loadcookie) |
| What it moves               | Every cookie for the open site, plus its `localStorage`                                     | One cookie, by name                                                                   |
| Where it's stored           | A JSON file in Playwright's `storageState` format                                           | A Netscape cookie file, or an environment variable for the rest of the run            |
| Keeps `sameSite`            | Yes                                                                                         | Only through an environment variable                                                  |
| Works with Playwright files | Yes, in both directions                                                                     | No                                                                                    |
| Pick it when                | You don't know how the app stores its session, or it uses several cookies or `localStorage` | You know the one cookie that holds the session, or you don't want a file on disk      |

When you aren't sure, use session reuse. It carries the open site's cookies and `localStorage`. Start with [Sign in once and reuse the session](/docs/test-docs/reuse-a-session), and before you run it in CI, read [Protect sign-in secrets and session files](/docs/test-docs/sign-in-secrets).