为了支持其他日志记录格式,我开始开发自定义Robotframework Listener。使用指南中的示例,我已经能够复制简单的PythonListner示例。可以使用以下示例成功运行此示例:
python.exe -m robot.run --listener C:\temp\tiny.py -s Test02.Test C:\temp\Test02
由listener类生成的文件包含已发生的不同事件,并且该功能按预期运行。
将以下行添加到__init__
类的方法时:
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上复制。这很奇怪,我需要一些帮助来进一步分析或(理想地)解决此问题。
由于Python类是由Robotframework调用的,所以我不确定如何继续调试它,因此也可以在那里提出建议。无论如何,我都会遇到麻烦,可以使用您的帮助。
您正在尝试BuiltIn()
在测试开始之前参考。这就是错误的含义Cannot access execution context
:测试尚未开始,因此没有执行上下文。简而言之,您无法BuiltIn
在测试运行之前访问库的方法。
测试开始运行之前,您将必须等待调用该语句。
例如:
class listener:
ROBOT_LISTENER_API_VERSION = 2
def start_suite(self, name, attrs):
self.suite_source = BuiltIn().get_variable_value('${SUITE SOURCE}')
但是,如果您仅需要当前套件的来源,则该信息可在listener方法中找到start_suite
。
例如:
class MyListener:
ROBOT_LISTENER_API_VERSION = 2
def start_suite(self, name, attrs):
self.suite_source = attrs["source"]
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句