Aller au contenu principal

Dynamic Values in ${…} Placeholders

A ${…} placeholder is how a value is filled in at run time instead of being typed in now. Inside the braces, one of two things can be written:

  • a variable name — ${BookingReference} — resolved from the environments and the values extracted by earlier steps;
  • a function call — ${GetDate()} — computed when the step runs.

Function calls are how a request gets today's date, a fresh identifier, or a random value without a script step. They re-evaluate on every run, so a test that needs "tomorrow" never has a stale date in it.

The quickest case​

A flight search needs a departure date one day ahead, and it must stay correct next month.

  1. Add a mapping rule to the step, and put this in its Value:
    ${GetDateTime("yyyy-MM-dd", "86400")}
  2. Run it. The rule writes tomorrow's date, in ISO form, into the field the rule targets.

Nothing else in the test knows the value was computed, so assertions and later steps can reference the same field as usual.

Where a ${…} is evaluated​

PlaceEvaluated
A mapping rule's value (data transfer between steps)Yes — when the rule runs
A manual filling rule's value in the API PlaygroundYes — when the request is sent
A wait-message step's filtering rule valueYes — when the step runs
A request URL, path or headerYes — at send time
A value typed straight into a request body field, or into an assertion's expected value as a literalStored as written; a ${…} there stays literal text

The distinction that matters in practice: a rule interprets its value, a field stores what you typed. When you need a computed value in a body, put it there with a mapping rule rather than typing the token into the body.

Writing a call​

${GetDateTime("yyyy-MM-dd", "86400")}
${Concat("BAG-", BookingReference)}
  • Arguments are text in double quotes — "86400", "yyyy-MM-dd".
  • An argument without quotes names a variable, resolved like any other placeholder. That is how you mix a constant with something the run produced: ${Concat("BAG-", BookingReference)}.
  • Calls nest, so a function may take another function's result as its argument.
  • Offsets are in seconds, and the sign is direction: 86400 is one day ahead, -86400 one day back, 7200 two hours ahead.
  • All arguments arrive as text; a function that needs a number parses it itself.
  • Keep commas, closing parentheses and closing braces out of an argument's text — they are what marks an argument's end.

The functions​

Date and time​

FunctionReturns
GetDate()Today as yyyy-MM-dd.
GetDateTime()The current date and time in the machine's usual format. Prefer an explicit format.
GetDateTime(format)The current date and time in a format you name, e.g. ${GetDateTime("yyyy-MM-dd HH:mm")}.
GetDateTime(format, offsetSeconds)The same, shifted by an offset: ${GetDateTime("yyyy-MM-dd", "86400")} is tomorrow.
GetUnixTimeStamp()The current Unix time in seconds.
GetUnixTimeStamp(offsetSeconds)The same, shifted.

These run on the clock of the machine executing the test.

Identifiers​

FunctionReturns
NewGuid()A new GUID, lowercase with hyphens.
GetGuid(format)A new GUID in a chosen form — N (no separators), D, B (braced), P (parenthesised).

Random values​

FunctionReturns
RandomInt(min, max)A whole number from min up to but not including max.
RandomString(length)A random alphanumeric string of that length.
RandomDigits(length)A random string of digits — useful for phone numbers and one-time codes.

Text​

FunctionReturns
ToUpper(value) / ToLower(value)The value upper-cased or lower-cased.
Trim(value)The value without surrounding whitespace.
Length(value)How many characters it has.
Concat(a, b)Two values joined.
Replace(input, oldValue, newValue)The input with every occurrence replaced.
Substring(value, startIndex)From a zero-based position to the end.
Substring(value, startIndex, length)A bounded slice. A position past the end is an error, not an empty result.

Encoding​

FunctionReturns
Base64Encode(value) / Base64Decode(value)Base64 of the value, and back. Decoding something that is not valid Base64 fails and says so.
UrlEncode(value) / UrlDecode(value)Percent-encoding, and back.

Completion while typing​

Type $ in a rule's value field and a list opens: the variables available at that point in the test, followed by the functions. A function row shows its parameters, so you can tell the overloads apart:

${BookingReference}
${GetDateTime(format, offsetSeconds)}
${RandomInt(min, max)}

Choosing a function inserts a complete, working call — ${RandomInt("1", "100")} — with the first argument's value selected, so typing replaces it and the quotes and the rest of the call stay as they are. Choosing a no-argument function, such as ${GetDate()}, just inserts it.

When something is wrong​

  • Unknown function name, or the wrong number of arguments — the rule fails, and the step's information names the function. The call is not silently left as text.
  • An unquoted argument that matches no variable — the rule fails naming that argument. Quote it if you meant it as text.
  • A ${…} that stays visible in a request — it was written somewhere values are stored rather than evaluated (see the table above), or it names a variable that does not exist in the active environment.

Fresh value each run, or one value reused​

Because a function is evaluated every time, a data-driven case gets a different value per row. That is usually what you want for unique keys. When a run must reuse one value across several steps, extract it once into a variable and reference that variable — repeating the token gives repeating values.