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 }}" }
"""
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.
| Option | Values | Default |
|---|---|---|
country | ISO 3166-1 alpha-2 code (FR, US, GB, …) | US |
format | e164, national, international | e164 |
# 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
| Format | Example | Use for |
|---|---|---|
e164 | +33612345678 | APIs, databases, assertions |
national | 06 12 34 56 78 | Frontend form fields |
international | +33 6 12 34 56 78 | UI display, logs |
Integer
Generates a random integer within a range.
| Option | Default |
|---|---|
min | 0 |
max | 1000 |
And I store the value "{{ rand:int:min=1,max=99 }}" into "quantity" variable
Date
Generates a random date.
| Option | Values | Default |
|---|---|---|
direction | past, future, now | past |
format | Any Go time layout | RFC3339 (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.
| Option | Default |
|---|---|
count | 3 |
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
e164format 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
- Variables — Store and reuse variables across steps
- API Testing — REST and GraphQL testing
- Frontend Testing — Browser automation steps