尝试为机器人框架实现侦听器接口,以便收集有关关键字执行的信息,例如执行时间,通过/失败状态,以及状态失败时的失败消息 . 示例代码如下

import os.path
import tempfile

class PythonListener:
    ROBOT_LISTENER_API_VERSION = 2
    ROBOT_LIBRARY_SCOPE = 'GLOBAL'

    def __init__(self, filename='listen.txt'):
        outpath = os.path.join(tempfile.gettempdir(), filename)
        self.outfile = open(outpath, 'w')

    def end_keyword(self, name, attrs):
       self.outfile.write(name + "\n")
       self.outfile.write(str(attrs) + "\n")

    def close(self):
       self.outfile.close()

除了关键字失败消息之外的所有信息都可以在从机器人框架传递给end_test方法的属性中获得 .

文档可以在这里找到 . https://github.com/robotframework/robotframework/blob/master/doc/userguide/src/ExtendingRobotFramework/ListenerInterface.rst#id36

end_test()方法的属性中提供了失败消息 . 但是如果使用RunKeywordAndIgnoreError运行关键字,则不会有这些信息 .

我可以看到机器人框架中有一个特殊的变量$ ,其中包含当前关键字的可能错误消息是否可以在侦听器类中访问此变量 . https://github.com/robotframework/robotframework/blob/master/doc/userguide/src/CreatingTestData/Variables.rst#automatic-variables

是否有其他方法可以在每个关键字的末尾收集失败消息信息?