# Variables: reuse values in tests

URL: https://testmode.ai/docs/variables/

> A variable is a named value you define once per project and reuse in Testmode steps, Expected Outcomes and Start Paths. Syntax, naming and matching rules.

A variable is a named value, such as a search term or a support message, that you define once for a project and use in many tests as `{{Name}}`. When a test runs, Testmode replaces each variable with its current value, so changing the value in one place updates every test that uses it.

You manage variables for the current project under **Settings** > **Variables**. Every member can see the list and copy a variable's syntax. Viewers don't see **Add Variable** or the edit and delete icons.

## Create a variable

**Before you start:** you need the Editor role or above.

1. Open **Settings** in the sidebar and click the **Variables** tab.

2. Click **Add Variable**.

3. Enter a **Name**, for example `Search Term`.

4. Enter the **Value**, for example `hammer`. It can span several lines.

5. Optionally add a **Description**, for example `Keyword used by catalogue search tests`.

6. Click **Save**.

Testmode shows "Variable created". The list is sorted by name and shows each variable's description and value.

[Screenshot: Variables settings listing named values with descriptions, with a copy confirmation check mark next to Search Term. Caption: Variables hold values you reuse across tests; copy the double-brace syntax with one click.]

The [Assistant](https://testmode.ai/docs/create-tests-with-the-assistant/) and [exploration proposals](https://testmode.ai/docs/review-and-apply-proposals/) can also create variables for you. Both need the Editor role or above too.

If saving fails, the message says why. For example, "A variable with this name already exists" means the name is taken in this project, and a name with other characters is refused with "Name must start with a letter or underscore and contain only letters, numbers, spaces, dashes, and underscores".

## Insert a variable into a test

In the test case editor, the **Insert Variable** button sits on each step, on **Expected Outcome** and on **Start Path**. You need the Editor role or above to save the test case.

1. Put the cursor where the value should go.

2. Click **Insert Variable**.

3. Search or scroll, then click the variable. Each one shows its description and current value.

The variable appears as a chip that shows its current value, for example `hammer`. Hover the chip to see "Variable: Search Term". Click the X on a chip to remove it.

The Toolshop test case "Search finds hammers" uses `{{Search Term}}` in its first step. Saved, the step reads:

```text
Type {{Search Term}} into the "Search" field and click "Search".
```

When the test runs, Testmode reads it as: Type hammer into the "Search" field and click "Search".

**Note: Added a variable while Test Cases was open?**

The Test Cases page loads variables when it opens. If you add a variable in **Settings** while Test Cases is open, reload Test Cases to see it in the picker. A variable you type by hand is still filled in when the test runs.

## Copy a variable's syntax

On the **Variables** tab, click the copy icon next to a variable's name. Testmode copies the name in double braces, such as `{{Search Term}}`, and shows "Copied to clipboard". Paste it into any step, Expected Outcome or Start Path. If your browser blocks clipboard access, Testmode shows "Could not copy to clipboard" instead.

## Edit or delete a variable

**Before you start:** you need the Editor role or above.

- **Edit:** click the pencil on the row, change the name, value or description and click **Save**. Tests pick up the new value the next time they run.
- **Delete:** click the trash icon, then **Delete** in the **Delete variable?** dialog. Testmode shows "Variable deleted".

Renaming or deleting a variable does not update the tests that use it. They keep the old `{{Name}}` text, which is then no longer filled in (see the rules below). Search your test cases for the old name before you rename.

## Syntax and naming rules

| Rule | Details | Example |
| --- | --- | --- |
| Syntax | The exact name in double braces, with nothing else inside. | `{{Search Term}}` |
| First character | A letter or an underscore. | `Search Term`, `_basket` |
| Other characters | Letters, numbers, spaces, dashes and underscores. | `Contact Subject`, `order-2` |
| Uniqueness | One variable per name in a project. | |
| Case | Names match exactly, including letter case. | `{{search term}}` does not match `Search Term` |
| Spaces in braces | Spaces inside the braces become part of the name. | `{{ Search Term }}` does not match |
| Unknown name | Left in the text exactly as written, with no warning. | `{{Serch Term}}` stays as typed |
| Value | Any text, including several lines. It cannot be empty. | `My cordless drill stopped charging…` |

An unknown name does not make the test fail by itself. The agent receives the literal text, so a typo can lead to odd input or a failed test. Check spelling and case first when a test with variables misbehaves.

## Where variables are filled in

| Filled in | Not filled in |
| --- | --- |
| Steps of a test case | Environment **Base URL** |
| **Expected Outcome** | Credential fields (username, password, Login URL) |
| **Start Path** | Test case names |
| Exploration start paths | Tags |

Testmode fills in values when each test starts executing, so a test always uses the latest value, even if you changed it after starting the run.

## Variables are not secrets

Variable values are plain text. Every member of the organization can read them on the **Variables** tab and in the test case editor. A value the agent types can also appear in the recorded Test Steps of a run.

Keep passwords out of variables. Store logins as [credentials](https://testmode.ai/docs/credentials-and-automatic-login/) instead: their passwords are encrypted, never shown, and used only for automatic login.

## Related

  - [Write a test case](https://testmode.ai/docs/write-a-test-case/): Steps, Expected Outcome and Start Path, where variables go.
  - [Credentials and automatic login](https://testmode.ai/docs/credentials-and-automatic-login/): The right place for passwords.
  - [What Testmode records and who sees it](https://testmode.ai/docs/what-testmode-records/): Typed values, screenshots and logs.
