想要在robotframework里使用彩色的log
实际效果
注意:在vs code里白色只会在深色背景的主题下显示为白色,浅色主题都是灰色
也可以在终端输出彩色字符
实现代码
*** Variables ***
${BLACK} "\\033[30m"
${RED} "\\033[31m"
${GREEN} "\\033[32m"
${YELLOW} "\\033[33m"
${BLUE} "\\033[34m"
${PINK} "\\033[35m"
${WHITE} "\\033[37m"
必须在suite/testcase前置中运行该模块
如果改成testcase前置就把 set suite variable改成testcase variable
Initialize Colors
${black}= Evaluate ${BLACK}
Set Suite Variable ${black}
${red}= Evaluate ${RED}
Set Suite Variable ${red}
${green}= Evaluate ${GREEN}
Set Suite Variable ${green}
# More colors...
${yellow}= Evaluate ${YELLOW}
Set Suite Variable ${yellow}
${blue}= Evaluate ${BLUE}
Set Suite Variable ${blue}
${pink}= Evaluate ${PINK}
Set Suite Variable ${pink}
${white}= Evaluate ${WHITE}
Set Suite Variable ${white}
testcase
testcolor
Log To Console ${red}red
Log To Console ${black}black
Log To Console ${blue}blue
Log To Console ${yellow}yellow
Log To Console ${pink}pink
Log To Console ${white}white
Log/Log to console都可以