为了支持另一种日志格式,我开始开发 自定义 Robotframework 侦听器.使用指南中的示例,我已经能够复制简单的 PythonListner 示例.这个例子可以成功运行:
In order to support an alternative logging format I've started the development of a custom Robotframework Listener. Using the examples in the guide I've been able to replicate the simple PythonListner example. This example can be succesfully run using:
python.exe -m robot.run --listener C:\temp\tiny.py -s Test02.Test C:\temp\Test02由侦听器类生成的文件包含已发生的不同事件,并且功能正常工作.
The by the listener class generated file contains the different events that have occurred and the functionality is working as it should.
在类的 __init__ 方法中添加以下行时:
When adding the following line to the __init__ method of the class:
BuiltIn().get_variable_value('${SUITE SOURCE}')收到以下回复:
failed: Creating instance failed: RobotNotRunningError: Cannot access execution context Traceback (most recent call last): File "C:\temp\tiny.py", line 9, in __init__ print repr(BuiltIn().get_variables()) File "C:\Python27\lib\site-packages\robot\libraries\BuiltIn.py", line 940, in get_variables return utils.NormalizedDict(self._variables.current, ignore='_') File "C:\Python27\lib\site-packages\robot\libraries\BuiltIn.py", line 2669, in _variables return self._namespace.variables File "C:\Python27\lib\site-packages\robot\libraries\BuiltIn.py", line 2661, in _namespace return self._context.namespace File "C:\Python27\lib\site-packages\robot\libraries\BuiltIn.py", line 2656, in _context raise RobotNotRunningError('Cannot access execution context') ============================================================================== Test02 ============================================================================== Test02.Test ============================================================================== Process Data File | PASS | ------------------------------------------------------------------------------ Test02.Test | PASS | 1 critical test, 1 passed, 0 failed 1 test total, 1 passed, 0 failed ============================================================================== Test02 | PASS | 1 critical test, 1 passed, 0 failed 1 test total, 1 passed, 0 failed ============================================================================== Output: C:\temp\output.xml Log: C:\temp\log.html Report: C:\temp\report.html测试通过,但未生成文件.此结果已在 Python 2.7 和 Robotframework 3.0 和 2.8.5 上复制.这很奇怪,我需要一些帮助来进一步分析或(理想情况下)解决这个问题.
The test passes but the file is not generated. This result has been replicated on Python 2.7 and Robotframework 3.0 and 2.8.5. It is odd and I need some help to further analyse or (ideally) solve this problem.
由于 Python 类是由 Robotframework 调用的,我不确定如何继续调试它,因此也请随时提出建议.无论如何,我被卡住了,可以使用你的帮助.
Since the Python class is called by Robotframework I'm unsure how to continue debugging this, so feel free to make suggestions there as well. In any case I'm stuck and could use your help.
推荐答案您正在尝试在测试开始之前引用 BuiltIn().这就是错误 Cannot access execution context 的含义:测试尚未开始,因此没有执行上下文.简而言之,在测试运行之前,您无法访问 BuiltIn 库的方法.
You are trying to reference BuiltIn() before the test starts. That is what is meant by the error Cannot access execution context: the test hasn't started so there is no execution context. Simply put, you cannot access methods of the BuiltIn library before the test runs.
您必须等到测试开始运行后才能调用该语句.
You will have to wait to call that statement until after the test has started running.
例如:
class listener: ROBOT_LISTENER_API_VERSION = 2 def start_suite(self, name, attrs): self.suite_source = BuiltIn().get_variable_value('${SUITE SOURCE}')但是,如果您只需要当前套件的来源,那么该信息可在侦听器方法 start_suite 中获得.
However, if all you need is the source of the current suite, that information is available in the listener method start_suite.
例如:
class MyListener: ROBOT_LISTENER_API_VERSION = 2 def start_suite(self, name, attrs): self.suite_source = attrs["source"]更多推荐
Robotframework Listener 抛出“无法访问执行上下文";错误
发布评论