Robotframework Listener 抛出“无法访问执行上下文";错误

编程入门 行业动态 更新时间:2024-10-08 18:33:07
本文介绍了Robotframework Listener 抛出“无法访问执行上下文";错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

为了支持另一种日志格式,我开始开发 自定义 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 抛出“无法访问执行上下文";错误

本文发布于:2023-11-09 07:58:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1571803.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:上下文   抛出   无法访问   错误   Robotframework

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!