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

# Authenticate your tests

> Learn how to set up and use authentication in your Stably tests, including email-based logins, Google SSO, and test account management.

Authentication is a critical part of any application. If you're building tests that cover the parts of your app users actually care about, chances are you'll need to log in. Whether it's a simple email/password form or a more complex Google SSO flow, being able to authenticate reliably is key to building meaningful and trustworthy tests.

In this guide, we'll walk you through how to set up and use authentication in your tests using Stably.

***

## Setting Up Test Accounts

Before testing authentication, you’ll need to set up some test credentials.

### Email-Based Test Accounts

You can store these as environment variables within your project:

1. Go to [app.stably.ai](https://app.stably.ai)

2. From the sidebar, click **Test Data**

3. Navigate to the **Variables** tab

4. Fill out the name-value pair (you can use JSON):

   ```json theme={null}
   Name: test_account  
   Value: { "email": "test@email.com", "password": "testpassword" }
   ```

5. Click **Save**

You can now access this test account in your test logic using:

```ts theme={null}
VARS.test_account.email
VARS.test_account.password
```

### SSO Test Accounts (e.g. Google)

Set up your SSO test accounts under the same **Test Data > Test Accounts** section.

<Note>
  We’ve already documented how to do this. You can follow the detailed guide here:
  [Google OAuth Setup](/platform-capabilities/google-oauth)
</Note>

***

## Logging Into Your App in a Test

Once your test accounts are set up, here's how to use them during test recording.

### Email-Based Logins

<Tip>
  A quicker alternative to the steps below is to use <strong>Stably's AI agent</strong> to create the login actions. In the <strong>Add Step</strong> menu, simply select the <strong>Generate with AI</strong> option and instruct it to log in using your test account variable (i.e., "Log in using the `test_account` credentials").
</Tip>

1. Start recording your test as usual.
2. When the login screen appears:
   * Right-click the **email field** → choose **Fill**
   * In the modal, set the input type to **Dynamic**
   * Enter: `VARS.test_account.email`
3. Repeat the same steps for the **password field** using `VARS.test_account.password`
4. Click **Login** and continue recording the rest of your test.

### Google SSO Logins

<Note>
  Ensure your Google test account is already set up.
</Note>

1. From the **Add Step** or **Add Operation** menu, choose **Login to Google**
2. In the modal, select the test account you want to use from the dropdown
3. Click **Select** to confirm
4. Begin recording your test
5. When prompted in the login form, click **Sign in with Google**. The login flow should proceed automatically since the Google account is already logged in thanks to the previous "Login with Google" action.
6. (Optional) Visit [https://accounts.google.com](https://accounts.google.com) in the recorder to confirm that the login worked

***

## Reusing Login Steps

Once you've created login steps in one test, you can easily reuse them across multiple tests by creating a reusable component. This saves time and ensures consistency across your test suite.

### Creating a Login Component

<Steps>
  <Step title="Create the login steps">
    Create the login steps like you would normally (following the steps above for either email-based or Google SSO logins)
  </Step>

  <Step title="Select the login actions">
    Select all the actions that make up the login flow and click "Create Component"

    <Frame>
      <img src="https://mintcdn.com/stablyai/gQcjGEzeMU3Scby6/images/auth-core/select-actions.png?fit=max&auto=format&n=gQcjGEzeMU3Scby6&q=85&s=cebc6798e63eb06bf3a39444034d9bfb" alt="Selecting actions to create a component" width="3248" height="2112" data-path="images/auth-core/select-actions.png" />
    </Frame>
  </Step>

  <Step title="Name your component">
    Give the component a unique and relevant name (e.g., "Login with Main Account") and create the component

    <Frame>
      <img src="https://mintcdn.com/stablyai/gQcjGEzeMU3Scby6/images/auth-core/create-component.png?fit=max&auto=format&n=gQcjGEzeMU3Scby6&q=85&s=90a27511edb722c2297d9f38d09b0c2e" alt="Creating component from selected actions" width="3248" height="2112" data-path="images/auth-core/create-component.png" />
    </Frame>
  </Step>

  <Step title="Component replacement">
    Stably will automatically replace the actions with the component call in your current test
  </Step>
</Steps>

### Using Login Components in New Tests

In future test drafts, you can quickly add your login flow:

<Steps>
  <Step title="Open Add Step menu">
    Open the **"Add Step"** menu in your test draft
  </Step>

  <Step title="Find your component">
    **Scroll down or search** to find your component (e.g., "Login with Main Account")

    <Frame>
      <img src="https://mintcdn.com/stablyai/gQcjGEzeMU3Scby6/images/auth-core/finding-component.png?fit=max&auto=format&n=gQcjGEzeMU3Scby6&q=85&s=b4b6f8dd7b570150b6f08ed7c2a5db6a" alt="Finding the component in the Add Step menu" width="3248" height="2112" data-path="images/auth-core/finding-component.png" />
    </Frame>
  </Step>

  <Step title="Add to test draft">
    **Click on it** to add the entire login flow to your test draft

    <Frame>
      <img src="https://mintcdn.com/stablyai/gQcjGEzeMU3Scby6/images/auth-core/having-used-component.png?fit=max&auto=format&n=gQcjGEzeMU3Scby6&q=85&s=097ea9e37e62037e161d3fcab007a93c" alt="After having added the login component" width="3248" height="2112" data-path="images/auth-core/having-used-component.png" />
    </Frame>
  </Step>
</Steps>

<Tip>
  Login components are particularly useful for regression testing and when building test suites that require authentication across multiple user flows.
</Tip>

***

## Migrating from the Old "Auth Steps"

If you've used Stably before, you might be familiar with the older **auth steps** — AI-powered steps that bundled all the logic into a single step.

These legacy auth steps have now been **deprecated**.

They’ve been replaced with more flexible, modular actions like **“Login to Google”**, which you can combine with regular Playwright actions (click, fill, etc.) and Stably environment variables to create reliable, customizable login flows.

***

## Final Notes

Authentication can be complex — especially when anti-bot measures are in play. With Stably’s new modular login features and environment variable support, we aim to make testing auth flows as seamless and flexible as possible.

<Tip>
  Need help with authentication? Don’t hesitate to reach out to our team at [help@stably.ai](mailto:help@stably.ai)
</Tip>
