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

Commit 02c034e

Browse files
committed
feat: First keyword functions
1 parent 5f0c6be commit 02c034e

File tree

11 files changed

+148
-8
lines changed

11 files changed

+148
-8
lines changed

AppiumFlutterLibrary/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
__version__ = VERSION
77

88
class AppiumFlutterLibrary(
9+
_ApplicationManagementKeyWords,
10+
_ElementKeywords,
911
_RunOnFailureKeyWords,
10-
_ApplicationManagementKeyWords
12+
_WaintingKeywords
1113
):
1214
ROBOT_LIBRARY_SCOPE = 'GLOBAL'
1315
ROBOT_LIBRARY_VERSION = VERSION
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
from ._applicationmanagement import _ApplicationManagementKeyWords
2+
from ._element import _ElementKeywords
23
from ._runonfailure import _RunOnFailureKeyWords
4+
from ._waiting import _WaintingKeywords
35

46
__all__ = [
57
"_ApplicationManagementKeyWords",
6-
"_RunOnFailureKeyWords"]
8+
"_ElementKeywords",
9+
"_RunOnFailureKeyWords",
10+
"_WaintingKeywords"
11+
]

AppiumFlutterLibrary/keywords/_applicationmanagement.py

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

33
import robot
4-
4+
from appium import webdriver
5+
from AppiumFlutterLibrary.utils import ApplicationCache
56
from AppiumFlutterLibrary.keywords.keywordgroup import KeywordGroup
7+
from appium.webdriver import Remote
8+
from appium_flutter_finder import FlutterElement, FlutterFinder
69

710
class _ApplicationManagementKeyWords(KeywordGroup):
8-
def __init_(self):
11+
def __init__(self):
12+
self._cache = ApplicationCache
913
self._timeout_in_secs = float(5)
1014

15+
def open_application(self, remote_url, alias=None, **kwargs):
16+
desired_caps = kwargs
17+
application = Remote(str(remote_url), dict(desired_caps))
18+
19+
return self._cache.register(application, alias)
20+
21+
def login_to_application(self, remote_url, alias=None, **kwargs):
22+
driver = Remote('http://localhost:4723/wd/hub', dict(
23+
platformName='android',
24+
automationName='flutter',
25+
udid='emulator-5554',
26+
app='/home/igortavtib/Projects/robotframework-appiumflutterlibrary/app-prod-debug.apk'
27+
))
28+
29+
finder = FlutterFinder()
30+
31+
key_finder = finder.by_value_key('input-user')
32+
input_element = FlutterElement(driver, key_finder)
33+
key_finder = finder.by_value_key('input-password')
34+
password_element = FlutterElement(driver, key_finder)
35+
driver.execute_script('flutter:waitFor', input_element)
36+
input_element.send_keys('igoraugsto@gmail.com')
37+
password_element.send_keys('senha123')
38+
1139
def set_appium_timeout(self, seconds):
1240
old_timeout = self.get_appium_timeout()
1341
self._timeout_in_secs = robot.utils.timestr_to_secs(seconds)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import time
2+
from robot.libraries.BuiltIn import BuiltIn
3+
from .keywordgroup import KeywordGroup
4+
from appium_flutter_finder import FlutterElement, FlutterFinder
5+
6+
try:
7+
basestring # attempt to evaluate basestring
8+
9+
def isstr(s):
10+
return isinstance(s, basestring)
11+
except NameError:
12+
def isstr(s):
13+
return isinstance(s, str)
14+
15+
class _ElementKeywords(KeywordGroup):
16+
def __init__(self):
17+
self._element_finder = FlutterFinder()
18+
self._bi = BuiltIn()
19+
20+
def input_text(self, locator, text):
21+
application = self._current_application()
22+
finder = FlutterFinder()
23+
key_finder = finder.by_value_key(locator)
24+
element = FlutterElement(application, key_finder)
25+
element.send_keys(text)
26+
27+
28+
def _element_find(self, locator):
29+
application = self._current_application()
30+
element = None
31+
if isstr(locator):
32+
_locator = locator
33+
_key_finder = self._element_finder.by_value_key(_locator)
34+
element = FlutterElement(application, _key_finder)
35+
36+
return element
37+
38+
def _is_visible(self, locator):
39+
element = self._element_find(locator)
40+
if element is not None:
41+
return element.is_displayed()
42+
return None

AppiumFlutterLibrary/keywords/_runonfailure.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,5 @@ def register_keyword_to_run_on_failure(self, keyword):
1616
new_keyword_text = new_keyword if new_keyword is not None else "Nothing"
1717

1818
self._run_on_failure_keyword = new_keyword
19-
self._info('%s will be run on failure.' % new_keyword_text)
2019

2120
return old_keyword
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import robot
2+
from AppiumFlutterLibrary.keywords.keywordgroup import KeywordGroup
3+
from appium_flutter_finder import FlutterElement, FlutterFinder
4+
5+
6+
class _WaintingKeywords(KeywordGroup):
7+
def wait_for_element(self, locator, timeout=None, error=None):
8+
application = self._current_application()
9+
finder = FlutterFinder()
10+
key_finder = finder.by_value_key(locator)
11+
element = FlutterElement(application, key_finder)
12+
application.execute_script('flutter:waitFor', element)
13+
14+
def _format_timeout(self, timeout):
15+
timeout = robot.utils.timestr_to_secs(timeout) if timeout is not None else self._timeout_in_secs
16+
return robot.utils.secs_to_timestr(timeout)

AppiumFlutterLibrary/keywords/test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313

1414
key_finder = finder.by_value_key('input-user')
1515
input_element = FlutterElement(driver, key_finder)
16-
driver.execute('flutter::waitFor', input_element)
16+
driver.execute_script('flutter:waitFor', input_element)
1717
input_element.send_keys('Teste 123')
1818

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import six
2+
3+
from .applicationcache import ApplicationCache
4+
5+
if six.PY3:
6+
unicode = str
7+
8+
def escape_xpath_value(value):
9+
value = unicode(value)
10+
if '"' in value and '\'' in value:
11+
parts_wo_apos = value.split('\'')
12+
return "concat('%s')" % "', \"'\", '".join(parts_wo_apos)
13+
if '\'' in value:
14+
return "\"%s\"" % value
15+
return "'%s'" % value
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from robot.utils import ConnectionCache;
2+
3+
class ApplicationCache(ConnectionCache):
4+
def __init__(self):
5+
ConnectionCache.__init__(self, no_current_msg='No current application')
6+
self._closed = set()
7+
8+
@property
9+
def applications(self):
10+
return self._connections
11+
12+
def get_open_browsers(self):
13+
open_applications = []
14+
for application in self._connections:
15+
if application not in self._closed:
16+
open_applications.append(application)
17+
return open_applications
18+
19+
def close(self):
20+
if self.current:
21+
application = self.current
22+
application.quit()
23+
self.current = self._no_current
24+
self.current_index = None
25+
self._closed.add(application)
26+
27+
def close_all(self):
28+
for application in self._connections:
29+
if application not in self._closed:
30+
application.quit()
31+
self.empty_cache()
32+
return self.current

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.6.3'
2+
VERSION = '1.0.0-alpha'

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
'Appium-Python-Client >= 1.1.0',
3737
'selenium >= 2.47.1',
3838
'kitchen >= 1.2.4',
39-
'six >= 1.10.0'
39+
'six >= 1.10.0',
40+
'Appium-Flutter-Finder >= 0.3.0'
4041
],
4142
include_package_data=True,
4243
)

0 commit comments

Comments
 (0)