我正在Robot框架中为我的测试套件编写一个侦听器,将我的输出文件移动到基于测试设备ID嵌入其中的唯一ID的目录中。实际上,我受到this answer的启发,决定亲自尝试:
class OutputFilesListener(object):
ROBOT_LISTENER_API_VERSION = 3
def __init__(self):
self.output = ""
self.log = ""
self.report = ""
self.unique_id = ""
def end_suite(self, data, result):
# I would like to get data.resource.variables to read global variable I set in one of the test cases based on some output
print(data.resource.variables) # called properly, prints []
print(data.resource.keywords) # called properly, prints [<robot.running.model.UserKeyword object at 0x7f88157e7978>, <robot.running.model.UserKeyword object at 0x7f88157d80f0>, <robot.running.model.UserKeyword object at 0x7f88157d8160>] - makes sense
def output_file(self, path):
self.output = path
def log_file(self, path):
self.log = path
def report_file(self, path):
self.report = path
def close(self):
print("{} {} {}".format(self.output, self.log, self.report))
if self.log and self.report and self.output:
print("All are there!") # This is fine - so in general values are properly passed
所以看起来,传入data.resource.variables
到end_suite(...)
方法的变量是。。。嗯,空的。我只检查了data.resource.keywords
,似乎没有什么-所以有一些东西是正确填充的。另外,我已经检查了我设置的变量是否是可用的,并且它被正确地记录在不同的测试用例中。在
我的侦听器代码有什么问题吗?或者我应该在应用程序的其他部分查找问题?在
仅供参考,这是一行应该设置全局变量,并且它可以正常工作:
^{pr2}$
您似乎在问如何获得变量
${uniqueBoardid}
的值。不能通过.resource
属性来实现。在这种情况下,这个属性是无用的。它引用该套件的*** Variables ***
表。在您可以通过运行内置库中的
get_variable_value
方法来获得变量的值。在例如:
相关问题 更多 >
编程相关推荐