Allure Robot Framework

2.15.3 · active · verified Fri Apr 17

Allure Robot Framework integration provides a listener for Robot Framework that automatically collects test results and converts them into Allure's intermediate JSON format. This allows for generating rich, interactive test reports with detailed information on test execution. The current version is 2.15.3, and it follows the release cadence of the broader allure-python project, which is generally active with frequent updates.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates the full lifecycle: creating a minimal Robot Framework test, executing it with the Allure listener to generate raw results, and then processing those results into an interactive HTML report using the Allure command-line tool. Ensure `robotframework`, `allure-robotframework`, and `allure-commandline` are installed.

import os
import subprocess

# 1. Create a dummy Robot Framework test file
robot_file_content = """
*** Settings ***
Library    OperatingSystem
Library    allure_robotframework.library_api

*** Test Cases ***
Simple Allure Robot Test
    Log To Console    Starting Allure Robot Test
    allure_robotframework.library_api.step    This is an Allure step
    Create File    test_attachment.txt    Some attachment content
    allure_robotframework.library_api.attach    test_attachment.txt
    Log To Console    Test completed!
"""
robot_file_path = "example.robot"
with open(robot_file_path, 'w') as f:
    f.write(robot_file_content)
print(f"Created {robot_file_path}")

# 2. Run Robot Framework tests with the Allure listener
print("\n--- Running Robot Framework tests ---")
# This command executes Robot Framework, using allure-robotframework as a listener.
# It generates raw Allure results in the 'allure-results' directory.
try:
    subprocess.run(
        ["robot", "--listener", "allure_robotframework", robot_file_path],
        check=True,
        capture_output=True,
        text=True
    )
    print("Robot Framework tests executed successfully. Allure results generated in 'allure-results'.")
except subprocess.CalledProcessError as e:
    print(f"Error running Robot Framework tests: {e}")
    print(f"Stdout:\n{e.stdout}")
    print(f"Stderr:\n{e.stderr}")
    print("Please ensure 'robotframework' and 'allure-robotframework' are installed.")
    exit(1)
except FileNotFoundError:
    print("Error: 'robot' command not found. Please install Robot Framework.")
    exit(1)

# 3. Generate the Allure report
print("\n--- Generating Allure report ---")
# This command processes the raw results and creates a human-readable HTML report.
# It requires the 'allure-commandline' tool to be installed.
report_dir = "allure-report"
try:
    subprocess.run(
        ["allure", "generate", "allure-results", "-o", report_dir, "--clean"],
        check=True,
        capture_output=True,
        text=True
    )
    print(f"Allure report generated successfully in '{report_dir}'.")
    print(f"To view the report, open '{os.path.abspath(report_dir)}/index.html' in your browser, or run 'allure open {report_dir}'.")
except FileNotFoundError:
    print("\nError: 'allure' command not found.")
    print("Please install the Allure command-line tool. See https://docs.qameta.io/allure/#_install_a_commandline for instructions.")
    exit(1)
except subprocess.CalledProcessError as e:
    print(f"Error generating Allure report: {e}")
    print(f"Stdout:\n{e.stdout}")
    print(f"Stderr:\n{e.stderr}")
    exit(1)

# Optional cleanup:
# os.remove(robot_file_path)
# os.remove("test_attachment.txt")
# import shutil
# shutil.rmtree("allure-results", ignore_errors=True)
# shutil.rmtree(report_dir, ignore_errors=True)

view raw JSON →