Skip to main content

Overview

Environments let you organize variables into named groups — such as Production, Staging, or Local Dev — so your tests can use different configurations depending on the context they run in. Each environment holds a set of key-value variables that your tests can reference at runtime. Variables can be marked as sensitive to protect secrets like API keys and passwords.

Creating an Environment

1

Navigate to Environments

Click Environments in the sidebar.
2

Click New

Click the + New button in the toolbar.
3

Enter details

Provide a Name (e.g., Production, Staging) and an optional Description to help your team understand what this environment is for.
4

Create

Click Create. The new environment appears in the table and opens automatically.

Managing Variables

Click any environment row to open its detail drawer, where you can add, edit, search, and delete variables.

Adding Variables

1

Enter name and value

Type a variable Name and Value in the form at the top of the drawer.
2

Mark as sensitive (optional)

Toggle Sensitive if the value contains a secret (API key, password, token). Sensitive values are encrypted and masked in the UI.
Once a variable is marked as sensitive, it cannot be changed back. The value will be hidden and only accessible by your tests at runtime.
3

Add more rows (optional)

Click + Add Variable to add multiple variables at once before saving.
4

Save

Click Save to store all new variables.

Editing Variables

Click the pencil icon on any variable row to open inline editing. You can change the name, value, or toggle the sensitive flag (for non-sensitive variables only).

Deleting Variables

Click the trash icon on any variable row. A confirmation dialog will appear before the variable is permanently removed.

Sensitive Variables

Sensitive variables provide an extra layer of protection for secrets:
BehaviorDetail
Masked in UIDisplayed as •••••••• with a lock icon.
Hidden from APIThe get endpoint returns null for sensitive values.
IrreversibleOnce marked sensitive, a variable cannot be changed back.
Editable valueYou can update the value of a sensitive variable, but you won’t see the current value.
Auto-scrubbed from tracesWhen using --env, sensitive values are automatically redacted from Playwright traces before upload.
Always mark API keys, passwords, database credentials, and tokens as Sensitive.

Automatic Trace Scrubbing

When you run tests with stably test --env <name>, any variable marked Sensitive is automatically scrubbed from Playwright traces before they are uploaded to Stably. You do not need to configure sensitiveValues in your playwright.config.ts — the CLI handles it for you. This means the simplest way to protect secrets in traces is:
  1. Add your secrets as variables on this page and mark them as Sensitive.
  2. Run tests with --env:
stably test --env Staging
That’s it — sensitive values are redacted automatically.
If you need to scrub additional values that are not stored in a Stably Environment (e.g., locally defined secrets), you can also pass them manually via the sensitiveValues option in the reporter config. See Stably Test Reporter — Sensitive Data Scrubbing for details.

Default Environment

You can set a default environment for your project. The default environment is automatically used by scheduled runs and cloud executions when no specific environment is selected. To set a default, click the star icon next to an environment in the list, or use the Set as Default option in the environment detail drawer.

Using Environments from the CLI

The --env flag lets you load a named environment’s variables directly from Stably when running CLI commands. This removes the need to manage local .env files — variables are fetched securely from the Stably API at runtime.
# Load variables from your "Staging" environment
stably test --env Staging

# Works with all CLI commands
stably create "login test" --env Production
stably --env "Local Dev"
The CLI fetches all variables from the named environment and injects them into process.env for your tests. Variables marked as Sensitive are automatically scrubbed from Playwright traces — see Automatic Trace Scrubbing above.
The --env flag requires authentication. Set STABLY_API_KEY and STABLY_PROJECT_ID, or run stably login first.

Variable Precedence

When using the CLI, variables can come from multiple sources. They are resolved in the following order, from lowest to highest priority:
PrioritySourceDescription
1 (lowest)process.envSystem environment variables and shell exports
2--env-fileLocal .env files loaded via --env-file path
3--envRemote environment variables fetched from Stably
4 (highest)Stably internalsSTABLY_API_KEY, STABLY_PROJECT_ID
If the same variable name exists in multiple sources, the higher-priority source wins. For example, a BASE_URL defined in your --env Staging environment will override the same variable from a local --env-file .env file.
You can combine --env and --env-file in the same command. Use --env-file for local overrides and --env for shared team configuration stored in Stably.

Loading from a Local .env File

You can also load variables from a local file using the --env-file flag:
# Load from a specific file
stably test --env-file .env.staging

# Load multiple files (later files override earlier ones)
stably test --env-file .env --env-file .env.local

Downloading as .env

Click Download .env in the environment detail drawer to export all variables as a .env file. Non-sensitive variables include their full values, while sensitive variables appear as empty placeholders.
Sensitive variable values are not included in the download. You will need to fill them in manually.

Bulk Import

Click Bulk Import to import variables from a .env file into an environment. This is useful for migrating existing local configurations into Stably.