Robot Framework logging full traceback of errors and exceptions
I prefer having a full traceback of an error in case of a failing Robot Framework test case. But by default Robot Framework only shows the message of an exception. You get to know the failing keyword but no details about the underlying python code which threw the exception. You can retrieve this information either by changing the log level or via a custom Robot Framework Listener. In this article I will explain both approaches.
Changing log level to debug or below
Robot Framework will log the full traceback in case you set the log level to TRACE
or DEBUG
set log levels as described here in the Robot Framework user guide
in case you use RobotCode you can configure the log level via a
robot.toml
filerobot.toml# https://robotcode.io/02_get_started/configuration # Basic settings output-dir = "output" # log-level = "NONE" log-level = "INFO" # log-level DEBUG (or TRACE) would show full traceback # as debug level by default # log-level = "DEBUG" # log-level = "TRACE"
Robot Framework Listener which logs traceback
Alternatively you can create a custom Robot Framework Listener that will log the full traceback as error in case a keyword fails.
This way you can keep the over all log level at info or above.
I explain Robot Framework listeners with more detail in this other article about structured logging for Robot Framework.
Listener implementation
You can find the complete code in my git repository python-ideas (links to fixed commit).
Robot Framework provides a method which returns the error message and full traceback of the last occurred exception (see Robot Framework docs: robot.utils.error).
You can this method as shown in the following code block:
|
|
Run test case with listener
As described in the other article about the StructlogListener you have to add the ExceptionTracebackListener
as robot
cli argument (--listener
) or via robot.toml
file that is used by the RobotCode vscode extension:
|
|
Check traceback in logs
Check the Robot Framework log.html
file.
It will contain your custom traceback log messages with the defined log levels.