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.
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
3. Logging Variables and Responses
Variables can be logged to understand runtime behavior:
4. Taking Screenshots
Screenshots are useful for UI testing or debugging failed steps.
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:
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.