如何在RobotFramework的Report.html中显示变量值(使用RIDE)
Hey there! I see you're working with RIDE and want to show variable values in your Robot Framework test reports—this is such a handy trick for validating test data and debugging. Let me share a few simple, effective ways to do this:
1. Use the Log Keyword (Basic & Direct)
The most straightforward method is using the built-in Log keyword. By default, messages logged at INFO level or higher will appear in your Report.html.
Here's an example you can try in RIDE:
*** Test Cases *** Display Single Variable ${greeting} Set Variable Hello from RIDE! Log The greeting variable holds: ${greeting} INFO console=yes
- The
INFOlevel ensures the message is included in the report. - Adding
console=yeswill also print the variable to the console, which is helpful for real-time checks.
2. Show Multiple Variables with Log Many
If you need to display several variables at once, Log Many lets you list them out, and each will appear on a separate line in the report:
*** Test Cases *** Display Multiple Variables ${fruit1} Set Variable Cherry ${fruit2} Set Variable Date ${fruit3} Set Variable Elderberry Log Many Fruit 1: ${fruit1} Fruit 2: ${fruit2} Fruit 3: ${fruit3}
3. Highlight Variables with HTML Formatting
To make variable values stand out in the report, you can use HTML tags with the html=True parameter in the Log keyword:
*** Test Cases *** Highlight Variable Value ${user_session_id} Set Variable SESS-98765 Log <span style="color:blue; font-weight:bold;">Active Session ID:</span> ${user_session_id} INFO html=True
This will render the text in bold blue, making the variable easy to spot at a glance.
4. Adjust Log Level (If Needed)
If your variable logs aren't showing up, double-check the log level. Robot Framework defaults to INFO, but you can lower it to DEBUG to capture more detailed data:
*** Test Cases *** Set Debug Log Level Set Log Level DEBUG ${debug_var} Set Variable Debugging details here Log Debug variable: ${debug_var} DEBUG
Now even DEBUG-level messages will appear in your report.
All these methods work seamlessly in RIDE—just write the keywords in your test cases, run the suite, and open the generated Report.html to see your variables displayed clearly!
内容的提问来源于stack exchange,提问作者Shraddha V. Patkar

