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

Commit a09888e

Browse files
authored
feat: application keywords (#2)
* feat: new application keywords * feat: add timeout and element text
1 parent a5e3723 commit a09888e

File tree

6 files changed

+70
-13
lines changed

6 files changed

+70
-13
lines changed

AppiumFlutterLibrary/finder/elementfinder.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ def _find_by_text(self, application, element_text):
3636

3737
return element
3838

39-
40-
4139
def _parse_locator(self, locator):
4240
prefix = None
4341
criteria = locator

AppiumFlutterLibrary/keywords/_applicationmanagement.py

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# -*- coding: utf-8 -*-
22

33
import robot
4-
import time
54
from AppiumFlutterLibrary.utils import ApplicationCache
65
from AppiumFlutterLibrary.keywords.keywordgroup import KeywordGroup
76
from appium.webdriver import Remote
@@ -11,16 +10,38 @@ def __init__(self):
1110
self._cache = ApplicationCache()
1211
self._timeout_in_secs = float(5)
1312

14-
def close_application(self):
15-
self._cache.close()
16-
1713
def open_application(self, remote_url, alias =None, **kwargs):
1814
desired_caps = kwargs
1915
if desired_caps['automationName'] != 'flutter':
2016
raise ValueError("Appium Flutter Library only suports flutter automation. Try changing automationName capability to 'flutter'")
17+
self._debug("Opening application")
2118
application = Remote(str(remote_url), desired_caps)
2219
return self._cache.register(application, alias)
2320

21+
def reset_application(self):
22+
self._debug("Reseting application")
23+
self._current_application().reset()
24+
25+
def close_all_applications(self):
26+
self._debug("Closing all applications")
27+
self._cache.close_all()
28+
29+
def close_application(self):
30+
self._debug("Closing current apllication")
31+
self._cache.close()
32+
33+
def background_app(self, seconds=5):
34+
self._current_application().background_app(seconds)
35+
36+
def lock(self, seconds=5):
37+
self._current_application().lock(robot.utils.timestr_to_secs(seconds))
38+
39+
def portrait(self):
40+
self._rotate("PORTRAIT")
41+
42+
def touch_id(self, match = True):
43+
self._current_application().touch_id(match)
44+
2445
def set_appium_timeout(self, seconds):
2546
old_timeout = self.get_appium_timeout()
2647
self._timeout_in_secs = robot.utils.timestr_to_secs(seconds)
@@ -37,4 +58,8 @@ def get_appium_timeout(self):
3758
def _current_application(self):
3859
if not self._cache.current:
3960
raise RuntimeError('No application is open')
40-
return self._cache.current
61+
return self._cache.current
62+
63+
def _rotate(self, orientation):
64+
driver = self._current_application()
65+
driver.orientation = orientation

AppiumFlutterLibrary/keywords/_element.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,26 @@ def __init__(self):
1212
def input_text(self, locator, text):
1313
element = self._find_element(locator)
1414
self._info("Typing text '%s' into component '%s'" % (text, locator))
15-
element.send_keys(text)
15+
try:
16+
element.send_keys(text)
17+
except Exception as err:
18+
raise err
19+
20+
def clear_text(self, locator):
21+
element = self._find_element(locator)
22+
self._info("Clearing text from element '%s'" % (locator))
23+
try:
24+
element.clear()
25+
except Exception as err:
26+
raise err
1627

1728
def click_element(self, locator):
1829
element = self._find_element(locator)
1930
self._info("Clicking on element %s" % locator)
20-
element.click()
31+
try:
32+
element.click()
33+
except Exception as err:
34+
raise err
2135

2236
def element_should_be_visible(self, locator):
2337
element = self._find_element(locator)
@@ -30,6 +44,13 @@ def element_text_should_be(self, locator, text):
3044
raise AssertionError("Element '%s' text should be '%s' but is '%s'." %
3145
(locator, text, element.text))
3246

47+
def get_element(self, locator):
48+
return self._find_element(locator)
49+
50+
def get_element_text(self, locator):
51+
element = self._find_element(locator)
52+
return self._get_element_text(element)
53+
3354
def _is_visible(self, element):
3455
application = self._current_application()
3556
application.execute_script('flutter:waitFor', element, 1)
@@ -38,3 +59,7 @@ def _is_visible(self, element):
3859
def _find_element(self, locator):
3960
application = self._current_application()
4061
return self._element_finder.find(application, locator)
62+
63+
def _get_element_text(self, element):
64+
application = self._current_application()
65+
return application.execute_script('flutter:getText', element)

AppiumFlutterLibrary/keywords/_waiting.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,19 @@ class _WaintingKeywords(KeywordGroup):
77
def __init__(self):
88
self._element_finder = ElementFinder()
99

10-
def wait_for_element(self, locator, timeout=None, error=None):
10+
def wait_for_element(self, locator, timeout=20):
1111
application = self._current_application()
1212
element = self._element_finder.find(application, locator)
13-
application.execute_script('flutter:waitFor', element)
13+
if timeout == 0:
14+
timeout=None
15+
try:
16+
if timeout is None:
17+
application.execute_script('flutter:waitFor', element)
18+
else:
19+
application.execute_script('flutter:waitFor', element, timeout)
20+
except Exception:
21+
raise AssertionError("Could not find element '%s' in %s seconds" % (locator, timeout))
22+
1423

1524
def _format_timeout(self, timeout):
1625
timeout = robot.utils.timestr_to_secs(timeout) if timeout is not None else self._timeout_in_secs

AppiumFlutterLibrary/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# -*- coding: utf-8 -*-
2-
VERSION = '1.0.0-alpha.2'
2+
VERSION = '1.0.0-alpha.3'

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
ROOT = dirname(abspath(__file__))
77

88
setup(name='robotframework-appiumflutterlibrary',
9-
version='1.0.0-alpha.2',
9+
version='1.0.0-alpha.3',
1010
description='Robot Framework Mobile flutter app testing library for Appium Client Android & iOS & Web',
1111
long_description=open(join(ROOT, 'README.md')).read(),
1212
author='Igor Augusto',

0 commit comments

Comments
 (0)