0

I have a custom keyword in the robot framework which counts the items of a list. This works already in my underlying python file and prints the number 5 when five elements exists in a list.

Then I want to bring this value to the robot framework. But instead of a number I get: ${N_groups} is <built-in method count of list object at 0x03B01D78>

The code of the robot file:

*** Test Cases ***
Count Groups
    ${N_groups}    Setup Groups Count Groups
    log to console    ${N_groups}

How to get item-count of the list as an integer value?

Here is a part of my python file:

@keyword(name="Count Groups")
def count_groups(self):
    N = self.cur_page.count_groups()
    return N

And a more low level python file:

        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
1
  • 1
    What are you expecting to happen when you return children_text.count? What do you think .count represents? Commented Jan 27, 2016 at 14:33

1 Answer 1

2

Your function count_groups is returning children_text.count. children_text is a list, and you're returning the count method of that object, which explains the error that you're seeing. It's no different than if you did something like return [1,2,3].count.

Perhaps you intend to actually call the count function and return the results? Or, perhaps you are intending to return the length of the list? It's hard to see what the intent of the code is.

In either case, robot is reporting exactly what you're doing: you're returning a reference to a function, not an integer. My guess is that what you really want to do is return the number of items in the list, in which case you should change the return statement to:

return len(children_text)
Sign up to request clarification or add additional context in comments.

2 Comments

Hello Bryan, sorry for not being precise. I want to get the length of the list
@kame: in that case, I guessed right. You need to do return len(children_text)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.