Robot Framework DataDriver
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
-
Importing library 'DataDriver' failed: ModuleNotFoundError: No module named 'DataDriver'
cause The `robotframework-datadriver` package is not installed in the Python environment being used by Robot Framework.fixRun `pip install robotframework-datadriver` to install the library. -
Invalid argument count for Library 'DataDriver'. Expected 1 to 2 arguments, got 0.
cause The DataDriver library requires at least one argument, which is the path to the data file (e.g., Excel, CSV, JSON).fixProvide the path to your data file when importing the library, e.g., `Library DataDriver path/to/my_data.xlsx`. -
RERUN FAILED tests with DataDriver does not work after upgrading to Robot Framework 7.
cause Robot Framework 7.x introduced internal API changes, specifically relocating `robot.running.model.Variable`, which affected the RerunFailed feature in older DataDriver versions.fixUpgrade `robotframework-datadriver` to version 1.11.1 or higher to fix compatibility issues with Robot Framework 7.x's RerunFailed modifier. -
Excel cell containing 'None' is interpreted as NaN or empty instead of string 'None' when using DataDriver.
cause This is due to a change in Pandas 2.0 where the string 'None' is by default converted to a `None` value when reading Excel files, and `robotframework-datadriver` versions prior to 1.8.0 did not account for this.fixUpgrade `robotframework-datadriver` to version 1.8.0 or higher. This version includes a fix that ensures the string 'None' is preserved.
Warnings
- breaking Breaking changes in Robot Framework 7.x APIs require `robotframework-datadriver` version 1.10.0 or higher for basic compatibility, and 1.11.1+ for features like `RerunFailed`.
- gotcha When using `robot.run` (programmatically, not via CLI), `DataDriver` previously could not correctly pick up `include` or `exclude` tags.
- gotcha Pandas 2.0 changed its default behavior, interpreting the string 'None' in Excel cells as a `None` value (NaN in pandas) instead of the literal string 'None'.
- gotcha Earlier versions had issues correctly importing custom data readers by their module name, leading to `ModuleNotFoundError` or similar import failures.
- gotcha Test case names containing the `|` character (pipe symbol) could cause issues in earlier versions, especially when used with Pabot.
Install
-
pip install robotframework-datadriver
Imports
- AbstractDataDriverReader
from DataDriver import AbstractDataDriverReader
Quickstart
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')