Skip to content

Commit 6059fb2

Browse files
committed
Fixed methods receiving either uiObject or uiObject2 using "duck typing"
- Added 'list' option to 'dump' windows
1 parent bea539d commit 6059fb2

2 files changed

Lines changed: 18 additions & 10 deletions

File tree

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

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

21-
__version__ = '15.1.2'
21+
__version__ = '15.1.3'
2222

2323
import json
2424
import os
@@ -305,8 +305,9 @@ def waitForIdle(self, timeout):
305305
# UiObject
306306
#
307307
def setText(self, uiObject, text):
308+
# NOTICE: uiObject can receive UiObject or UiObject2
308309
params = {'text': text}
309-
return self.__httpCommand('/UiObject/0x%x/setText' % (uiObject.oid), params)
310+
return self.__httpCommand('/UiObject/0x%x/setText' % uiObject.oid, params)
310311

311312
#
312313
# UiObject2
@@ -315,11 +316,11 @@ def clickAndWait(self, uiObject2, eventCondition, timeout):
315316
params = {'eventCondition': eventCondition, 'timeout': timeout}
316317
return self.__httpCommand('/UiObject2/%d/clickAndWait' % (uiObject2.oid), params)
317318

318-
def getText(self, uiObject=None, uiObject2=None):
319+
def getText(self, uiObject=None):
320+
# NOTICE: uiObject can receive UiObject or UiObject2
321+
element = uiObject.__class__.__name__
319322
if uiObject:
320-
path = '/UiObject/%d/getText' % (uiObject.oid)
321-
elif uiObject2:
322-
path = '/UiObject2/%d/getText' % (uiObject2.oid)
323+
path = '/%s/%d/getText' % (element, uiObject.oid)
323324
else:
324325
raise ValueError("No uiObject or uiObject2 specified")
325326
response = self.__httpCommand(path, None)
@@ -412,10 +413,14 @@ def longClick(self):
412413
self.uiAutomatorHelper.longClick(oid=self.oid)
413414

414415
def getText(self):
415-
return self.uiAutomatorHelper.getText(uiObject2=self)
416+
# NOTICE: even if this is an uiObject2 we are invoking the only "getText" method in UiAutomatorHelper
417+
# passing the uiObject2 as uiObject
418+
return self.uiAutomatorHelper.getText(uiObject=self)
416419

417420
def setText(self, text):
418-
self.uiAutomatorHelper.setText(uiObject2=self, text=text)
421+
# NOTICE: even if this is an uiObject2 we are invoking the only "setText" method in UiAutomatorHelper
422+
# passing the uiObject2 as uiObject
423+
self.uiAutomatorHelper.setText(uiObject=self, text=text)
419424

420425

421426
class UiScrollable:

tools/dump

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Created on Feb 3, 2012
66
@author: diego
77
'''
88

9-
__version__ = '15.1.2'
9+
__version__ = '15.2.0'
1010

1111
import ast
1212
import getopt
@@ -75,7 +75,7 @@ OPTS_HELP = {
7575
'H': 'prints this help',
7676
'V': 'verbose comments',
7777
'I': 'ignore secure device',
78-
'F': 'force view server use (even if UiAutomator present:w)',
78+
'F': 'force view server use (even if UiAutomator present)',
7979
'S': 'don\'t start ViewServer',
8080
'k': 'don\'t ignore UiAutomator killed',
8181
'w': 'dump WINDOW content (default: -1, all windows)',
@@ -218,6 +218,9 @@ if options[DO_NOT_DUMP_VIEWS]:
218218
transform = MAP[DO_NOT_DUMP_VIEWS]
219219

220220
vc = ViewClient(*ViewClient.connectToDeviceOrExit(**kwargs1), **kwargs2)
221+
if options[WINDOW] == 'list':
222+
vc.list()
223+
sys.exit(0)
221224
if options[SAVE_SCREENSHOT]:
222225
vc.device.reconnect = True # (not options[DO_NOT_DUMP_VIEWS])
223226
ext = os.path.splitext(options[SAVE_SCREENSHOT])[1][1:].upper()

0 commit comments

Comments
 (0)