来自机器人框架中自定义关键字的整数变量

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 正在 returning children_text.countchildren_text 是一个列表,您正在 return 该对象的 count 方法,它解释了您看到的错误。这与您执行类似 return [1,2,3].count 的操作没有什么不同。

也许您打算实际 调用 count 函数和 return 结果?或者,也许您打算 return 列表的长度?很难看出代码的意图。

在任何一种情况下,robot 都会准确报告您的操作:您return正在引用一个函数,不是一个整数。我的猜测是你真正想要做的是 return 列表中的项目数,在这种情况下你应该将 return 语句更改为:

return len(children_text)