Skip to main content

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.

License

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 file
  • template_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 file
  • template_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:

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.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. 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

Credits

Developed for the Robot Framework community by the community and Dmitri Khanoukaev.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

robotframework_templateprocessor-1.0.0.tar.gz (5.6 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file robotframework_templateprocessor-1.0.0.tar.gz.

File metadata

File hashes

Hashes for robotframework_templateprocessor-1.0.0.tar.gz
Algorithm Hash digest
SHA256 0038735a37cc5e43457f94a29afa6ab6baeae7b0a32fb677a1196ffea1bb907c
MD5 be6212784c4cdaf6a6646479176e990e
BLAKE2b-256 31c3e8088139f78751ed3c5fc424ac3b668b36063eee5a3c258a517326c6e4e5

See more details on using hashes here.

File details

Details for the file robotframework_templateprocessor-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for robotframework_templateprocessor-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4e8270add51f4b2a52f2a8094688dc63255cfba19510e4e6abf00a5aeb1e6f48
MD5 9fdff279f9f68b99ffc519fa3999080a
BLAKE2b-256 bfe3e6b25f3e17dea276dca20ad2f7b14b60b6662a648520221dab57186c4560

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page