Skip to content
This repository was archived by the owner on Nov 23, 2023. It is now read-only.

Commit 525847c

Browse files
committed
feat: First core functionalities setup
1 parent aa5e7bb commit 525847c

File tree

5 files changed

+97
-0
lines changed

5 files changed

+97
-0
lines changed

AppiumFlutterLibrary/__init__.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# -*- coding: utf-8 -*-
2+
3+
from AppiumFlutterLibrary.keywords import *
4+
from AppiumFlutterLibrary.version import VERSION
5+
6+
__version__ = VERSION
7+
8+
class AppiumFlutterLibrary(
9+
_RunOnFailureKeyWords,
10+
_ApplicationManagementKeyWords
11+
):
12+
ROBOT_LIBRARY_SCOPE = 'GLOBAL'
13+
ROBOT_LIBRARY_VERSION = VERSION
14+
15+
def __init__(self, timeout=5, run_on_failure='Capture Page Screenshot'):
16+
for base in AppiumFlutterLibrary.__bases__:
17+
base.__init__(self)
18+
self.set_appium_timeout(timeout)
19+
self.register_keyword_to_run_on_failure(run_on_failure)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from ._applicationmanagement import _ApplicationManagementKeyWords
2+
from ._runonfailure import _RunOnFailureKeyWords
3+
4+
__all__ = [
5+
"_ApplicationManagementKeyWords",
6+
"_RunOnFailureKeyWords"]
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# -*- coding: utf-8 -*-
2+
3+
import robot
4+
5+
from AppiumFlutterLibrary.keywords.keywordgroup import KeywordGroup
6+
7+
class _ApplicationManagementKeyWords(KeywordGroup):
8+
def __init_(self):
9+
self._timeout_in_secs = float(5)
10+
11+
def set_appium_timeout(self, seconds):
12+
old_timeout = self.get_appium_timeout()
13+
self._timeout_in_secs = robot.utils.timestr_to_secs(seconds)
14+
return old_timeout
15+
16+
def get_appium_timeout(self):
17+
"""Gets the timeout in seconds that is used by various keywords.
18+
19+
See `Set Appium Timeout` for an explanation."""
20+
return robot.utils.secs_to_timestr(self._timeout_in_secs)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# -*- coding: utf-8 -*-
2+
3+
from AppiumFlutterLibrary.keywords.keywordgroup import KeywordGroup
4+
5+
6+
class _RunOnFailureKeyWords(KeywordGroup):
7+
def __init__(self):
8+
self._run_on_failure_keyword = None
9+
self._running_on_failure_routine = None
10+
11+
def register_keyword_to_run_on_failure(self, keyword):
12+
old_keyword = self._run_on_failure_keyword
13+
old_keyword_text = old_keyword if old_keyword is not None else "Nothing"
14+
15+
new_keyword = keyword if keyword.strip().lower() != "nothing" else "Nothing"
16+
new_keyword_text = new_keyword if new_keyword is not None else "Nothing"
17+
18+
self._run_on_failure_keyword = new_keyword
19+
self._info('%s will be run on failure.' % new_keyword_text)
20+
21+
return old_keyword
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# -*- coding: utf-8 -*-
2+
3+
import sys
4+
import inspect
5+
from six import with_metaclass
6+
try:
7+
from decorator import decorator
8+
except SyntaxError: # decorator module requires Python/Jython 2.4+
9+
decorator = None
10+
if sys.platform == 'cli':
11+
decorator = None # decorator module doesn't work with IronPython 2.6
12+
13+
def _run_on_failure_decorator(method, *args, **kwargs):
14+
try:
15+
return method(*args, **kwargs)
16+
except Exception as err:
17+
self = args[0]
18+
if hasattr(self, '_run_on_failure'):
19+
self._run_on_failure()
20+
raise err
21+
22+
class KeywordGroupMetaClass(type):
23+
def __new__(cls, clsname, bases, dict):
24+
if decorator:
25+
for name, method in dict.items():
26+
if not name.startswith('_') and inspect.isroutine(method):
27+
dict[name] = decorator(_run_on_failure_decorator, method)
28+
return type.__new__(cls, clsname, bases, dict)
29+
30+
class KeywordGroup(with_metaclass(KeywordGroupMetaClass, object)):
31+
pass

0 commit comments

Comments
 (0)