Robot Framework DataDriver

1.11.2 · active · verified Thu Apr 16

robotframework-datadriver is a library for Data-Driven Testing within the Robot Framework ecosystem. It allows users to separate test data from test logic, making it easier to manage and scale tests by running the same test case with multiple sets of input data. The library is actively maintained, with version 1.11.2 being the latest, and it frequently releases updates to ensure compatibility with new Robot Framework versions.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `robotframework-datadriver` with a simple CSV data file. It creates a CSV file and a Robot Framework test suite (`.robot` file) on the fly, then executes the tests using the `robot` command-line tool. Each row in the CSV will generate a separate test case, logging the provided parameters.

import os
import subprocess

# Create a dummy data file (e.g., my_data.csv)
csv_content = "TEST_NAME,param1,param2\nTest 1,ValueA,ValueB\nTest 2,ValueC,ValueD"
with open('my_data.csv', 'w') as f:
    f.write(csv_content)

# Create a Robot Framework test suite (e.g., my_tests.robot)
robot_content = """
*** Settings ***
Library    DataDriver    my_data.csv

*** Test Cases ***
My Data-Driven Test
    Log To Console    Data Row: ${data_row}
    Log To Console    Test Name: ${TEST_NAME}
    Log To Console    Param1: ${param1}
    Log To Console    Param2: ${param2}
"""
with open('my_tests.robot', 'w') as f:
    f.write(robot_content)

# Run the Robot Framework tests using subprocess
print("Running Robot Framework tests...")
result = subprocess.run(['robot', 'my_tests.robot'], capture_output=True, text=True)
print(result.stdout)
if result.stderr:
    print(result.stderr)

# Clean up generated files
os.remove('my_data.csv')
os.remove('my_tests.robot')
os.remove('output.xml')
os.remove('log.html')
os.remove('report.html')

view raw JSON →