Docs/Macros and variables
#

Macros and variables

Generate fresh test data in every run with macros such as $EMAIL(), $RANDOM_STRING() and $DATE(), and reuse values across steps with $var references, workflow inputs and step-qualified names.

Make my test data fresh on every run

A macro is a token like $EMAIL() that Cofactor replaces with new data every time a test runs. A variable like $var.user_email carries a value from one step to a later one. Together they keep tests from colliding with data left by an earlier run.

Use a macro in a step

  1. Pick a field that takes a macro. Open the test in the Flow Designer, select a step, and click a field such as an action's title, description or inputs, a Navigate URL, or an MCP step's instructions. Type $ to open the suggestions menu, keep typing to filter, and press Enter to insert one.

  2. Write the macro by hand when you know it. A macro is $NAME() or $NAME(args). It works on its own or inside a longer string.

    text
    $EMAIL()
    QA Test $FIRST_NAME() $LAST_NAME()
    order-$RANDOM_STRING(6)
    

    To type the text $EMAIL() without running it, put a backslash first: \$EMAIL().

  3. Save a generated value you need again. A value you enter in an action step's Inputs section becomes a variable named after the input. If the input company has the value Acme $RANDOM_STRING(6), later steps can read $var.company and get the same value the earlier step used.

  4. Check the Variables list. Click the canvas background so that no step is selected. The Configure tab lists every variable the test uses, with a label for where it comes from: Input, Macro, Extracted, Credential, Seed, Called Flow, Workflow Input or Environment. A warning on a name means more than one step defines it. Use the step-qualified name in that case.

Macro catalog

MacroGives youExample
$UUID()A random UUID v4a1b2c3d4-e5f6-7890-abcd-ef1234567890
$EMAIL()A unique test addresstest-k3x9q2ab@example-test.com
$FIRST_NAME()A first name from a fixed listJordan
$LAST_NAME()A last name from a fixed listChen
$PHONE()A US number in the 555 range+1-555-382-7491
$RANDOM_INT(min, max)An integer from min to max, both included$RANDOM_INT(100,999) gives 427
$RANDOM_STRING(length)Letters and digits, 1 to 1000 characters$RANDOM_STRING(5) gives xK9mQ
$PICK(a,b,c)One of the values you list, at random$PICK(212,312,415) gives 312
$TODAY()Today's date as YYYY-MM-DD2026-02-19
$DATE(days)The date that many days from today; negative for the past$DATE(-7)
$NOW()The current time as an ISO 8601 timestamp2026-02-19T14:30:00.000Z
$NOW(offset, "format")The time shifted by +5m, -2h, 30s or 1d, optionally formatted in UTC$NOW(+5m, "HH:mm")
$TIMESTAMP()Unix time in milliseconds1771520400000
$SEQUENCE("name")1, 2, 3 and so on for each use of that name in a run; it starts again at 1 in the next run$SEQUENCE("orders")
$AI("prompt")Text an AI writes for your prompt; Cofactor asks once per distinct prompt in a run$AI("subject of a refund question")

An unknown macro name or bad arguments is an error. Format tokens for $NOW are YYYY, MM, DD, HH, mm, ss, and the unpadded H and m. A format cannot contain commas or parentheses.

Workflow inputs

A workflow input is a value you define once and fill in before each run, such as a user email or a role. Each input becomes a variable.

  1. Open the input editor. Click the canvas background so that no step is selected. In the Configure tab, click Configure scenarios, then open the Schema tab.

  2. Add an input. Click Add input and set:

    FieldWhat it does
    LabelThe name people see when they run the test, for example User email.
    TypeText, Email, Number, Password, Textarea, or Persona.
    Variable nameHow steps refer to it, for example $var.user_email. Cofactor fills it in from the label.
    RequiredThe run needs a value for it.
    Default valueUsed when a scenario or a run does not set the input. It accepts macros, except for Password inputs.
  3. Save. Click Save schema.

  4. Use it. Type $var.user_email in any step field. When you start a run, the Run configuration dialog asks for each input.

To run the same test with different sets of input values, see Scenarios.

Read a variable from another step

Variables come from several places.

SourceHow you refer to it
A workflow input, or an action step's input$var.name
Data captured from the page$var.order_id
A seed test's output$var.<dataKey>, using the output name the seed declares
A persona input$var.<input name>.username and the other credential fields
An application variable you declared$var.ENV.<NAME>
Another step, when two steps use the same name$var.Step2_Create_Client.id

Seeds and captured data are covered in Setup, seed & teardown.

Check it worked

  1. Run the test twice. Open both runs and confirm that each used different values for the fields where you added macros.
  2. In the Configure tab, confirm that the Variables list shows each name you expect and no collision warnings.
  3. For a workflow input, start a run from the app and confirm the Run configuration dialog lists it, with an asterisk on required inputs.

Go deeper

  • Scenarios turn workflow inputs into named variations such as admin and member.
  • Setup, seed & teardown explains how seeded data reaches a test.
  • Core nodes lists the step types that accept macros.
  • Run cofactor workflow guide macros for the macro reference the CLI prints.