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

Commit 81727ec

Browse files
authored
feat: documentation (#3)
1 parent a09888e commit 81727ec

File tree

8 files changed

+1828
-2
lines changed

8 files changed

+1828
-2
lines changed

AppiumFlutterLibrary/__init__.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,53 @@ class AppiumFlutterLibrary(
1313
_RunOnFailureKeyWords,
1414
_WaintingKeywords,
1515
):
16+
""" AppiumFlutterLibrary is a flutter testing library for Robot Framework
17+
that uses FlutterDriver class and appium to test flutter mobile apps.
18+
19+
The lib was inspired by AppiumLibrary.
20+
21+
== Flutter Finder ==
22+
23+
All keywords that needs to interact with and element needs to find this element
24+
first. For this prupose we have the locators that comunicate with FlutterDriver
25+
findBy functions.
26+
27+
== Locators ==
28+
29+
By default when passing a locator without a specifier the library will get this
30+
locator as a FlutterDriver key. If you want to use a different locator you need to
31+
set the specifier.
32+
33+
Example:
34+
35+
| Click Element input-button
36+
| Click Element text=Input
37+
38+
Avalible locators:
39+
40+
| *Locator* | *Description* |
41+
| key(default) | FlutterDriver element key. |
42+
| text | Element text. |
43+
"""
1644
ROBOT_LIBRARY_SCOPE = 'GLOBAL'
1745
ROBOT_LIBRARY_VERSION = VERSION
1846

1947
def __init__(self, timeout=5, run_on_failure='Capture Page Screenshot'):
48+
"""AppiumFlutterLibrary can be imported with optional arguments.
49+
``timeout`` is the default timeout used to wait for all waiting actions.
50+
It can be later set with `Set Appium Timeout`.
51+
52+
``run_on_failure`` specifies the name of a keyword (from any available
53+
libraries) to execute when a AppiumFlutterLibrary keyword fails.
54+
By default `Capture Page Screenshot` will be used to take a screenshot of the current page.
55+
Using the value `No Operation` will disable this feature altogether. See
56+
`Register Keyword To Run On Failure` keyword for more information about this
57+
functionality.
58+
59+
Examples:
60+
| Library | AppiumFlutterLibrary | 10 | # Sets default timeout to 10 seconds |
61+
| Library | AppiumFlutterLibrary | timeout=10 | run_on_failure=No Operation | # Sets default timeout to 10 seconds and does nothing on failure |
62+
"""
2063
for base in AppiumFlutterLibrary.__bases__:
2164
base.__init__(self)
2265
self.set_appium_timeout(timeout)

AppiumFlutterLibrary/keywords/_applicationmanagement.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,21 @@ def __init__(self):
1111
self._timeout_in_secs = float(5)
1212

1313
def open_application(self, remote_url, alias =None, **kwargs):
14+
"""Opens a new application to given Appium server.
15+
16+
*Note*: You must specify automationName capability as 'flutter', so the
17+
FlutterDriver is enabled.
18+
19+
Capabilities of appium server, Android and iOS,
20+
Please check https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/server-args.md
21+
| *Option* | *Man.* | *Description* |
22+
| remote_url | Yes | Appium server url |
23+
| alias | no | alias |
24+
25+
Examples:
26+
| Open Application | http://localhost:4723/wd/hub | alias=Myapp1 | automationName=flutter | platformName=iOS | platformVersion=7.0 | deviceName='iPhone Simulator' | app=your.app |
27+
| Open Application | http://localhost:4723/wd/hub | platformName=Android | automationName=flutter | platformVersion=4.2.2 | deviceName=192.168.56.101:5555 | app=${CURDIR}/demoapp/OrangeDemoApp.apk | appPackage=com.netease.qa.orangedemo | appActivity=MainActivity |
28+
"""
1429
desired_caps = kwargs
1530
if desired_caps['automationName'] != 'flutter':
1631
raise ValueError("Appium Flutter Library only suports flutter automation. Try changing automationName capability to 'flutter'")
@@ -23,26 +38,73 @@ def reset_application(self):
2338
self._current_application().reset()
2439

2540
def close_all_applications(self):
41+
"""Closes all open applications.
42+
43+
This keyword is meant to be used in test or suite teardown to
44+
make sure all the applications are closed before the test execution
45+
finishes.
46+
47+
After this keyword, the application indices returned by `Open Application`
48+
are reset and start from `1`.
49+
"""
2650
self._debug("Closing all applications")
2751
self._cache.close_all()
2852

2953
def close_application(self):
54+
"""Closes the current application and also close webdriver session."""
3055
self._debug("Closing current apllication")
3156
self._cache.close()
3257

3358
def background_app(self, seconds=5):
59+
"""
60+
Puts the application in the background on the device for a certain
61+
duration in seconds.
62+
"""
3463
self._current_application().background_app(seconds)
3564

3665
def lock(self, seconds=5):
66+
"""
67+
Lock the device for a certain period of time. iOS only.
68+
"""
3769
self._current_application().lock(robot.utils.timestr_to_secs(seconds))
3870

3971
def portrait(self):
72+
"""
73+
Set the device orientation to PORTRAIT
74+
"""
4075
self._rotate("PORTRAIT")
4176

77+
def landscape(self):
78+
"""
79+
Set the device orientation to LANDSCAPE
80+
"""
81+
self._rotate('LANDSCAPE')
82+
4283
def touch_id(self, match = True):
84+
"""
85+
Simulate Touch ID on iOS Simulator
86+
`match` (boolean) whether the simulated fingerprint is valid (default true)
87+
88+
New in AppiumLibrary 1.5
89+
"""
4390
self._current_application().touch_id(match)
4491

4592
def set_appium_timeout(self, seconds):
93+
"""Sets the timeout in seconds used by various keywords.
94+
95+
There are several `Wait ...` keywords that take timeout as an
96+
argument. All of these timeout arguments are optional. The timeout
97+
used by all of them can be set globally using this keyword.
98+
99+
The previous timeout value is returned by this keyword and can
100+
be used to set the old value back later. The default timeout
101+
is 5 seconds, but it can be altered in `importing`.
102+
103+
Example:
104+
| ${orig timeout} = | Set Appium Timeout | 15 seconds |
105+
| Open page that loads slowly |
106+
| Set Appium Timeout | ${orig timeout} |
107+
"""
46108
old_timeout = self.get_appium_timeout()
47109
self._timeout_in_secs = robot.utils.timestr_to_secs(seconds)
48110
return old_timeout

AppiumFlutterLibrary/keywords/_element.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ def __init__(self):
1010
self._element_finder = ElementFinder()
1111

1212
def input_text(self, locator, text):
13+
"""Input text into the specified element.
14+
15+
If the element does not support text input an error
16+
will be raised.
17+
"""
1318
element = self._find_element(locator)
1419
self._info("Typing text '%s' into component '%s'" % (text, locator))
1520
try:
@@ -18,6 +23,11 @@ def input_text(self, locator, text):
1823
raise err
1924

2025
def clear_text(self, locator):
26+
"""Clear the text from specified element.
27+
28+
If the element does not support text clearing an error
29+
will be raised.
30+
"""
2131
element = self._find_element(locator)
2232
self._info("Clearing text from element '%s'" % (locator))
2333
try:
@@ -26,6 +36,11 @@ def clear_text(self, locator):
2636
raise err
2737

2838
def click_element(self, locator):
39+
"""Tap the specified element.
40+
41+
If the element does not support tapping an error
42+
will be raised.
43+
"""
2944
element = self._find_element(locator)
3045
self._info("Clicking on element %s" % locator)
3146
try:
@@ -34,17 +49,29 @@ def click_element(self, locator):
3449
raise err
3550

3651
def element_should_be_visible(self, locator):
52+
"""Verify if the element is visible using FlutterDriver.waitFor().
53+
54+
If the element isn't visible raise an Assertion Error.
55+
"""
3756
element = self._find_element(locator)
3857
if not self._is_visible(element):
3958
raise AssertionError("Element '%s' should be visible but not" % locator)
4059

4160
def element_text_should_be(self, locator, text):
61+
"""Verify if the element text is equal to provided text.
62+
63+
If the text isn't equal raise an Assertion Error.
64+
65+
If the element does not support getText() raise an error.
66+
"""
4267
element = self._find_element(locator)
4368
if element.text != text:
4469
raise AssertionError("Element '%s' text should be '%s' but is '%s'." %
4570
(locator, text, element.text))
4671

4772
def get_element(self, locator):
73+
"""Returns the element object.
74+
"""
4875
return self._find_element(locator)
4976

5077
def get_element_text(self, locator):

AppiumFlutterLibrary/keywords/_screen.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ def __init__(self):
66
self._element_finder = ElementFinder()
77

88
def scroll_to_element(self, locator):
9+
""" Uses FlutterDriver.scrollIntoView() to scroll until element is visible.
10+
"""
911
application = self._current_application()
1012
element = self._element_finder.find(application, locator)
1113
self._info(element)

AppiumFlutterLibrary/keywords/_waiting.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ def __init__(self):
88
self._element_finder = ElementFinder()
99

1010
def wait_for_element(self, locator, timeout=20):
11+
""" Uses FlutterDriver.waitFor() to wait for an element by the
12+
specified timeout duration.
13+
14+
By default the timeout is 20 seconds.
15+
"""
1116
application = self._current_application()
1217
element = self._element_finder.find(application, locator)
1318
if timeout == 0:

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

0 commit comments

Comments
 (0)