From 137940b8266b83239996eb9590cfa3492bb0ca1b Mon Sep 17 00:00:00 2001 From: igortavtib Date: Thu, 4 Nov 2021 11:01:06 -0300 Subject: [PATCH 1/2] feat: new application keywords --- AppiumFlutterLibrary/finder/elementfinder.py | 2 -- .../keywords/_applicationmanagement.py | 35 ++++++++++++++++--- AppiumFlutterLibrary/keywords/_element.py | 18 ++++++++-- AppiumFlutterLibrary/version.py | 2 +- setup.py | 2 +- 5 files changed, 48 insertions(+), 11 deletions(-) diff --git a/AppiumFlutterLibrary/finder/elementfinder.py b/AppiumFlutterLibrary/finder/elementfinder.py index 5b365e2..076f16f 100644 --- a/AppiumFlutterLibrary/finder/elementfinder.py +++ b/AppiumFlutterLibrary/finder/elementfinder.py @@ -36,8 +36,6 @@ def _find_by_text(self, application, element_text): return element - - def _parse_locator(self, locator): prefix = None criteria = locator diff --git a/AppiumFlutterLibrary/keywords/_applicationmanagement.py b/AppiumFlutterLibrary/keywords/_applicationmanagement.py index 88f5992..010d622 100644 --- a/AppiumFlutterLibrary/keywords/_applicationmanagement.py +++ b/AppiumFlutterLibrary/keywords/_applicationmanagement.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- import robot -import time from AppiumFlutterLibrary.utils import ApplicationCache from AppiumFlutterLibrary.keywords.keywordgroup import KeywordGroup from appium.webdriver import Remote @@ -11,16 +10,38 @@ def __init__(self): self._cache = ApplicationCache() self._timeout_in_secs = float(5) - def close_application(self): - self._cache.close() - def open_application(self, remote_url, alias =None, **kwargs): desired_caps = kwargs if desired_caps['automationName'] != 'flutter': raise ValueError("Appium Flutter Library only suports flutter automation. Try changing automationName capability to 'flutter'") + self._debug("Opening application") application = Remote(str(remote_url), desired_caps) return self._cache.register(application, alias) + def reset_application(self): + self._debug("Reseting application") + self._current_application().reset() + + def close_all_applications(self): + self._debug("Closing all applications") + self._cache.close_all() + + def close_application(self): + self._debug("Closing current apllication") + self._cache.close() + + def background_app(self, seconds=5): + self._current_application().background_app(seconds) + + def lock(self, seconds=5): + self._current_application().lock(robot.utils.timestr_to_secs(seconds)) + + def portrait(self): + self._rotate("PORTRAIT") + + def touch_id(self, match = True): + self._current_application().touch_id(match) + def set_appium_timeout(self, seconds): old_timeout = self.get_appium_timeout() self._timeout_in_secs = robot.utils.timestr_to_secs(seconds) @@ -37,4 +58,8 @@ def get_appium_timeout(self): def _current_application(self): if not self._cache.current: raise RuntimeError('No application is open') - return self._cache.current \ No newline at end of file + return self._cache.current + + def _rotate(self, orientation): + driver = self._current_application() + driver.orientation = orientation \ No newline at end of file diff --git a/AppiumFlutterLibrary/keywords/_element.py b/AppiumFlutterLibrary/keywords/_element.py index d59bb23..c8878fc 100644 --- a/AppiumFlutterLibrary/keywords/_element.py +++ b/AppiumFlutterLibrary/keywords/_element.py @@ -12,12 +12,26 @@ def __init__(self): def input_text(self, locator, text): element = self._find_element(locator) self._info("Typing text '%s' into component '%s'" % (text, locator)) - element.send_keys(text) + try: + element.send_keys(text) + except Exception as err: + raise err + + def clear_text(self, locator): + element = self._find_element(locator) + self._info("Clearing text from element '%s'" % (locator)) + try: + element.clear() + except Exception as err: + raise err def click_element(self, locator): element = self._find_element(locator) self._info("Clicking on element %s" % locator) - element.click() + try: + element.click() + except Exception as err: + raise err def element_should_be_visible(self, locator): element = self._find_element(locator) diff --git a/AppiumFlutterLibrary/version.py b/AppiumFlutterLibrary/version.py index bfa6692..e01f2f8 100644 --- a/AppiumFlutterLibrary/version.py +++ b/AppiumFlutterLibrary/version.py @@ -1,2 +1,2 @@ # -*- coding: utf-8 -*- -VERSION = '1.0.0-alpha.2' \ No newline at end of file +VERSION = '1.0.0-alpha.3' \ No newline at end of file diff --git a/setup.py b/setup.py index c6f21af..f432fed 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ ROOT = dirname(abspath(__file__)) setup(name='robotframework-appiumflutterlibrary', - version='1.0.0-alpha.2', + version='1.0.0-alpha.3', description='Robot Framework Mobile flutter app testing library for Appium Client Android & iOS & Web', long_description=open(join(ROOT, 'README.md')).read(), author='Igor Augusto', From d79982e9aa548543416f061abef0c18f0e2f2eb0 Mon Sep 17 00:00:00 2001 From: igortavtib Date: Fri, 12 Nov 2021 10:17:09 -0300 Subject: [PATCH 2/2] feat: add timeout and element text --- AppiumFlutterLibrary/keywords/_element.py | 11 +++++++++++ AppiumFlutterLibrary/keywords/_waiting.py | 13 +++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/AppiumFlutterLibrary/keywords/_element.py b/AppiumFlutterLibrary/keywords/_element.py index c8878fc..35653d9 100644 --- a/AppiumFlutterLibrary/keywords/_element.py +++ b/AppiumFlutterLibrary/keywords/_element.py @@ -44,6 +44,13 @@ def element_text_should_be(self, locator, text): raise AssertionError("Element '%s' text should be '%s' but is '%s'." % (locator, text, element.text)) + def get_element(self, locator): + return self._find_element(locator) + + def get_element_text(self, locator): + element = self._find_element(locator) + return self._get_element_text(element) + def _is_visible(self, element): application = self._current_application() application.execute_script('flutter:waitFor', element, 1) @@ -52,3 +59,7 @@ def _is_visible(self, element): def _find_element(self, locator): application = self._current_application() return self._element_finder.find(application, locator) + + def _get_element_text(self, element): + application = self._current_application() + return application.execute_script('flutter:getText', element) \ No newline at end of file diff --git a/AppiumFlutterLibrary/keywords/_waiting.py b/AppiumFlutterLibrary/keywords/_waiting.py index 3944f42..c25afb0 100644 --- a/AppiumFlutterLibrary/keywords/_waiting.py +++ b/AppiumFlutterLibrary/keywords/_waiting.py @@ -7,10 +7,19 @@ class _WaintingKeywords(KeywordGroup): def __init__(self): self._element_finder = ElementFinder() - def wait_for_element(self, locator, timeout=None, error=None): + def wait_for_element(self, locator, timeout=20): application = self._current_application() element = self._element_finder.find(application, locator) - application.execute_script('flutter:waitFor', element) + if timeout == 0: + timeout=None + try: + if timeout is None: + application.execute_script('flutter:waitFor', element) + else: + application.execute_script('flutter:waitFor', element, timeout) + except Exception: + raise AssertionError("Could not find element '%s' in %s seconds" % (locator, timeout)) + def _format_timeout(self, timeout): timeout = robot.utils.timestr_to_secs(timeout) if timeout is not None else self._timeout_in_secs