Debugging in Robot Framework is essential to identify issues in test cases. Here are several methods to debug and troubleshoot your scripts effectively:
Set the log level to DEBUG to get detailed logs in the output.
robot --loglevel DEBUG my_test.robot
Robot Framework provides logging functions to print information during test execution.
*** Test Cases ***
Debugging Example
Log This is a normal log message
Log To Console This message appears in the terminal
Log Variable value: ${my_variable} level=DEBUG
Log → Adds messages to the log file.Log To Console → Prints messages directly in the console.Run Keyword And Continue On FailureThis allows the script to continue even if a step fails, helping you gather more information.
Run Keyword And Continue On Failure Click Element //button[@id='submit']
For UI tests, capture a screenshot on failure.
SeleniumLibrary does this automatically, but you can also use:
Capture Page Screenshot
Pause Execution (Interactive Debugging)You can pause execution and manually inspect variables.
Pause Execution
Log Variables)To check variable values at runtime:
Log Variables
Dry-run mode helps check for syntax errors without executing the test.
robot --dryrun my_test.robot
If you are using Python custom libraries, insert Python’s pdb debugger in your code.
import pdb
pdb.set_trace() # This pauses execution for debugging
Breakpoints for Step-by-Step ExecutionYou can simulate breakpoints using:
Input Text username_field my_username
Sleep 5s # Simulating a wait to manually inspect
Sleep allows you to check the browser state before proceeding.| Debugging Method | Description |
|---|---|
--loglevel DEBUG |
Enables detailed logs |
Log & Log To Console |
Prints messages for debugging |
Pause Execution |
Pauses test execution for manual inspection |
Capture Page Screenshot |
Captures screenshots for UI debugging |
Log Variables |
Displays all variables at a point |
--dryrun |
Checks for syntax errors before running tests |
pdb.set_trace() |
Debugs Python libraries step by step |