Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable run on failure keyword #43

Merged
merged 2 commits into from
Dec 3, 2021

Conversation

robinmatz
Copy link
Collaborator

Hi there,

this PR is one possible solution for issue 42.

The standard procedure for running on failure in other libraries is to have your library class, in our case Mainframe3270, inherit from DynamicCore.

By overwriting DynamicCore's run_keyword function, we can take control of keyword execution by surrounding BuiltIn's run_keyword function in a try -> catch routine

def run_keyword(self, name, args, kwargs=None):
        try:
            return DynamicCore.run_keyword(self, name, args, kwargs)
        except Exception:
            self.run_on_failure()
            raise

As you can see, in the exception part, we run our own defined routine and then raise the final error.

Working with DynamicCore has one downside, which is that the main library has to have this structure:

"""Main library."""

from robotlibcore import DynamicCore

from mystuff import Library1, Library2


class MyLibrary(DynamicCore):
    """General library documentation."""

    def __init__(self):
        libraries = [Library1(), Library2()]
        DynamicCore.__init__(self, libraries)

    @keyword
    def keyword_in_main(self):
        pass

Also, library keywords must be annotated with @keyword,
see

This explains why I moved the description, as well as import arguments into __init__.py.

I understand that this is quite the change to the project structure. However, I also feel this a very useful feature supported out of the box by most popular GUI automation frameworks.

You can check the feature by running the new test cases under tests/run_on_failure/

grafik

@samuelpcabral samuelpcabral merged commit 63a5d55 into MarketSquare:master Dec 3, 2021
@github-actions github-actions bot mentioned this pull request Mar 14, 2022
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