[英]Integer variable from a custom keyword in the robot framework
我在机器人框架中有一个自定义关键字,用于计算列表中的项目。 这已经在我的基础python文件中工作了,并且当列表中存在五个元素时,打印数字5。
然后,我想将此值带入机器人框架。 但是我得到的不是数字: ${N_groups}
是<built-in method count of list object at 0x03B01D78>
机械手文件的代码:
*** Test Cases ***
Count Groups
${N_groups} Setup Groups Count Groups
log to console ${N_groups}
如何获取列表的项目计数为整数值?
这是我的python文件的一部分:
@keyword(name="Count Groups")
def count_groups(self):
N = self.cur_page.count_groups()
return N
还有一个更底层的python文件:
def count_groups(self):
ele_tc = self._wait_for_treecontainer_loaded(self._ef.get_setup_groups_treecontainer())
children_text = self._get_sublist_filter(ele_tc, lambda ele: ele.find_element_by_tag_name('a').text,
True)
return children_text.count
您的功能count_groups
返回的是children_text.count
。 children_text
是一个列表,您将返回该对象的count
方法,这说明了您所看到的错误。 这与您执行return [1,2,3].count
类的操作没有什么不同。
也许您打算实际调用 count
函数并返回结果? 或者,也许您打算返回列表的长度? 很难看到代码的意图是什么。
在这两种情况下,robot都会准确地报告您的工作:您返回的是对函数的引用, 而不是整数。 我的猜测是,您真正想要做的是返回列表中的项目数,在这种情况下,您应该将return语句更改为:
return len(children_text)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.