> ## Documentation Index
> Fetch the complete documentation index at: https://docs.testsprite.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Authentication (UI)

> How UI tests sign in to your app: test account credentials, OTP (one-time password) login with a TestSprite-managed account, or SSO (single sign-on) such as Google.

![The test account and login method section on the UI project configuration step](https://mintcdn.com/testspriteinc/CImpC64Ju-sB5348/images/ui-testing-authentication-overview.png?fit=max\&auto=format\&n=CImpC64Ju-sB5348\&q=85\&s=911e1c0a329bb5b581b0d75f56212a77)

## Why UI Tests Need to Log In

Without a way to sign in, TestSprite can only explore and test what a signed-out visitor sees. You configure login once, and TestSprite signs in the same way for [feature exploration](https://docs.testsprite.com/web-portal/core/ui/feature-exploration.md), test generation, and every run.

> [!NOTE]
>
> This page covers browser login for UI projects only. For API projects, see [Auto-Auth](https://docs.testsprite.com/web-portal/core/api/auto-auth.md).

## Getting Started: Sign-in required

The sign-in section has two tabs. Choose **No sign-in** if the part of your app you want covered works without an account. Choose **Sign-in required** and three login methods appear as cards; pick the one that matches how users get into your app.

![The Sign-in row with Sign-in required picked, and the Test account credentials, OTP login and SSO cards below it](https://mintcdn.com/testspriteinc/CImpC64Ju-sB5348/images/ui-testing-authentication-require-sign-in.png?fit=max\&auto=format\&n=CImpC64Ju-sB5348\&q=85\&s=bd5483e18c3e13d0b8c6a3a9f7b1cdbb)

| Method | Card | Best for | What **you** provide | Key limitations |
| :- | :- | :- | :- | :- |
| **1. You provide an account** | <kbd>Test account credentials</kbd> | Apps with a plain username/password login and a test account you already control | Username + password | Doesn't cover OTP/2FA or social login on its own |
| **2. TestSprite manages an account** | <kbd>OTP (one-time password) login</kbd> | Apps that require email or SMS one-time codes to sign up / log in | Nothing: TestSprite registers and owns the account | **Fixed at project creation, can't be changed later.** One managed account per environment. Can't run two OTP logins at the same moment |
| **3. You log in, we record it** | <kbd>SSO (single sign-on), e.g. Google</kbd> | SSO and social logins such as Google, plus logins that block automated sign-in (for example, a CAPTCHA or bot detection) | A one-time manual sign-in in a live browser | Session expires and needs periodic re-login. Availability is gated (see [prerequisites](#method-3-prerequisites)) |

***

## Method 1: Existing Test Account

You give TestSprite a username and password for an account you control. It signs in with them before exploring and before every run.

![Test account credentials card expanded with username and password fields](https://mintcdn.com/testspriteinc/CImpC64Ju-sB5348/images/ui-testing-authentication-Existing-Test-Account.png?fit=max\&auto=format\&n=CImpC64Ju-sB5348\&q=85\&s=2e46da3d82d043fc63f55da8ce5c3af3)

### Configuration

**1. Select Test account credentials**

Choose **Sign-in required**, then pick the **Test account credentials** card.

**2. Enter the credentials**

| Field | What to provide |
| :- | :- |
| <kbd>Username</kbd> | The email or username your app's login form expects, e.g. `testuser@example.com` |
| <kbd>Password</kbd> | The password for that account. Use the eye toggle to reveal what you typed. |

**3. Continue**

TestSprite checks that both fields are filled, then uses them during exploration and every run.

### Best for

* Standard email/username + password logins
* A dedicated **test account** you keep in a known state
* Staging environments with seeded accounts

### Limitations

* **Doesn't handle one-time codes.** If your login sends an email or SMS code after the password step, this method gets stuck at the code prompt. Use [Method 2](#method-2-otp-one-time-password-login).
* **Doesn't handle SSO or social login.** "Continue with Google" and similar logins can't be driven with a username and password. Use [Method 3](#method-3-sign-in-with-google).

> [!TIP]
>
> **Use a dedicated test account, not a real user's.** Exploration and runs perform real actions while signed in, so a throwaway account with broad permissions keeps real users' data clean.

***

## Method 2: OTP (One-Time Password) Login

For apps that email or text a one-time code at signup or login. You provide **nothing**: TestSprite registers a dedicated test account with an email address and phone number it owns, receives the code your app sends, and enters it automatically.

![OTP Login card expanded showing Verify via Email / Phone / Email + Phone tabs](https://mintcdn.com/testspriteinc/CImpC64Ju-sB5348/images/ui-testing-authentication-OTP.png?fit=max\&auto=format\&n=CImpC64Ju-sB5348\&q=85\&s=05fd338aab8405c02f86c4b3a9895b23)

### Configuration

**1. Select OTP (one-time password) Login**

Choose **Sign-in required**, then pick the **OTP (one-time password) Login** card.

**2. Choose how your app verifies (Verify via)**

| Option | Use when your app sends the code to… |
| :- | :- |
| <kbd>Email</kbd> | An email address |
| <kbd>Phone</kbd> | A phone number (SMS) |
| <kbd>Email + Phone</kbd> | Both, for two-factor flows that verify an email *and* a phone |

**3. Create the project**

There are no credentials to type. When the project is created, TestSprite provisions the managed account and uses it from then on.

### Best for

* Passwordless logins
* Signups that require email verification before you can proceed
* Two-factor flows where a code is the second factor

### Limitations

> [!WARNING]
>
> **OTP configuration is fixed at project creation.** You can't switch a project to OTP later, turn OTP off, change the channel, or rename an OTP environment. To change it, create a new project or environment with the settings you want.

* **One managed account per environment.** To test with a second managed account, add another [environment](#multiple-test-accounts-multiple-environments).
* **OTP logins in one environment run one at a time**, so the managed inbox or phone doesn't pick up the wrong code. A second login waits for the first, then reuses its session. This is why [session reuse](#reusing-a-login-session) matters most for this method.
* **It depends on your signup and login flow.** It works wherever TestSprite's testing agent can drive registration and code entry. If a flow can't be completed (unusual signup gates, required fields it can't guess, aggressive bot protection), the login fails loudly rather than running signed out. See [Troubleshooting](#troubleshooting).

***

## Method 3: SSO (Single Sign-On)

For SSO and social logins such as **"Sign in with Google"**, and for any login that blocks automated sign-in. TestSprite doesn't automate these. Instead, it opens a real browser, **you** sign in yourself, and TestSprite records the session so later runs start signed in.

![The SSO card selected, with its Set up Login button and a note on how SSO login works](https://mintcdn.com/testspriteinc/CImpC64Ju-sB5348/images/ui-testing-authentication-google.png?fit=max\&auto=format\&n=CImpC64Ju-sB5348\&q=85\&s=ee4a978473d003e46e7e9f46a72b1c03)

### How it works

When you finish creating the project (or click "Log in" from environment settings later), a **live browser opens inside the modal**. You sign in as usual (for example, click "Continue with Google" and complete Google's sign-in), then click **I've finished logging in**. TestSprite captures the signed-in session (cookies and local storage) to replay later.

![Signing in through Continue with Google inside the embedded live browser](https://mintcdn.com/testspriteinc/CImpC64Ju-sB5348/images/ui-testing-authentication-google-work.png?fit=max\&auto=format\&n=CImpC64Ju-sB5348\&q=85\&s=1696269291e9e2a992951008545a594f)

### Configuration

**1. Select SSO (single sign-on)**

Choose **Sign-in required**, then pick the **SSO (single sign-on), e.g. Google** card. If the card isn't there, the feature isn't enabled for your account yet.

**2. Finish creating the project**

The **Log in to your app** modal opens with a live browser pointed at your app. You'll see *"Opening a live browser…"* first.

**3. Sign in yourself in the live browser**

Complete the sign-in. You have up to about 15 minutes.

**4. Click I've finished logging in**

TestSprite captures the session and shows **Login captured ✓**.

> [!NOTE]
>
> **Not ready to log in?** Click **Skip for now**. The project is still created, and you can capture the session later from environment settings (see [Re-authenticating](#re-authenticating-an-expired-session)). Until then, runs execute signed out.

### Best for

* SSO and social logins, such as **"Sign in with Google"** ("Continue with Google")
* Logins that block automated sign-in, for example with a CAPTCHA or bot detection
* Any sign-in that's better completed by a human once than automated

### Limitations

* **Sessions expire.** Your app's own session lifetime is the ceiling. After that, log in again once (see [Re-authenticating](#re-authenticating-an-expired-session)).
* **It needs a human at capture time**, once per session.

### Prerequisites

* Your environment has a **public URL** the live browser can reach. Local URLs (`localhost`, private IPs) can't be reached from TestSprite's browser.

***

## Reusing a Login Session

Instead of signing in before every test, TestSprite can reuse a recent successful login. On the environment form (for OTP and manual-login environments), turn on **Reuse Login Session** and set a **Reuse window** in minutes. Within the window, runs start from the signed-in session; after it, TestSprite logs in fresh.

![Reuse Login Session toggle with a reuse window field](https://mintcdn.com/testspriteinc/CImpC64Ju-sB5348/images/ui-testing-authentication-reuse-existing.png?fit=max\&auto=format\&n=CImpC64Ju-sB5348\&q=85\&s=348d48d3d8e6d252ff501cd88043134e)

> [!WARNING]
>
> **Keep the reuse window shorter than your app's real session lifetime.** If your app signs users out after 60 minutes and the window is 120, reused sessions will already be dead and runs will fail. When in doubt, err short.

***

## Multiple Test Accounts, Multiple Environments

**Each account is one environment**, and a project can have several. That's how you cover different roles (admin vs. member) or tenants (org A vs. org B).

![Environments settings page listing multiple environments each with its own account](https://mintcdn.com/testspriteinc/NgwJ2RcRMRwjh7Vv/images/environment-create-1.png?fit=max\&auto=format\&n=NgwJ2RcRMRwjh7Vv\&q=85\&s=d34900280fc369d579987c6612fa9ff5)

### Adding Another Environment

**1. Open the project's environments**

Go to **Project Settings → Test Execution → Environment**. The default environment carries an **Active** badge.

**2. Click Add Environment**

Give it a **Name** (e.g. `Admin`, `Staging`, `Tenant B`) and a **Website URL**, then set up its login the same way: **Sign-in required** plus one of the three methods.

**3. Point tests at the right environment**

Runs use the **Active** environment by default. Use **Set as Active** to switch, or pin an environment on a test list or schedule.

> [!NOTE]
>
> Each environment holds exactly one test account: one username/password, one managed OTP account, or one recorded session. An OTP environment can't be renamed, so name it correctly when you create it.

***

## Re-authenticating an Expired Session (Method 3)

When a recorded SSO session expires, TestSprite tells you, and runs execute signed out until you refresh it.

![Manual login status card showing an expired session with a Log in again button](https://mintcdn.com/testspriteinc/CImpC64Ju-sB5348/images/ui-testing-authentication-Expired-Session.png?fit=max\&auto=format\&n=CImpC64Ju-sB5348\&q=85\&s=39f12b4e502fa2dff00dc02b7d59c6cf)

On the environment's edit dialog, the **Manual login (Google / SSO)** card shows one of:

| State | What it means | Action |
| :- | :- | :- |
| **Signed in** | A valid session is captured and runs reuse it. Shows when it expires. | Nothing needed |
| **Expired** | The saved login expired; runs execute signed out until you refresh. | Click **Log in again** |
| **Not logged in yet** | You skipped capture at creation. | Click **Log in** |

**Log in again** reopens the live browser so you can sign in and capture a fresh session.

***

## Common Login Failures & Troubleshooting

> [accordion] My login sends a one-time code and Test account credentials gets stuck
>
> Username and password alone can't get past a code prompt. Recreate the project (or add an environment) with **OTP (one-time password) Login**.

> [accordion] My app uses SSO or social login, and login never completes
>
> SSO and social logins such as Google can't be driven with a stored username and password, and some providers block automated sign-in. Use **SSO (single sign-on), e.g. Google** and log in yourself once in the live browser. If you don't see that card, the feature isn't enabled for your account yet; [reach out](https://discord.gg/QQB9tJ973e).

> [accordion] I can't switch an existing project to OTP, or turn OTP off
>
> OTP settings are locked at project creation. Create a new project or environment with the OTP settings you want.

> [accordion] Runs started failing after working fine (SSO project)
>
> The recorded session probably expired. Go to **Project Settings → Test Execution → Environment**, open the environment, and click **Log in again** on the *Manual login (Google / SSO)* card. If it happens often, shorten the [reuse window](#reusing-a-login-session).

> [accordion] The live browser won't open, or says the URL is unreachable
>
> The manual-login browser needs a **publicly reachable URL**; `localhost` and private addresses can't be opened from TestSprite's cloud browser. Use a public staging URL, or set up the MCP server to test locally.

> [accordion] An OTP run waited a while before starting
>
> OTP logins in one environment run one at a time, so a second run waits for the first login and then reuses its session. Turning on [Reuse Login Session](#reusing-a-login-session) cuts down repeat logins.

## Where to Go Next

> [card] [UI Quickstart](https://docs.testsprite.com/web-portal/core/ui/quickstart.md)
>
> The end-to-end walkthrough

> [card] [Feature Exploration](https://docs.testsprite.com/web-portal/core/ui/feature-exploration.md)
>
> How TestSprite uses your login to explore the app

> [card] [Environments](https://docs.testsprite.com/web-portal/setup/environments.md)
>
> Managing multiple environments (and accounts)

> [card] [Auto-Auth (API)](https://docs.testsprite.com/web-portal/core/api/auto-auth.md)
>
> The backend equivalent: token refresh for API tests


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.