How do you debug Robot Framework scripts?

Debugging Robot Framework Scripts

Debugging in Robot Framework is essential to identify issues in test cases. Here are several methods to debug and troubleshoot your scripts effectively:


1. Enable Debug Logs
(Increase Log Level)

Set the log level to DEBUG to get detailed logs in the output.

Run the test with DEBUG logs :
robot --loglevel DEBUG my_test.robot
  • This provides detailed execution steps, making it easier to trace failures.

2. Use Built-in Logging

Robot Framework provides logging functions to print information during test execution.

Example :
*** 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.

3. Use Run Keyword And Continue On Failure

This allows the script to continue even if a step fails, helping you gather more information.

Example :
Run Keyword And Continue On Failure    Click Element    //button[@id='submit']
  • This prevents stopping execution on failures.

4. Capture Screenshots on Failure

For UI tests, capture a screenshot on failure.

SeleniumLibrary does this automatically, but you can also use:

Capture Page Screenshot
  • The screenshot is stored in the logs folder for debugging.

5. Debug with Pause Execution
(Interactive Debugging)

You can pause execution and manually inspect variables.

Example :
Pause Execution
  • The script pauses and waits for user input before proceeding.

6. Print Variable Values (Log Variables)

To check variable values at runtime:

Log Variables
  • Displays all available variables at that moment.

7. Run Tests in Dry-Run Mode

Dry-run mode helps check for syntax errors without executing the test.

Run in dry-run mode :
robot --dryrun my_test.robot
  • This ensures test cases are syntax-correct before execution.

8. Debug Using Pdb (Python Debugger)

If you are using Python custom libraries, insert Python’s pdb debugger in your code.

Example (in Python Library file) :
import pdb
pdb.set_trace()  # This pauses execution for debugging
  • This allows step-by-step debugging for custom Python functions.

9. Use Breakpoints for Step-by-Step Execution

You can simulate breakpoints using:

Input Text    username_field    my_username
Sleep    5s   # Simulating a wait to manually inspect
  • Adding Sleep allows you to check the browser state before proceeding.

Summary Table
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