Dynamic Calculations
Sometimes a step needs a value that cannot be hard-coded — today's date, an age computed from a birthday, a random number, the current value of a counter plus ten, and so on. msg.ZenTestAI offers two ways to handle this:
- Macros — the recommended way. A macro is a named, parameterized function you define once and reuse across tests. Macros are deterministic, can be tested in isolation, and the value they produce is predictable.
- Dynamic Calculations (
${ ... }) — the legacy approach described on this page. It still works, but is only suited to genuine one-off needs.
When to use what
| Use case | Use this |
|---|---|
| You need the same computation in many places, or expect to need it again later. | Macro |
| You want the value verified before the test runs. | Macro (use the test-run-in-sandbox feature) |
| You need a one-shot calculation that you genuinely don't want to keep around as a macro. | Dynamic Calculation (this page) |
Type = in any step or URL field to open the macro autocomplete. Pick (or quickly create) the macro that fits your case — it will be reusable and deterministic from then on. See the Macros chapter for the full guide.
Limitations of Dynamic Calculations
Compared to macros, dynamic calculations have two important downsides — which is why we recommend macros as the default:
- Less consistent. Each calculation is interpreted by the AI agent at execution time from your free-text description. Two similar-looking calculations can drift apart in subtle ways (rounding, formatting, time zone), making test results less reproducible.
- Cannot be tested in isolation. There is no way to validate a dynamic calculation outside of running the full test step. With a macro, you can run it against sample inputs in the macro editor before saving.
For those reasons, treat dynamic calculations as a workaround for one-time use rather than a building block of your test suite.
How a Dynamic Calculation works
Everything you write inside ${ ... } (note: no = after the $, that would be a macro call) is interpreted by an AI agent during test execution. The agent receives the following context to base its answer on:
- the current URL,
- the current date and time,
- the current browser settings (language, timezone, …),
- the current user / role identifier,
- all parameter names and their values.
The agent computes a value from your free-text description and the context above, and that value replaces the ${ ... } block in the step before the step itself is executed.
Examples
Type ${ current date and time, UTC in format DD.MM.YYYY HH:mm:ss } into the field "Current Date and Time"
Type ${ 18 years ago, format YYYY } into the field "Birth Year"
Remember the amount of steps in parameter [[AMOUNT_OF_STEPS]].
Type ${ [[AMOUNT_OF_STEPS]] + 10 } into the field "Entries visible"
Type ${ random number between 1 and 100 } into the field "Random Number"
Test cases should be as reproducible as possible. Even with a careful prompt, dynamic calculations can produce slightly different values from one run to the next. Wherever the same computation will be needed more than once — or where reproducibility matters — convert it into a macro instead.