Skip to content

Commit c8c867d

Browse files
committed
Fixed swipe parameter names
- Added UiAutomatorHelper methods
1 parent b39c6e8 commit c8c867d

3 files changed

Lines changed: 51 additions & 17 deletions

File tree

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

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
@author: Diego Torres Milano
1919
'''
2020

21-
__version__ = '11.1.0'
21+
__version__ = '11.2.2'
2222

2323
import os
2424
import subprocess
@@ -197,6 +197,12 @@ def __httpCommand(self, url, params=None, method='GET'):
197197
raise RuntimeError("method not supported: " + method)
198198
return response.content
199199

200+
#
201+
# Device
202+
#
203+
def getDisplayRealSize(self):
204+
return self.__httpCommand('/Device/getDisplayRealSize')
205+
200206
#
201207
# UiAutomatorHelper internal commands
202208
#
@@ -210,6 +216,16 @@ def quit(self):
210216
#
211217
# UiDevice
212218
#
219+
def click(self, x, y):
220+
params = {'x': x, 'y': y}
221+
return self.__httpCommand('/UiDevice/click', params)
222+
223+
def dumpWindowHierarchy(self):
224+
dump = self.__httpCommand('/UiDevice/dumpWindowHierarchy').decode(encoding='UTF-8', errors='replace')
225+
if DEBUG:
226+
print >> sys.stderr, "DUMP: ", dump
227+
return dump
228+
213229
def findObject(self, resourceId):
214230
if not resourceId:
215231
raise RuntimeError('findObject: resourceId must have a value')
@@ -221,23 +237,29 @@ def findObject(self, resourceId):
221237
return int("0x" + m.group(1), 16)
222238
raise RuntimeError("Invalid response: " + response)
223239

224-
def takeScreenshot(self, scale=1.0, quality=90):
225-
params = {'scale': scale, 'quality': quality}
226-
return self.__httpCommand('/UiDevice/takeScreenshot', params)
240+
def pressBack(self):
241+
return self.__httpCommand('/UiDevice/pressBack')
227242

228-
def click(self, x, y):
229-
params = {'x': x, 'y': y}
230-
return self.__httpCommand('/UiDevice/click', params)
243+
def pressHome(self):
244+
return self.__httpCommand('/UiDevice/pressHome')
231245

232-
def swipe(self, (x0, y0), (x1, y1), steps):
233-
params = {'x0': x0, 'y0': y0, 'x1': x1, 'y1': y1, 'steps': steps}
246+
def pressKeyCode(self, keyCode, metaState=0):
247+
params = {'keyCode': keyCode, 'metaState': metaState}
248+
return self.__httpCommand('/UiDevice/pressKeyCode', params)
249+
250+
def pressRecentApps(self):
251+
return self.__httpCommand('/UiDevice/pressRecentApps')
252+
253+
def swipe(self, startX=-1, startY=-1, endX=-1, endY=-1, steps=10, segments=[], segmentSteps=5):
254+
if startX != -1 and startY != -1:
255+
params = {'startX': startX, 'startY': startY, 'endX': endX, 'endY': endY, 'steps': steps}
256+
else:
257+
params = {'segments': ','.join(str(p) for p in segments), "segmentSteps": segmentSteps}
234258
return self.__httpCommand('/UiDevice/swipe', params)
235259

236-
def dumpWindowHierarchy(self):
237-
dump = self.__httpCommand('/UiDevice/dumpWindowHierarchy').decode(encoding='UTF-8', errors='replace')
238-
if DEBUG:
239-
print >> sys.stderr, "DUMP: ", dump
240-
return dump
260+
def takeScreenshot(self, scale=1.0, quality=90):
261+
params = {'scale': scale, 'quality': quality}
262+
return self.__httpCommand('/UiDevice/takeScreenshot', params)
241263

242264
#
243265
# UiObject

src/com/dtmilano/android/viewclient.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2318,9 +2318,21 @@ class ViewClient:
23182318
If not running the ViewServer is started on the target device or emulator and then the port
23192319
mapping is created.
23202320
2321+
LocalViewServer backend
2322+
=======================
2323+
ViewServer is started as an application services instead of as a system service.
2324+
23212325
UiAutomator backend
23222326
===================
23232327
No service is started.
2328+
2329+
null backend
2330+
============
2331+
Allows only operations using PX or DIP as hierarchy is not dumped and thus Views not recognized.
2332+
2333+
UiAutomatorHelper backend
2334+
=========================
2335+
Requires B{Culebra Tester} installed on Android device.
23242336
'''
23252337

23262338
imageDirectory = None
@@ -3630,15 +3642,15 @@ def longTouch(self, x, y):
36303642
if self.uiAutomatorHelper:
36313643
if DEBUG_UI_AUTOMATOR_HELPER:
36323644
print >> sys.stderr, "Long-touching (%d, %d) through UiAutomatorHelper" % (x, y)
3633-
self.uiAutomatorHelper.swipe((x, y), (x, y), 400)
3645+
self.uiAutomatorHelper.swipe(startX=x, startY=y, endX=x, endY=y, steps=400)
36343646
else:
36353647
self.device.longTouch(x, y)
36363648

36373649
def swipe(self, (x0, y0), (x1, y1), steps=400):
36383650
if self.uiAutomatorHelper:
36393651
if DEBUG_UI_AUTOMATOR_HELPER:
36403652
print >> sys.stderr, "Swipe (%d, %d) (%d, %d) through UiAutomatorHelper" % (x0, y0, x1, y1)
3641-
self.uiAutomatorHelper.swipe((x0, y0), (x1, y1), steps)
3653+
self.uiAutomatorHelper.swipe(startX=x0, startY=y0, endX=x1, endY=y1, steps=steps)
36423654
else:
36433655
warnings.warn("swipe only implemented using UiAutomatorHelper. Use AdbClient.drag() instead.")
36443656

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def testSwipe_random(self):
6565
x1 = random.randint(0, 1000)
6666
y1 = random.randint(0, 1000)
6767
steps = random.randint(10, 100)
68-
response = self.uiAutomatorHelper.swipe((x0, y0), (x1, y1), steps)
68+
response = self.uiAutomatorHelper.swipe(startX=x0, startY=y0, endX=x1, endY=y1, steps=steps)
6969
if DEBUG:
7070
print >> sys.stderr, "response=", response
7171

0 commit comments

Comments
 (0)