Robot Framework Faker Library
robotframework-faker is a Robot Framework keyword library that acts as a wrapper for the popular Faker Python library, enabling easy generation of fake test data within Robot Framework test suites. The current version is 6.0.0, supporting Python 3.9 through 3.13. Releases are made as needed, often coinciding with significant changes in the underlying Faker library or Robot Framework compatibility updates.
Common errors
-
[ ERROR ] Error in file 'mytest.robot' on line X: Importing test library 'FakerLibrary' failed: ModuleNotFoundError: No module named 'FakerLibrary'
cause The `robotframework-faker` package is not installed in the Python environment where Robot Framework is running, or there's a typo in the library import statement.fixEnsure `robotframework-faker` is installed: `pip install robotframework-faker`. Double-check the spelling in your Robot file: `Library FakerLibrary`. -
[ ERROR ] Error in library 'FakerLibrary': Adding keyword 'ean8' failed: Union cannot be empty.
cause This specific error often indicates a compatibility issue between `FakerLibrary` and newer versions of Robot Framework (e.g., 7.0.0+), potentially related to changes in Robot Framework's internal keyword loading or `Faker`'s data structures.fixCheck the `robotframework-faker` GitHub issues for updates on Robot Framework 7.x compatibility. Temporarily, consider downgrading Robot Framework to a previous stable version (e.g., 6.1.1) if the issue is urgent. -
Importing test library 'FakerLibrary' failed: ... (generic import failure or 'contains no keywords')
cause The library might be installed, but Robot Framework cannot locate it due to an incorrect Python environment, incompatible Python versions, or a corrupted installation.fixVerify `pip list` shows `robotframework-faker` and `Faker` in the active environment. Ensure Robot Framework is executed from the same Python environment where these libraries are installed. Confirm your Python version is within the supported range (3.9-3.13 for `robotframework-faker` v6.0.0).
Warnings
- breaking Version 5.0.0 removed support for Python 2.7, aligning with the upstream Faker library's move to Python 3.
- breaking Version 6.0.0 removed the `pkg_resources` API, which was deprecated in Setuptools. This may affect specific build or deployment environments that relied on it. [cite: v6.0.0 release notes]
- gotcha Starting with v6.0.0, `robotframework-faker` no longer pins the version of its underlying `Faker` package. This means the user is responsible for ensuring `Faker` is installed and that its version is compatible with the `FakerLibrary` keywords being used. Mismatched versions can lead to unexpected behavior or missing keywords.
- gotcha FakerLibrary keywords cannot be directly called within Robot Framework's `*** Variables ***` section. This section is for static assignments, not for executing dynamic keywords that generate data at runtime.
Install
-
pip install robotframework-faker
Imports
- FakerLibrary
from robotframework_faker import FakerLibrary
*** Settings *** Library FakerLibrary
Quickstart
--- example.robot ---
*** Settings ***
Library FakerLibrary locale=en_US
Documentation Example of using Robot Framework Faker Library
*** Test Cases ***
Generate a Fake Name and Address
${name}= FakerLibrary.Name
Log To Console Generated Name: ${name}
${address}= FakerLibrary.Address
Log To Console Generated Address: ${address}
Generate Multiple Words
${words_5}= FakerLibrary.Words nb=5
Log To Console 5 Words: ${words_5}
--- To run ---
pip install robotframework robotframework-faker
robot example.robot