Advanced Expressions for Test Data
This guide explains how to use dynamic expressions in your UI tests for forms, assertions, API payloads, and validations. These expressions allow you to generate contextual data at test runtime instead of hardcoding static values.
Date Formatting
Use natural language inside {{date:...}} syntax to generate dynamic dates. Our AI-powered date engine interprets your request and returns the appropriate date.
Why Use Dynamic Dates?
- Automate date-dependent scenarios - Test workflows that depend on current or future dates
- Eliminate hardcoded dates - No more updating tests when dates expire
- Relative date logic - Calculate dates relative to test execution (e.g., "today + 2 days")
- Business logic support - Handle complex requirements like "last working day of the month"
How It Works
Write any date description in natural language after the colon. The system uses AI to interpret your request and generate the correct date.
Syntax: {{date:your natural language description}}
Common Examples
| Use Case | Expression | Example Output |
|---|---|---|
| Current date | {{date:today}} | 2025-05-28 |
| Tomorrow | {{date:tomorrow}} | 2025-05-29 |
| Yesterday | {{date:yesterday}} | 2025-05-27 |
| Days from now | {{date:today +2 days}} | 2025-05-30 |
| First working day of last week | {{date:first working day of last week}} | 2025-05-20 |
| Next week's Friday | {{date:next weeks Friday, generate a valid date}} | 2025-06-06 |
| Random date in next year | {{date:a random date in the next year, generate a valid date}} | 2026-03-15 |
| First Wednesday of next year | {{date:first Wednesday of next year}} | 2026-01-07 |
| End of current quarter | {{date:last day of current quarter}} | 2025-06-30 |
Custom Output Formats
Add >> followed by your desired format pattern to customize the output.
| Format Pattern | Expression | Example Output |
|---|---|---|
| Day only | {{date:today>>dd}} | 28 |
| Month only | {{date:today>>mm}} | 05 |
| Year only | {{date:today>>yyyy}} | 2025 |
| US format | {{date:today>>mm/dd/yyyy}} | 05/28/2025 |
| Custom format | {{date:tomorrow>>dd yyyy}} | 29 2025 |
| ISO timestamp | {{date:today>>yyyy-mm-dd}}T09:00:00 | 2025-05-28T09:00:00 |
Relative Date Calculations
| Operation | Expression | Example Output |
|---|---|---|
| Previous month | {{date:today -1 month>>mm}} | 04 |
| Previous year | {{date:today -1 year>>yyyy}} | 2024 |
| Next month | {{date:today +1 month>>mm}} | 06 |
| Next year | {{date:today +1 year>>yyyy}} | 2026 |
| 30 days ago | {{date:today -30 days}} | 2025-04-28 |
Tip: You can use d or D interchangeably in expressions (e.g., +2 days or +2 Days).
Concatenation Expressions
Combine static text, numbers, and dynamic values to build complex inputs like email addresses, usernames, or test IDs.
String + String
Join multiple strings using the + operator.
Example:
{{"username_" + "test"}}
Output: username_test
Example with dates:
{{date:today +1 year>>yyyy}}T09:00:00.000+01:00
Output: 2026T09:00:00.000+01:00
Number + Number
Perform arithmetic operations with numbers or test data variables.
Example:
{{5 + 3}}
Output: 8
Example with variables:
{{base_price + 10}}
Output: 110 (if base_price is 100)
String + Number
Combine text with numeric values from your test data.
Example:
{{"Order_" + 12345}}
Output: Order_12345
Example with variables:
{{"Total: $" + {{price}}}}
Output: Total: $99.99 (if price is 99.99)
String + Faker
Combine static strings with dynamically generated faker.js values using the ${} syntax.
Example:
${'test_' + {{internet.userName()}}}
Output: test_john_doe47
Example for email:
${'qa_' + {{internet.userName()}} + '@testdomain.com'}
Output: qa_alice_smith@testdomain.com
Note: You can use any faker.js method. Common ones include:
{{internet.userName()}}- Random username{{internet.email()}}- Random email{{name.firstName()}}- Random first name{{phone.number()}}- Random phone number{{address.city()}}- Random city name
Custom JavaScript Evaluation
For complex calculations or transformations beyond simple expressions, use JavaScript code blocks with the ${} syntax.
Capabilities
- Built-in JavaScript functions (ES5 and ES6+)
- Access to test data variables
- Math operations and string manipulations
- Array and object methods
Example: Calculate Tax
Use case: Add 18% tax to a base price stored in test data.
Expression:
${{{base_price}} * 1.18}
Example:
- If
base_price= 100 - Output:
118
Example: Format Phone Number
Expression:
${{{raw_phone}}.replace(/(\d{3})(\d{3})(\d{4})/, '($1) $2-$3')}
Example:
- If
raw_phone= "5551234567" - Output:
(555) 123-4567
Example: Conditional Logic
Expression:
${{{age}} >= 18 ? 'Adult' : 'Minor'}
Example:
- If
age= 25 - Output:
Adult
Example: Generate Random Number in Range
Expression:
${Math.floor(Math.random() * 100) + 1}
Output: Random number between 1-100
Where to Use These Expressions
These expressions work in:
- Form input fields - Auto-fill test data dynamically
- Assertions - Verify expected values with computed dates or calculations
- API payloads - Build request bodies with dynamic data
- Test data variables - Define reusable computed values
- Element locators - Generate dynamic selectors (use with caution)
- Validation rules - Compare against expected formats or ranges
Best Practices
- Use natural language for dates - The AI interpreter handles complex date logic better than manual calculations
- Keep expressions readable - Break complex logic into multiple test data variables
- Test your expressions - Verify outputs in a test run before using in critical paths
- Combine approaches - Use concatenation + faker + JavaScript together for powerful data generation
- Document custom expressions - Add comments in your test data for team clarity
Common Patterns
Generate Unique Email
${'test_' + Date.now() + '@example.com'}
Future Appointment Date (7 days out)
{{date:today +7 days>>mm/dd/yyyy}}
Calculate Age from Birth Year
${new Date().getFullYear() - {{birth_year}}}
Random Selection from Array
${['Red', 'Blue', 'Green'][Math.floor(Math.random() * 3)]}
Format Currency
${'$' + {{amount}}.toFixed(2)}
Troubleshooting
Expression not evaluating?
- Check syntax:
{{date:...}}for dates,${}for JavaScript - Verify variable names match your test data exactly
- Ensure quotes are balanced in string concatenation
Date returning unexpected value?
- Be specific in natural language (e.g., "next Monday" vs "Monday")
- Use format specifier if output format is wrong:
>>yyyy-mm-dd - Try rephrasing the date description
JavaScript expression error?
- Only built-in JavaScript is available (no external libraries)
- Check for typos in method names
- Verify test data variables exist before referencing them
