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

Commit 66b3f94

Browse files
authored
feat: new keywords and locators (#4)
1 parent 81727ec commit 66b3f94

File tree

4 files changed

+60
-0
lines changed

4 files changed

+60
-0
lines changed

AppiumFlutterLibrary/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ class AppiumFlutterLibrary(
4040
| *Locator* | *Description* |
4141
| key(default) | FlutterDriver element key. |
4242
| text | Element text. |
43+
| semantics | Element semantics label |
44+
| tooltip | Element tooltip message |
45+
| type | Element type |
4346
"""
4447
ROBOT_LIBRARY_SCOPE = 'GLOBAL'
4548
ROBOT_LIBRARY_VERSION = VERSION

AppiumFlutterLibrary/finder/elementfinder.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ def __init__(self):
77
'xpath': self._find_by_xpath,
88
'key': self._find_by_key,
99
'text': self._find_by_text,
10+
'semantics': self._find_by_semantics_label,
11+
'tooltip': self._find_by_tooltip_message,
12+
'type': self._find_by_type,
1013
}
1114

1215
def find(self, application, locator):
@@ -36,6 +39,24 @@ def _find_by_text(self, application, element_text):
3639

3740
return element
3841

42+
def _find_by_semantics_label(self, application, semantics):
43+
finder_semantics_label = self._element_finder.by_semantics_label(semantics)
44+
element = FlutterElement(application, finder_semantics_label)
45+
46+
return element
47+
48+
def _find_by_tooltip_message(self, application, tooltip):
49+
finder_tooltip_message = self._element_finder.by_tooltip(tooltip)
50+
element = FlutterElement(application, finder_tooltip_message)
51+
52+
return element
53+
54+
def _find_by_type(self, application, type):
55+
finder_type = self._element_finder.by_type(type)
56+
element = FlutterElement(application, finder_type)
57+
58+
return element
59+
3960
def _parse_locator(self, locator):
4061
prefix = None
4162
criteria = locator

AppiumFlutterLibrary/keywords/_element.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,28 @@ def element_text_should_be(self, locator, text):
6969
raise AssertionError("Element '%s' text should be '%s' but is '%s'." %
7070
(locator, text, element.text))
7171

72+
def element_text_should_not_be(self, locator, text):
73+
"""Verify if the element text is not equal to provided text.
74+
75+
If the text isn't equal raise an Assertion Error.
76+
77+
If the element does not support getText() raise an error.
78+
"""
79+
element = self._find_element(locator)
80+
if element.text == text:
81+
raise AssertionError("Element '%s' text should not be '%s' but is." %
82+
(locator, text))
83+
7284
def get_element(self, locator):
7385
"""Returns the element object.
7486
"""
7587
return self._find_element(locator)
7688

7789
def get_element_text(self, locator):
90+
"""Returns element text
91+
92+
If the element does not support getText() raise an error.
93+
"""
7894
element = self._find_element(locator)
7995
return self._get_element_text(element)
8096

AppiumFlutterLibrary/keywords/_waiting.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,26 @@ def wait_for_element(self, locator, timeout=20):
2424
application.execute_script('flutter:waitFor', element, timeout)
2525
except Exception:
2626
raise AssertionError("Could not find element '%s' in %s seconds" % (locator, timeout))
27+
28+
def wait_for_element_absent(self, locator, timeout=20):
29+
"""Wait until element is absent. Uses FlutterDriver.waitForAbsent() to wait
30+
for an element be absent for the specified timeout duration.
31+
32+
By default the timeout is 20 seconds.
33+
"""
34+
application = self._current_application()
35+
element = self._element_finder.find(application, locator)
36+
if timeout == 0:
37+
timeout=None
38+
try:
39+
if timeout is None:
40+
application.execute_script('flutter:waitForAbsent', element)
41+
else:
42+
application.execute_script('flutter:waitForAbsent', element, timeout)
43+
except Exception:
44+
raise AssertionError("Element '%s' still not absent in %s seconds" % (locator, timeout))
45+
46+
2747

2848

2949
def _format_timeout(self, timeout):

0 commit comments

Comments
 (0)