Skip to content

Commit fca7d40

Browse files
committed
Add swipe segments as list of tuples
- Convert tuples to points
1 parent 31d03d5 commit fca7d40

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

src/com/dtmilano/android/uiautomator/uiautomatorhelper.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
from __future__ import print_function
2222

23-
__version__ = '21.17.0'
23+
__version__ = '21.17.1'
2424

2525
import json
2626
import os
@@ -513,6 +513,15 @@ def swipe(self, **kwargs):
513513
"""
514514
if self.all(['start_x', 'start_y', 'end_x', 'end_y', 'steps'], kwargs):
515515
return self.uiAutomatorHelper.api_instance.ui_device_swipe_get(**kwargs)
516+
if 'segments' in kwargs:
517+
# noinspection PyBroadException
518+
try:
519+
segments = kwargs['segments']
520+
if isinstance(segments, list):
521+
if all(isinstance(e, tuple) for e in segments):
522+
kwargs['segments'] = list(map(lambda e: Point(*e), segments))
523+
except Exception:
524+
pass
516525
body = culebratester_client.SwipeBody(**kwargs)
517526
return self.uiAutomatorHelper.api_instance.ui_device_swipe_post(body=body)
518527

tests/comm/dtmilano/android/uiautomator/uiautomatorhelpertests.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
import random
66
import sys
77

8-
from culebratester_client import ObjectRef
8+
from culebratester_client import ObjectRef, Point
99

10+
# noinspection PyBroadException
1011
try:
1112
sys.path.insert(0, os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src'))
1213
except:
@@ -84,6 +85,23 @@ def testSwipe_random(self):
8485
print("response=", response, file=sys.stderr)
8586
self.assertEqual(response.status, 'OK')
8687

88+
def testSwipe_list_of_points(self):
89+
segments = [Point(0, 0), Point(100, 100), Point(0, 100)]
90+
steps = random.randint(10, 100)
91+
response = self.uiAutomatorHelper.ui_device.swipe(segments=segments, segment_steps=steps)
92+
if DEBUG:
93+
print("response=", response, file=sys.stderr)
94+
self.assertEqual(response.status, 'OK')
95+
96+
def testSwipe_list_of_tuples(self):
97+
segments = [(0, 0), (100, 100), (0, 100)]
98+
steps = random.randint(10, 100)
99+
response = self.uiAutomatorHelper.ui_device.swipe(segments=segments, segment_steps=steps)
100+
if DEBUG:
101+
print("response=", response, file=sys.stderr)
102+
self.assertEqual(response.status, 'OK')
103+
104+
87105
def testSetText_UiObject2_Chinese_text(self):
88106
# This enters a Reminder using Calendar
89107
# See https://github.com/dtmilano/AndroidViewClient/issues/242

0 commit comments

Comments
 (0)