# How to Use Variables in TestOwl Tests

:::lead
Variables are reusable values that can be referenced throughout your Test Cases, and Flows. Instead of hardcoding the same value in multiple places, define it once and reuse it everywhere.
:::

:::callout{title="Why use Variables?"}
Using Variables makes your tests easier to maintain. Update the value once, and every Test Case or Flow that references it automatically uses the new value.
:::

## Common use cases

Variables are useful for values that change over time or are reused across multiple tests.

Some common examples include:

- Application URLs
- Usernames
- Email addresses
- Product IDs
- Search terms
- Order numbers
- Environment-specific values

For sensitive values such as passwords, API keys, or access tokens, use [Secrets](/docs/data/secrets) instead.

## Creating a Variable

To create a Variable:

1. Open **Data Config** from the sidebar.
2. Select the **Variables** tab.
3. Click **New Variable**.
4. Enter a unique **Variable Name**, such as `API_BASE_URL`.
5. Choose its **Type** — **Static** for a fixed value, or **Dynamic** to generate a fresh value every run (see [Test Data Generator](/docs/data/test-data)).
6. Enter the **Value**.
7. Choose the **Scope**: **Global**, or **Specific Environments** and pick which ones.
8. Save the Variable.

You can also **Duplicate** an existing Variable from the table to create a similar one quickly.

![Create Variable](/images/data/variables/create-variable.png)

## Using Variables

Variables can be used in any step that supports them.

Reference a Variable using double curly braces:

```text
{{apiBaseUrl}}
```

Most supported fields include a **Select from Variable or Secret** button, allowing you to insert Variables without typing their names manually.

![Using Variables](/images/data/variables/using-variable.png)

## Variable scope

Variables can be configured with different scopes.

### Global Variables

A global Variable is available throughout the entire project and can be used in every Test Case, Flow, and Environment.

Examples include:

- Company name
- Default language
- Shared email address

### Environment-specific Variables

Environment-specific Variables override the global value for a particular Environment.

This is useful when different environments require different values, such as:

- Base URLs
- Test accounts
- Database identifiers
- API endpoints

For example:

| Environment | `apiBaseUrl` |
| --- | --- |
| Development | `https://dev.example.com` |
| Staging | `https://staging.example.com` |
| Production | `https://example.com` |

## Editing Variables

Updating a Variable automatically updates every Test Case and Flow that references it.

There's no need to edit individual tests when a shared value changes.

## Deleting Variables

Deleting a Variable moves it to the [Recycle Bin](/docs/workspace/recycle-bin) instead of permanently removing it.

Variables remain in the Recycle Bin for **15 days** and can be restored during that time, after which they are permanently deleted.

:::warning{title="Before deleting a Variable"}
Before deleting a Variable, make sure it isn't referenced by existing Test Cases or Flows. Removing a Variable may cause those tests to fail until the reference is updated.
:::

## Best practices

- Use Variables instead of repeating the same value across multiple tests.
- Give Variables descriptive names such as `apiBaseUrl` or `adminUsername`.
- Store sensitive information in [Secrets](/docs/data/secrets), not Variables.
- Keep Environment-specific values inside Environment-specific Variables.
- Delete unused Variables regularly to keep your project organised.

## Next steps

::::cardgrid
:::card{title="Secrets" href="/docs/data/secrets"}
Store passwords, API keys, and other sensitive values securely.
:::

:::card{title="Environments" href="/docs/environments/overview"}
Learn how Environment-specific Variables work.
:::

:::card{title="Test Data Generator" href="/docs/data/test-data"}
Generate realistic test data dynamically during test execution.
:::
::::