Variables
Introduction
Variables let you capture dynamic information at runâtime and reference it later from a single, wellâknown location.
- Project variables (global) live at the project level and are shared by every test in the workspace.
- Local variables are defined inside an individual test and exist only for that test run.
Using variables keeps your scenarios concise and resilient â you change the value in one place and every reference stays up to date.
Defining Project Variables
Open Test Data Variables
Open Test Data ⸠Variables in the leftâhand navigation.
Add a new variable
Click + Add Variable, give it a name and value, then save.
Mark as sensitive (optional)
Toggle Sensitive to hide the value after creation.
Tip: Because project variables are encrypted at rest you can safely store secrets such as API keys, passwords, or tokens.
Defining Local Variables
You can add a Define variable step anywhere in a test. Stably offers four ways to assign a value:
1. Static value
Type any literal such as 3
, true
, or "hello world"
and click Save.
2. Extract from the current page
When defining the variable value, select the âAI Extractionâ option and simply type in a natural language description of the data you want to extract, and Stably will capture its text/attribute in realâtime. In the example below we store the large centered number in var1
:
3. Generate test data with AI
In case you donât need a very particular value, but something random that satisfies a set of criteria, then use AI to generate appropriate random values â e.g. âGenerate a phone number ending in 6363â. Stably creates realistic, unique data every run.
4. Compute a value using an expression
Use JavaScript ande any built-in helpers to combine or transform existing variables (prefix VARS.
) to come up with the value that will be assigned to this new variable
5. Extract from email
Stably also allows you to extract information from emails that are sent to you Stably-provisioned email address. For more details on how to do this, check out this document on âReceiving Emailsâ
Using Variables in Tests
There are several ways to utilize variables throughout your tests. Note that all variables (both global and local) are referenced from the same VARS
object
1. Inside custom code blocks
Use VARS.<name>
to refer to the variable with name <name>
. VARS
is a JS object so you can use it like how you would any other JS object.
2. Fill inputs with variable values
Similarly, when filling out text inputs, you can reference your variables in the same way to fill the input with variableâs value rather than a static literal.
3. AI agent context
Whenever you ask Stablyâs AI to generate steps it automatically receives the current variable set, so you can prompt it with instructions like âif VARS.plan
is âpremiumâ skip the upsell pageâ.
4. AI assertions
Variables are also supplied to the AI when asserting, so you can add a layer of conditional logic to your AI visual assertions.
Best practices
âď¸ Do | â Avoid |
---|---|
Give variables descriptive, lowerâcamelCase names (totalRevenueToday ). | Abbreviations that will be hard to remember later (trtd ). |
Store secrets in project variables marked Sensitive. | Hardâcoding credentials directly in steps. |
Reâuse variables instead of duplicating text across steps. | Updating the same literal value in many places. |
Reset or regenerate variables at the start of each run when needed. | Relying on state left over from previous runs. |