Robot Framework library for generating test data files from templates with dynamic content
Project description
Robot Framework Template Processor
A library for generating test data files from templates with dynamic content. Perfect for creating test fixtures, mock data, and complex test scenarios with date/time manipulation, loops, and auto-incrementing values. Can Be used with Robot Framework or with Python directly.
Concept Overview
Use this tool to avoid heavy maintenance.
Template file
|
v
+-------------------+
| Template |-> Output file
Inputs (variables / lists) -> | Processor |
+-------------------+
Template generation pattern is especially helpful to avoid maintenance of countless test files when the format changes or when the format needs updating. It allows you to maintain your template in one place instead of a number of pre-made files.
Also, when big and long files are required, this generator is a way to go.
Features
- Dynamic Date/Time: Generate timestamps with day or month offsets
- Auto-Incrementing Values: Create sequential IDs and counters
- Loops: Iterate over lists to generate repeated content blocks
- Nested Loops: Support for complex nested loop structures
- Variable Substitution: Replace placeholders with constant values
- Synchronized Lists: Iterate multiple lists in parallel within loops
- Loop-Scoped Counters: Independent counters that increment per iteration
Features to come
- Random value: Generate random value withing given limits
- Random list value: Places random value from given list (e.g. list of allowed statuses)
Installation
pip install robotframework-templateprocessor
Or install from source:
git clone https://github.com/DmitriKhanoukaev/robotframework-templateprocessor.git
cd robotframework-templateprocessor
pip install -e .
Quick Start
Robot Framework Usage
See the simple example below. For more examples, refer to:
- templates in
./tests/data/ - generated results in
./tests/temp/ - the tests that generate them in
./tests/TemplateBasedGenerator.robot
*** Settings ***
Library TemplateProcessorLibrary.py
*** Test Cases ***
Small Demo Test Showing Concept Of Template Based Generation
[Tags] gen_file_demo dkh
Generate File ${Temppath}DemoFile.txt
... ${Data}Demo_TEMPLATE.txt
... LINECOUNT=${3}
... INDEXSHIFT=1
File Should Exist ${Temppath}DemoFile.txt
${content} = Get File ${Temppath}DemoFile.txt
Where Demo_TEMPLATE.txt is:
This file will have %%%CONSTANT@LINECOUNT%%% lines and it was generated %%%NOW@0@%Y-%m-%d%%%
%%%LOOP@LINECOUNT@demolines%%%
line index %%%INDEX%%%
%%%LOOP@END@demolines%%%
DemoFile.txt will be generated:
This file will have 3 lines and it was generated 2026-02-27
line index 1
line index 2
line index 3
Python Usage
from TemplateProcessorCore import TemplateProcessor
processor = TemplateProcessor()
template_content = "ID: %%%CONSTANT@ID%%%, Time: %%%NOW@0@%Y-%m-%d%%%"
result = processor.process(template_content, {"ID": "test001"})
print(result) # ID: test001, Time: 2026-02-20
Template Syntax
1. Date/Time Placeholders
Syntax: %%%NOW@offset@format%%%
Generate current date/time with day offset:
Template:
Test run at: %%%NOW@0@%Y.%m.%d %H:%M:%S%%%
4 days ago: %%%NOW@-4@%Y.%m.%d%%%
3 days ahead: %%%NOW@3@%Y.%m.%d%%%
Output:
Test run at: 2026.02.20 15:08:29
4 days ago: 2026.02.16
3 days ahead: 2026.02.23
Syntax: %%%MONTHDELTA@offset@format%%%
Generate date/time with month offset:
Template:
2 months ago: %%%MONTHDELTA@-2@%Y.%m.%d%%%
1 month ahead: %%%MONTHDELTA@1@%Y.%m.%d%%%
Output:
2 months ago: 2025.12.20
1 month ahead: 2026.03.20
2. Variable Substitution
Syntax: %%%CONSTANT@ID%%%
Replace with parameter values:
Template:
File ID: %%%CONSTANT@ID%%%
Environment: %%%CONSTANT@ENV%%%
Robot Framework:
Generate File output.txt template.txt ID=file001 ENV=Production
Output:
File ID: file001
Environment: Production
3. Auto-Incrementing Counters
Syntax: %%%INC@base@increment%%%
Generate sequential values:
Template:
%%%INC@1.1@0.001%%%
%%%INC@1.1@0.001%%%
%%%INC@1.1@0.001%%%
Output:
1.1
1.101
1.102
4. Loops
Syntax:
%%%LOOP@INPUT@loopname%%%
... content ...
%%%LOOP@END@loopname%%%
Generate repeated content blocks:
Template:
%%%LOOP@ITEMS@myloop%%%
Item #%%%INDEX%%%: %%%myloop.VALUE%%%
%%%LOOP@END@myloop%%%
Robot Framework:
Generate File output.txt template.txt ITEMS=${['Apple', 'Banana', 'Cherry']}
Output:
Item #1: Apple
Item #2: Banana
Item #3: Cherry
5. Loop-Scoped Counters
Syntax: %%%LOOPINC@base@increment%%%
Counters that reset for each loop iteration:
Template:
%%%LOOP@ITEMS@myloop%%%
Loop index: %%%INDEX%%%
Counter: %%%LOOPINC@2.1@0.2%%%
%%%LOOP@END@myloop%%%
Output:
Loop index: 1
Counter: 2.1
Loop index: 2
Counter: 2.3
Loop index: 3
Counter: 2.5
6. Synchronized Lists in Loops
Syntax: %%%LOOPLIST@ID%%%
Iterate multiple lists in parallel:
Template:
%%%LOOP@INDICES@myloop%%%
Code: %%%LOOPLIST@CODES%%%
Value: %%%LOOPLIST@VALUES%%%
%%%LOOP@END@myloop%%%
Robot Framework:
Generate File output.txt template.txt
... INDICES=${[0, 1, 2]}
... CODES=${['ABC', 'DEF', 'XYZ']}
... VALUES=${[333, 444, 555]}
Output:
Code: ABC
Value: 333
Code: DEF
Value: 444
Code: XYZ
Value: 555
7. Nested Loops
Full support for nested loop structures with accessible loop context:
Template:
%%%LOOP@OUTER@loop1%%%
Outer #%%%loop1.INDEX%%%: %%%loop1.VALUE%%%
%%%LOOP@INNER@loop2%%%
Inner #%%%loop2.INDEX%%%: %%%loop2.VALUE%%%
%%%LOOP@END@loop2%%%
%%%LOOP@END@loop1%%%
Keywords
Generate File
Generates a file from a template.
Arguments:
output_file: Path to the output filetemplate_file: Path to the template file**parameters: Template parameters (key=value pairs)
Returns: Timestamp used in generation
Example:
${timestamp}= Generate File
... /tmp/output.txt
... template.txt
... ID=test123
... ENV=Production
... ITEMS=${['A', 'B', 'C']}
Generate File And Return Content
Generates a file and returns both the content and timestamp.
Arguments:
output_file: Path to the output filetemplate_file: Path to the template file**parameters: Template parameters (key=value pairs)
Returns: Tuple of (content, timestamp)
Example:
${content} ${timestamp}= Generate File And Return Content
... /tmp/output.txt
... template.txt
... ID=test123
Use Cases
- Test Data Generation: Create realistic test datasets with varying dates and IDs
- API Test Payloads: Generate JSON/XML files with dynamic content
- Database Seeding: Create SQL insert scripts with sequential values
- Load Testing: Generate large test files with repeated patterns
- Time-Based Testing: Test with past, present, and future dates
- Localization Testing: Generate test files in multiple formats
Examples
Complete examples are available in the tests/ directory:
- Date/time manipulation: tests/data/DateTimeEdgeCases_TEMPLATE.txt → tests/temp/DateTimeEdgeCases.txt
- Loop examples: tests/data/Loop_TEMPLATE.txt → tests/temp/Looped.txt
- Nested loops: tests/data/NestedLoops_TEMPLATE.txt → tests/temp/NestedLoops.txt
- Complex combinations: tests/data/ComplexCombinations_TEMPLATE.txt → tests/temp/ComplexCombinations.txt
Running Tests
# Run Robot Framework tests
robot tests/TemplateBasedGeneratorNew.robot
# Run Python unit tests
pytest tests/test_template_processor.py
Contributing
Contributions are welcome! Please feel free to submit a Pull Request. Or suggest a feature.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Development Setup
# Clone the repository
git clone https://github.com/DmitriKhanoukaev/robotframework-templateprocessor.git
cd robotframework-templateprocessor
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install development dependencies
pip install -e .
pip install -r requirements-dev.txt
# Run tests
robot tests/TemplateBasedGeneratorNew.robot
pytest tests/
License
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
Support
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Robot Framework Slack:
#toolschannel
Credits
Developed for the Robot Framework community by the community and Dmitri Khanoukaev.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file robotframework_templateprocessor-1.0.0.tar.gz.
File metadata
- Download URL: robotframework_templateprocessor-1.0.0.tar.gz
- Upload date:
- Size: 5.6 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0038735a37cc5e43457f94a29afa6ab6baeae7b0a32fb677a1196ffea1bb907c
|
|
| MD5 |
be6212784c4cdaf6a6646479176e990e
|
|
| BLAKE2b-256 |
31c3e8088139f78751ed3c5fc424ac3b668b36063eee5a3c258a517326c6e4e5
|
File details
Details for the file robotframework_templateprocessor-1.0.0-py3-none-any.whl.
File metadata
- Download URL: robotframework_templateprocessor-1.0.0-py3-none-any.whl
- Upload date:
- Size: 14.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4e8270add51f4b2a52f2a8094688dc63255cfba19510e4e6abf00a5aeb1e6f48
|
|
| MD5 |
9fdff279f9f68b99ffc519fa3999080a
|
|
| BLAKE2b-256 |
bfe3e6b25f3e17dea276dca20ad2f7b14b60b6662a648520221dab57186c4560
|