I would like to put some colors in the console output of RobotFramework.
I tried to use the console color codes like:
${message}= Set Variable hello world!
Log To Console \\e[0;36;49m${message}\\e[0;39;49m
(In a linux console, echo -e "\e[0;36;49mHello world!\e[0;39;49m"
print Hello world!
in cyan)
(I also tried with one \
and also \033[31m, \033[0m, ...
codes)
But it doesn't work...
So, is it possible to do something like:
${message}= Set Variable hello world!
Log To Console ${message.red}
I found this module but I didn't found anything on how to use it :(
I tried:
Log To Console ${message.red} robot.output.console.highlighting
and
${message}= Evaluate ${message}.red robot.output.console.highlighting
Log To Console ${message}
But none works :'(
Because of Robot Framework interpretation of '\', Log To Console \\033[31mRed Text\\033[0m
doesn't color the output.
To solve this problem, you have to Evaluate
the variable before to log in to console:
${message}= Evaluate "\\033[31mRed Text\\033[0m"
Log To Console ${message}
I ended up with the below solution, which I find quite "clean":
*** 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...
Then, you just have to use the previous keyword in a Suite/Test Case Setup and you can colorize your outputs like below:
Log To Console ${cyan}Some Text in cyan and a ${red}${variable}${cyan} in red${default}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With