Skip to content

Commit b04aec0

Browse files
author
Qualify
committed
Swipe By Percent - new keyword added
Get Window Height - new keyword added Get Window Width - new keyword added
1 parent 8cad8cc commit b04aec0

File tree

7 files changed

+162
-14
lines changed

7 files changed

+162
-14
lines changed

CHANGES.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
History
22
=======
3+
1.4.5
4+
----------------
5+
- Swipe By Percent - new keyword added
6+
- Element Should Be Visible - new keyword added
7+
- Text Should Be Visible - new keyword added
8+
- Get Window Height - new keyword added
9+
- Get Window Width - new keyword added
10+
311
1.4.4
412
----------------
513
- Get Capability added for easy access to desired capabilities

README.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ AppiumLibrary is modeled after (and forked from) `appiumandroidlibrary <https:/
1414

1515
It support Python 2.x only.
1616

17+
Documentation
18+
-------------
19+
20+
The keyword documentation could be found at `Keyword Documentation
21+
<http://serhatbolsu.github.io/robotframework-appiumlibrary/AppiumLibrary.html>`_
22+
1723

1824
Installation
1925
------------
@@ -62,11 +68,6 @@ for more information.
6268
As it uses Appium make sure your Appium server is up and running.
6369
For how to use Appium please refer to `Appium Documentation <http://appium.io/getting-started.html>`_
6470

65-
Documentation
66-
-------------
67-
68-
The keyword documentation could be found at `Keyword Documentation
69-
<http://serhatbolsu.github.io/robotframework-appiumlibrary/AppiumLibrary.html>`_
7071

7172
Contributing
7273
-------------

docs/AppiumLibrary.html

Lines changed: 85 additions & 6 deletions
Large diffs are not rendered by default.

src/AppiumLibrary/keywords/_android_utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ def wait_activity(self, activity, timeout, interval=1):
146146

147147
def install_app(self, app_path, app_package):
148148
""" Install App via Appium
149+
150+
Android only.
149151
150152
- app_path - path to app
151153
- app_package - package of install app to verify

src/AppiumLibrary/keywords/_applicationmanagement.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,30 @@ def get_contexts(self):
192192
print(self._current_application().contexts)
193193
return self._current_application().contexts
194194

195+
def get_window_height(self):
196+
"""Get current device height.
197+
198+
Example:
199+
| ${width} | Get Window Height |
200+
| ${height} | Get Window Height |
201+
| Click A Point | ${width | ${height} |
202+
203+
New in AppiumLibrary 1.4.5
204+
"""
205+
return self._current_application().get_window_size()['height']
206+
207+
def get_window_width(self):
208+
"""Get current device width.
209+
210+
Example:
211+
| ${width} | Get Window Height |
212+
| ${height} | Get Window Height |
213+
| Click A Point | ${width | ${height} |
214+
215+
New in AppiumLibrary 1.4.5
216+
"""
217+
return self._current_application().get_window_size()['width']
218+
195219
def switch_to_context(self, context_name):
196220
"""Switch to a new context"""
197221
self._current_application().switch_to.context(context_name)

src/AppiumLibrary/keywords/_touch.py

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,46 @@ def swipe(self, start_x, start_y, offset_x, offset_y, duration=1000):
4141
Usage:
4242
| Swipe | 500 | 100 | 100 | 0 | 1000 |
4343
44-
*!Important Note:* Android `Swipe` is not working properly, use ``offset_x`` and ``offset_y``
45-
as if these are destination points.
44+
_*NOTE: *_
45+
Android 'Swipe' is not working properly, use ``offset_x`` and ``offset_y`` as if these are destination points.
4646
"""
4747
driver = self._current_application()
4848
driver.swipe(start_x, start_y, offset_x, offset_y, duration)
4949

50+
def swipe_by_percent(self, start_x, start_y, end_x, end_y):
51+
"""
52+
Swipe from one percent of the screen to another percent, for an optional duration.
53+
Normal swipe fails to scale for different screen resolutions, this can be avoided using percent.
54+
55+
Args:
56+
- start_x - x-percent at which to start
57+
- start_y - y-percent at which to start
58+
- end_x - x-percent distance from start_x at which to stop
59+
- end_y - y-percent distance from start_y at which to stop
60+
- duration - (optional) time to take the swipe, in ms.
61+
62+
Usage:
63+
| Swipe By Percent | 90 | 50 | 10 | 50 | # Swipes screen from right to left. |
64+
65+
_*NOTE: *_
66+
This also considers swipe acts different between iOS and Android.
67+
68+
New in AppiumLibrary 1.4.5
69+
"""
70+
width = self.get_window_width()
71+
height = self.get_window_height()
72+
x_start = float(start_x) / 100 * width
73+
x_end = float(end_x) / 100 * width
74+
y_start = float(start_y) / 100 * height
75+
y_end = float(end_y) / 100 * height
76+
x_offset = x_end - x_start
77+
y_offset = y_end - y_start
78+
platform = self._get_platform()
79+
if platform == 'android':
80+
self.swipe(x_start, y_start, x_end, y_end)
81+
else:
82+
self.swipe(x_start, y_start, x_offset, y_offset)
83+
5084
def scroll(self, start_locator, end_locator):
5185
"""
5286
Scrolls from one element to another

src/AppiumLibrary/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# -*- coding: utf-8 -*-
22

3-
VERSION = '1.4.4'
3+
VERSION = '1.4.5'

0 commit comments

Comments
 (0)