【问题标题】:Integer variable from a custom keyword in the robot framework机器人框架中自定义关键字的整数变量
【发布时间】:2016-01-27 22:42:31
【问题描述】:

我在机器人框架中有一个自定义关键字,用于计算列表中的项目。这已经在我的底层 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

【问题讨论】:

  • 当您返回children_text.count 时,您期望发生什么?你认为.count 代表什么?

标签: variables selenium robotframework


【解决方案1】:

您的函数count_groups 正在返回children_text.countchildren_text 是一个列表,您正在返回该对象的 count 方法,这解释了您所看到的错误。这与您执行return [1,2,3].count 之类的操作没有什么不同。

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

在任何一种情况下,机器人都会准确地报告您在做什么:您返回的是对函数的引用,不是一个整数。我的猜测是,您真正想要做的是返回列表中的项目数,在这种情况下,您应该将 return 语句更改为:

return len(children_text)

【讨论】:

  • 你好 Bryan,抱歉不准确。我想得到列表的长度
  • @kame:在那种情况下,我猜对了。你需要做return len(children_text)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-11-08
  • 2018-08-01
  • 2020-04-21
  • 2020-08-30
  • 2020-11-06
  • 2015-10-14
  • 2019-06-11
相关资源
最近更新 更多