Robot Framework:如何将控制台输出重定向到文件

时间:2016-04-28 10:41:42

标签: python robotframework

我想知道是否可以将Robot Framework的stdout从控制台重定向到文件?目前,当我运行pybot时,输出是在命令提示符下(对于Windows),我可以更改它以便它将转到文件吗? (命令提示符下没有显示任何内容)。

4 个答案:

答案 0 :(得分:1)

除了@Bryan的建议外,如果要将输出(xml,日志,报告)重定向到特定目录或文件,可以使用pybot脚本的以下选项:

-d --outputdir dir       Where to create output files. The default is the
                      directory where tests are run from and the given path
                      is considered relative to that unless it is absolute.
-o --output file         XML output file. Given path, similarly as paths given
                      to --log, --report, --xunit, and --debugfile, is
                      relative to --outputdir unless given as an absolute
                      path. Other output files are created based on XML
                      output files after the test execution and XML outputs
                      can also be further processed with Rebot tool. Can be
                      disabled by giving a special value `NONE`. In this
                      case, also log and report are automatically disabled.
                      Default: output.xml
-l --log file            HTML log file. Can be disabled by giving a special
                      value `NONE`. Default: log.html
                      Examples: `--log mylog.html`, `-l NONE`
-r --report file         HTML report file. Can be disabled with `NONE`
                      similarly as --log. Default: report.html

答案 1 :(得分:1)

也许您只想将其记录到您的控制台(如果是Jenkins):

*** Keywords ***
Log To Current Console
    [Arguments]  ${TO_LOG}
    Log To Console  \n\n${TO_LOG}

或者有时检查机器人测试的调试很好:

-b --debugfile file      Debug file written during execution. Not created
                         unless this option is specified.

答案 2 :(得分:0)

在Linux服务器上,您只需将机器人命令行传送到tee

即可
robot -d results <test name>.robot  | tee <test name>.out

答案 3 :(得分:0)

如果从代码运行,则可以执行类似

的操作
import robot.run
with open("message_out.log", "w") as log_file_out, open("message_err.log", "w") as log_file_err:
    robot.run("test",
               stdout=log_file_out,
               stderr=log_file_err)