Random Data Generation

Generate dynamic, random test data inline in your Gherkin files using the {{ rand:type:options }} syntax

Random Data Generation

TestFlowKit's random data engine lets you inject dynamic, random values directly in your Gherkin files — without writing any step code. Values are generated at runtime, each time the step executes.

Syntax

{{ rand:type }}
{{ rand:type:key=value }}
{{ rand:type:key=value,key=value }}

The rand: prefix tells the engine to generate a value. Everything after is the type and its options.

Supported Generators

UUID

Generates a random UUID v4.

When I set the request body to:
  """
  { "id": "{{ rand:uuid }}" }
  """

Email

Generates a random email address. Optionally pin the domain.

# Random email with random domain
And I store the value "{{ rand:email }}" into "user_email" variable

# Force a specific domain
And I store the value "{{ rand:email:domain=kil.com }}" into "user_email" variable

Phone Number

Generates a valid phone number for a given country.

OptionValuesDefault
countryISO 3166-1 alpha-2 code (FR, US, GB, …)US
formate164, national, internationale164
# France — E.164 (best for APIs)
And I store the value "{{ rand:phone:country=FR,format=e164 }}" into "phone" variable
# → +33612345678

# USA — national format (for frontend forms)
And I store the value "{{ rand:phone:country=US,format=national }}" into "phone" variable
# → (415) 555-2671

# USA — international
And I store the value "{{ rand:phone:country=US,format=international }}" into "phone" variable
# → +1 415-555-2671

Phone format guide

FormatExampleUse for
e164+33612345678APIs, databases, assertions
national06 12 34 56 78Frontend form fields
international+33 6 12 34 56 78UI display, logs

Integer

Generates a random integer within a range.

OptionDefault
min0
max1000
And I store the value "{{ rand:int:min=1,max=99 }}" into "quantity" variable

Date

Generates a random date.

OptionValuesDefault
directionpast, future, nowpast
formatAny Go time layoutRFC3339 (2006-01-02T15:04:05Z07:00)
# Past date in ISO 8601
And I store the value "{{ rand:date:direction=past }}" into "birth_date" variable

# Future date in short format
And I store the value "{{ rand:date:direction=future,format=2006-01-02 }}" into "expiry" variable

# Current timestamp
And I store the value "{{ rand:date:direction=now }}" into "timestamp" variable

Words / Free Text

Generates a random sentence with the given number of words.

OptionDefault
count3
And I store the value "{{ rand:words:count=6 }}" into "description" variable

Regex

Generates a string matching a regular expression.

# Generates e.g. "ABC-1234"
And I store the value "{{ rand:regex:pattern=[A-Z]{3}-\d{4} }}" into "code" variable

# Generates a hex color
And I store the value "{{ rand:regex:pattern=#[0-9A-F]{6} }}" into "color" variable

The pattern= option consumes the rest of the expression, so commas and colons inside the regex are safe.

Usage Patterns

REST API

Generate a dynamic request body each test run:

Scenario: Create a user with random data
  Given I prepare a request to "myapi.create_user"
  And I store the value "{{ rand:uuid }}" into "user_id" variable
  And I store the value "{{ rand:email:domain=kil.com }}" into "user_email" variable
  When I set the request body to:
    """
    {
      "id": "{{user_id}}",
      "email": "{{user_email}}"
    }
    """
  And I send the request
  Then the response status code should be 201
  And the response should contain "{{user_email}}"

GraphQL

Random values work directly in GraphQL variable tables:

Scenario: Create a post with random content
  Given I prepare a request to "myapi.create_post"
  And I set the following GraphQL variables:
    | title | {{ rand:words:count=4 }} |
    | body  | {{ rand:words:count=12 }} |
  When I send the request
  Then the GraphQL response should not have errors

Frontend Forms

Scenario: Register with random phone number
  Given the user goes to the "registration" page
  And I store the value "{{ rand:phone:country=FR,format=national }}" into "phone" variable
  When the user enters "{{phone}}" into the "phone" field
  And the user clicks the "submit" button
  Then the "confirmation" should be visible

Reusing a Generated Value

Each {{ rand:uuid }} call generates a new value. To use the same value multiple times, store it first:

# Store once
And I store the value "{{ rand:uuid }}" into "request_id" variable

# Reuse as many times as needed
When I set the request body to:
  """
  { "id": "{{request_id}}" }
  """
Then the response should contain "{{request_id}}"

Reproducibility

Every generated value is logged to the console output at execution time with the [rand] prefix, so failing tests can be investigated:

[rand] generated '{{ rand:uuid }}' → 4a8b2c1d-...
[rand] generated '{{ rand:phone:country=FR,format=e164 }}' → +33612345678

Best Practices

  • ✅ Use {{ rand:uuid }} for IDs — guaranteed unique, no collision
  • ✅ Use e164 format for phone numbers in API tests — most stable
  • ✅ Store generated values into variables before reusing them
  • ✅ Check the console log when a test fails — the exact values are printed
  • ⚠️ Avoid {{ rand:... }} in config.yml — it is only resolved at step execution time, not at config load time

Next Steps