Skip to content

Adds possibility to define get matching xpath count kw return type#735

Merged
aaltat merged 2 commits intorobotframework:masterfrom
aaltat:fix_get_matching_xpath_count_return_type
Jan 24, 2017
Merged

Adds possibility to define get matching xpath count kw return type#735
aaltat merged 2 commits intorobotframework:masterfrom
aaltat:fix_get_matching_xpath_count_return_type

Conversation

@aaltat
Copy link
Contributor

@aaltat aaltat commented Jan 22, 2017

Fixes #715

def get_matching_xpath_count(self, xpath, return_str=True):
"""Returns number of elements matching `xpath`

The default return type is `str`but it can changed to `int` by setting

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing space after `str`

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, I will fix it.

"""
count = len(self._element_find("xpath=" + xpath, False, False))
return str(count)
return str(count) if return_str else count

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO we should follow DateTime's lead and use a util method to make sure that str('false') is treated as False, etc.

from robot.utils import is_truthy
...
return str(count) if is_truthy(return_str) else count

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, but would like to do it same time for all the keywords using booleans. There is #719 for this problem.

Should Be Equal ${count} 19
Should Be String ${count}
${count}= Get Matching XPath Count //a ${False}
Should Be Equal As Numbers ${count} 19

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can just do a direct comparison to an int here...

Should Be Equal    ${count}    ${19}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I will fix it.

@aaltat aaltat merged commit ad5f63f into robotframework:master Jan 24, 2017
@aaltat aaltat deleted the fix_get_matching_xpath_count_return_type branch January 24, 2017 22:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants