Variables, test-level and global

Keep credentials, environment URLs, and generated values out of your steps and in one editable place.

View as Markdown

A variable is a named value you can reference from a step instead of typing it inline. Write it as a token in double braces, and Testsnag substitutes the value when the step runs. The payoff is that a password, a staging URL, or an account email lives in exactly one place, and changing it does not mean editing twelve steps across four tests.

  1. 1A plain variable. Reference it from any step as a double-braced token.
  2. 2A secret variable. Its value is masked here and in AI responses.
  3. 3Reveal, lock, or delete a variable.
Type {{username}} into the email field
Navigate to {{base_url}}/checkout

Two levels

Test-level variables belong to a single test and are edited from its recorder. Global variables belong to the whole workspace and are edited from the Variables page in the sidebar. When both define the same name, the test wins, which lets one test override a workspace default without affecting anything else.

Global variables and test-level variables are available on every plan.

Environment variables

An environment such as Staging or Production can carry its own variables. During a run in that environment they win over every other layer. The full order, from lowest to highest, is global, then block, then test, then environment.

Secret values

Mark a variable secret and its value is masked in the interface. Use it for passwords and API keys. It is still sent to the site under test, exactly as typing it would be, so treat secret as "not shown on screen" rather than as a vault.

Generated values

Some tests need a value that must be different every run, such as the email address on a sign-up form that rejects duplicates. Testsnag provides tokens for that: random tokens produce a fresh value on each use, while persistent tokens generate a value once and reuse it consistently for the rest of the run, so a sign-up step and a later login step can share the same generated address.

{{rs}}    random string, 8 characters
{{rs12}}  random string, 12 characters
{{rn}}    random digits, 6 characters
{{prs}}   persistent random string, stable for the whole run

Still stuck, or spotted something out of date?

Contact support