Robotframework 测试执行后,如何在Robot framework日志文件中记录命令输出?

Robotframework 测试执行后,如何在Robot framework日志文件中记录命令输出?,robotframework,Robotframework,在Robot Framework log.html中,我想记录从python文件执行的命令输出。如所附的log.html屏幕截图所示,现在我无法看到命令输出。简单,它打印或记录为PASS 我的机器人文件: *** Settings *** Library test *** Test cases *** check test Python关键字: def test(): cmd = ' net test" ' output = os.popen(cmd

在Robot Framework log.html中,我想记录从python文件执行的命令输出。如所附的log.html屏幕截图所示,现在我无法看到命令输出。简单,它打印或记录为PASS

我的机器人文件:

*** Settings ***
Library         test


*** Test cases ***
check
    test
Python关键字:

def test():
    cmd = ' net test" '
    output = os.popen(cmd).read()
    match1 = re.findall('.* (successfully).*',output)
    mat1 = ['successfully']
    if match1 == mat1:
        print "PASS::"
有谁能给我指点一下吗


如果希望命令的输出显示在日志中,有三种方法:使用print语句、使用logging API或使用内置的log关键字。这些方法都记录在文档中

在这三种方法中,日志API可以说是最好的选择

使用打印语句 您已经在使用此方法。这在《用户指南》中的一节中有记录,该节名为:

。。。方法还可以将消息发送到日志 只需将文件写入标准输出流(stdout)或 标准错误流(stderr)

例如:

def test():
    cmd = ' net test" '
    output = os.popen(cmd).read()
    match1 = re.findall('.* (successfully).*',output)
    mat1 = ['successfully']
    if match1 == mat1:
        print "output: " + output
from robot.api import logger
def test():
    ...
    logger.info("output: " + output)
from robot.libraries import BuiltIn
...
def test():
    ...
    BuiltIn().log("this is a debug message", "DEBUG")
使用日志API 有一个用于日志记录的公共API,也记录在用户指南中 在名为:

Robot框架有一个基于Python的日志API,用于将消息写入 将日志文件和文件发送到控制台。测试库可以像这样使用此API info(“我的消息”),而不是通过标准 输出如打印“信息我的消息”。除了程序性的 接口使用起来更干净,这个API有一个好处 日志消息具有准确的时间戳

例如:

def test():
    cmd = ' net test" '
    output = os.popen(cmd).read()
    match1 = re.findall('.* (successfully).*',output)
    mat1 = ['successfully']
    if match1 == mat1:
        print "output: " + output
from robot.api import logger
def test():
    ...
    logger.info("output: " + output)
from robot.libraries import BuiltIn
...
def test():
    ...
    BuiltIn().log("this is a debug message", "DEBUG")
使用内置的Log关键字 最后,您还可以使用内置关键字。《用户指南》中标题为“使用内置关键字”的部分介绍了如何使用这些关键字

用Python实现的测试库可以使用Robot框架的 例如,用于获取有关已执行的 测试和使用的设置。这个强大的机制 但是,与框架的通信应谨慎使用, 因为所有Robot框架的API都不是由 它们可能在不同的框架之间发生根本性的变化 版本

例如:

def test():
    cmd = ' net test" '
    output = os.popen(cmd).read()
    match1 = re.findall('.* (successfully).*',output)
    mat1 = ['successfully']
    if match1 == mat1:
        print "output: " + output
from robot.api import logger
def test():
    ...
    logger.info("output: " + output)
from robot.libraries import BuiltIn
...
def test():
    ...
    BuiltIn().log("this is a debug message", "DEBUG")