Fogarasi Norbert
Fogarasi Norbert

Reputation: 672

Using Bultin's library "Wait Until Keyword Succeeds" with custom keyword

I am writing a custom Robot Framework library in Python. I want to wait for a custom keyword until succeeds, but I don't know how to call it properly with custom keyword, I'm currently getting this error: keyword '_element_should_not_have_class_name' failed after retrying for 30 seconds. The last error was: No keyword with name '_element_should_not_have_class_name' found.

My custom keyword looks like this:

def _element_should_not_have_class_name(self, element_locator, class_name):
    self.logger.console('Begin')
    classes = self.appiumlib.get_element_attribute(locator=Util.get_css_locator(self.locator[element_locator]), attribute='className')
    self.logger.console('Got classes: {}'.format(classes))
    self.builtin.should_not_contain(classes, class_name)

The keyword where I want to call it until it succeeds:

def _wait_until_connection_succeeds(self, element_locator):
    self.builtin.wait_until_keyword_succeeds('0.5 min', '1 sec', '_element_should_not_have_class_name', element_locator, 'disabled')

If I write inside the parameter list as a function it runs, but only once. What could be a solution for this?

Upvotes: 0

Views: 1823

Answers (1)

Bryan Oakley
Bryan Oakley

Reputation: 385970

The error is telling you the problem, there is no keyword named _element_should_not_have_class_name. Robot doesn’t recognize functions which begin with _ as keywords. See What methods are considered keywords in the robot framework user guide.

Solution: remove the leading underscore from the function name.

Upvotes: 4

Related Questions