Skip to content
Browse docs
Docs / Browser tests / Test environments, variables and secrets

Test environments, variables and secrets

An environment is where your tests run, such as staging or production, and the values their steps use there: a base URL, test account names, passwords. Write a test once with {{baseUrl}} and {{password}}, and the environment fills them in.

Add an environment

  1. On the Tests page, click Environments at the top right, then New environment.
  2. Enter a Name, such as Staging or Production.
  3. Enter the Base URL, for example https://staging.example.com. Steps that start with {{baseUrl}}, and start addresses that are only a path such as /login, open this address.
  4. Under Variables, click Add variable for each value your steps need: a name (letters, digits and _, starting with a letter) and its value.
  5. Turn on Secret for passwords, API keys and two-factor seeds.
  6. Click Add environment.
The Edit environment sheet for Staging: its base URL, The workspace default switched on, the variable username and the variable password stored as a secret

Secrets are write-only

A secret is stored encrypted. Once saved, it shows as Stored with a lock, and nobody can read it back, not even an admin. Click Replace to type a new value, or Keep the stored value to change your mind.

When a step types a secret variable, Monity treats it as secret: the value shows as •••• in results, logs and alerts, and the field is blurred in screenshots. The step’s sentence names the variable, such as {{password}}, with a lock.

The environments page

The Environments page with the Staging environment, its Default tag, base URL and variables, the secret shown with a lock

Each card shows the environment’s base URL and variables; secrets show only their name and a lock. The ⋮ menu has Edit, Make default and Delete.

The default environment

One environment in each workspace is The workspace default; the first one you add is. Tests run on it unless the test or its folder chooses another. To change it, make another environment the default. If you delete an environment a test uses, that test runs on the default instead.

Choose the environment for a test

In the editor’s Start card, pick the Environment. The line below shows its base URL. For a test in a folder that sets one, the first choice is Same as the folder. A folder can set the environment for all its tests, and a deploy trigger can run a test on another environment with ?environment=Production.

The Environment menu in the editor's Start card: Same as the folder (Staging), and Staging tagged Default

Where a variable’s value comes from

When a step uses {{name}}, the run looks in this order and takes the first value it finds:

  1. Values saved earlier in the same run by Save a value or Set a variable steps.
  2. The test’s own variables, in the editor’s Variables card.
  3. The environment’s variables.
  4. The built-in values, such as {{baseUrl}} and {{random.email}} (see Write a browser test).

So a test can override one environment value for itself. Keep secrets in environments rather than in a test’s variables, which are not encrypted.

Log in with two-factor authentication

For a test account protected by an authenticator app, Monity can type the current code:

  1. When you set up two-factor authentication for the test account, copy the secret key the site shows (often under “Can’t scan the QR code?”). The whole otpauth:// link also works.
  2. Add it to the environment as a variable, for example shopTotp, and turn on Secret.
  3. In the test, add a Type step into the code field with the value {{totp.shopTotp}}.

Each time the step runs, Monity works out the code that is valid at that moment, as the app on your phone would: six digits every 30 seconds by default, or the digits, period and algorithm an otpauth:// link sets.

Use test accounts

Give tests their own account on your site, with no real customer data and no admin rights. Everyone in the workspace can open a run and see what the test saw on each page.

Kamil, Alex and Martyna Median reply under 6 hours

Have a question?

Pricing, security, or scoping - pick a route and you will land in a real person's inbox.