Robot Framework

7.4.2 · active · verified Thu Apr 09

Robot Framework is a generic open-source automation framework for acceptance testing, acceptance test-driven development (ATDD), and robotic process automation (RPA). It uses a keyword-driven approach, allowing for easy-to-read test cases. The project is actively maintained with frequent bug fix releases (e.g., 7.4.x series) and feature releases (e.g., 7.4, 7.3) typically a few times a year. The current version is 7.4.2.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to programmatically run a Robot Framework test from a Python script. It creates a simple `.robot` file on the fly and then uses `robot.run` to execute it. This is useful for integrating Robot Framework into CI/CD pipelines or other automation scripts. Standard usage often involves running tests directly from the command line using `robot path/to/tests.robot`.

import os
import tempfile
from pathlib import Path
from robot import run

# Create a temporary .robot test file
robot_content = '''
*** Settings ***
Library    OperatingSystem

*** Test Cases ***
My First Robot Test
    Log To Console    Hello from Robot Framework!
    Create File    ${TEMPDIR}${/}robot_test.txt    This is a test file.
    File Should Exist    ${TEMPDIR}${/}robot_test.txt
    Remove File    ${TEMPDIR}${/}robot_test.txt
'''

with tempfile.TemporaryDirectory() as tmpdir:
    test_file_path = Path(tmpdir) / 'my_test.robot'
    test_file_path.write_text(robot_content)

    print(f"Running Robot Framework test from: {test_file_path}")
    # Execute the test programmatically
    # Setting loglevel to DEBUG for verbose output, can be omitted
    result = run(test_file_path.as_posix(), loglevel='INFO', outputdir=tmpdir)

    if result == 0:
        print("Robot Framework test ran successfully!")
    else:
        print(f"Robot Framework test failed with exit code: {result}")

    print(f"Output and logs can be found in: {tmpdir}")

view raw JSON →