Skip to content

Commit

Permalink
Add swipe segments as list of tuples
Browse files Browse the repository at this point in the history
- Convert tuples to points
  • Loading branch information
dtmilano committed Oct 13, 2022
1 parent 31d03d5 commit fca7d40
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/com/dtmilano/android/uiautomator/uiautomatorhelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

from __future__ import print_function

__version__ = '21.17.0'
__version__ = '21.17.1'

import json
import os
Expand Down Expand Up @@ -513,6 +513,15 @@ def swipe(self, **kwargs):
"""
if self.all(['start_x', 'start_y', 'end_x', 'end_y', 'steps'], kwargs):
return self.uiAutomatorHelper.api_instance.ui_device_swipe_get(**kwargs)
if 'segments' in kwargs:
# noinspection PyBroadException
try:
segments = kwargs['segments']
if isinstance(segments, list):
if all(isinstance(e, tuple) for e in segments):
kwargs['segments'] = list(map(lambda e: Point(*e), segments))
except Exception:
pass
body = culebratester_client.SwipeBody(**kwargs)
return self.uiAutomatorHelper.api_instance.ui_device_swipe_post(body=body)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
import random
import sys

from culebratester_client import ObjectRef
from culebratester_client import ObjectRef, Point

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

def testSwipe_list_of_points(self):
segments = [Point(0, 0), Point(100, 100), Point(0, 100)]
steps = random.randint(10, 100)
response = self.uiAutomatorHelper.ui_device.swipe(segments=segments, segment_steps=steps)
if DEBUG:
print("response=", response, file=sys.stderr)
self.assertEqual(response.status, 'OK')

def testSwipe_list_of_tuples(self):
segments = [(0, 0), (100, 100), (0, 100)]
steps = random.randint(10, 100)
response = self.uiAutomatorHelper.ui_device.swipe(segments=segments, segment_steps=steps)
if DEBUG:
print("response=", response, file=sys.stderr)
self.assertEqual(response.status, 'OK')


def testSetText_UiObject2_Chinese_text(self):
# This enters a Reminder using Calendar
# See https://github.com/dtmilano/AndroidViewClient/issues/242
Expand Down

0 comments on commit fca7d40

Please sign in to comment.