Mat*_*u.P 3 colors robotframework
我想在RobotFramework的控制台输出中添加一些颜色.
我尝试使用控制台颜色代码,如:
${message}=  Set Variable  hello world!
Log To Console  \\e[0;36;49m${message}\\e[0;39;49m
(在linux控制台中,以青色echo -e "\e[0;36;49mHello world!\e[0;39;49m"打印Hello world!)
(我也试过一个\也是\033[31m, \033[0m, ...代码)
但它不起作用......
那么,是否可以做以下事情:
${message}=  Set Variable  hello world!
Log To Console ${message.red}
我找到了这个模块,但我没有找到任何关于如何使用它:(
我试过了:
Log To Console ${message.red}  robot.output.console.highlighting
和
${message}=  Evaluate  ${message}.red  robot.output.console.highlighting
Log To Console ${message}
但没有一个有效:'(
由于Robot框架对'\'的解释,Log To Console  \\033[31mRed Text\\033[0m不会对输出进行着色.
要解决此问题,您必须Evaluate先登录变量才能登录到控制台:
${message}=  Evaluate  "\\033[31mRed Text\\033[0m"
Log To Console  ${message}
我最终得到了以下解决方案,我发现它非常"干净":
*** Variables ***
${BLACK}  "\\033[30m"
${RED}    "\\033[31m"
# More colors ANSI codes...
*** Keywords ***
Initialize Colors
  ${black}=  Evaluate  ${BLACK}
  Set Test Variable  ${black}
  ${red}=  Evaluate  ${RED}
  Set Test Variable  ${red}
  # More colors...
然后,您只需在套件/测试用例设置中使用上一个关键字,您就可以将输出着色,如下所示:
Log To Console  ${cyan}Some Text in cyan and a ${red}${variable}${cyan} in red${default}