Robot Framework – Logging, Reporting, and Screenshots

Robot Framework automatically generates detailed logs and reports after every test execution. It allows to add custom logs, debug information, and screenshots to make test results more informative and easy to analyze.

1. Built-In Logs and Reports

Executing a test command like: robot tests/

generates three output files in the working directory:

File

Description

report.html

High-level summary of all test results

log.html

Detailed keyword-level log of each test step

output.xml

Raw data used internally to build reports


2. Custom Logging

Custom messages can be added using BuiltIn keywords.

*** Test Cases ***
Custom Logging Example
    Log    Starting the test case
    Log To Console    Appears on terminal
    Log    Test completed successfully.    INFO


Logging Keywords

Keyword

Description

Log

Writes a message to the log file

Log To Console

Prints directly to the terminal

Log Many

Logs multiple messages at once

Set Log Level

Adjusts verbosity (TRACE, DEBUG, INFO, WARN, ERROR)


Example with Log Levels

Set Log Level    DEBUG
Log    Debug info shown in log    DEBUG
Log    Warning message    WARN
Log    Error message    ERROR


3. Logging Variables and Responses

Variables can be logged to understand runtime behavior:

${response}=    Get Request    api    /users
Log    ${response.status_code}
Log    ${response.text}
Log Many    ${variable1}    ${variable2}    ${variable3}


4. Taking Screenshots

Screenshots are useful for UI testing or debugging failed steps.

*** Test Cases ***
Screenshot Example
    Open Browser    https://robotframework.org    chrome
    Capture Page Screenshot
    Close Browser


5. Advanced: screenshot-on-failure

In Robot Framework, screenshot-on-failure behavior can be achieved using a Teardown in combination with Run Keyword If Test Failed (or using the built-in automatic screenshot on failure in SeleniumLibrary). Here’s how the example can be modified:

*** Settings ***
Library    SeleniumLibrary
Library    OperatingSystem
*** Test Cases ***
Save Screenshot On Failure
    [Teardown]    Take Screenshot On Failure
    Open Browser    https://example.com    chrome
    # Example step that may fail
    Page Should Contain    NonExistingElement
    Close Browser
*** Keywords ***
Take Screenshot On Failure
    Run Keyword If Test Failed
    ...    Capture Page Screenshot    ./results/screenshots/failure_${TEST NAME}.png
    ...    Log To Console    Screenshot saved at ./results/screenshots/failure_${TEST NAME}.png


Explanation:

     - [Teardown] ensures that Take Screenshot On Failure runs after the test, regardless of pass/fail.
     - Run Keyword If Test Failed executes the screenshot only if the test fails.
     - ${TEST NAME} dynamically includes the test name in the screenshot file name.

With this setup, screenshots are captured only for failed tests, keeping results folder clean.
 

Related Tutorials