Skip to content

Commit b645bd9

Browse files
committed
Added more verbose output to UiAutomator 'dumped' error
- Version 2.3.6 - Added forceviewserveruse to viewclientconnected tests - Added help, ignore-secure-device, force-viewserver-use nad do-no-start-view-server options to dump.py - Renamed test to viewclient-with-real-devices-connected
1 parent 5343b8e commit b645bd9

4 files changed

Lines changed: 30 additions & 19 deletions

File tree

AndroidViewClient/examples/dump.py

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,11 @@
2828

2929
from com.dtmilano.android.viewclient import ViewClient
3030

31+
HELP = 'help'
3132
VERBOSE = 'verbose'
33+
IGNORE_SECURE_DEVICE = 'ignore-secure-device'
3234
FORCE_VIEW_SERVER_USE = 'force-view-server-use'
35+
DO_NOT_START_VIEW_SERVER = 'do-not-start-view-server'
3336
UNIQUE_ID = 'uniqueId'
3437
POSITION = 'position'
3538
CONTENT_DESCRIPTION = 'content-description'
@@ -39,29 +42,36 @@
3942
'd':ViewClient.TRAVERSE_CITCD, CONTENT_DESCRIPTION:ViewClient.TRAVERSE_CITCD,
4043
'c':ViewClient.TRAVERSE_CITC, CENTER:ViewClient.TRAVERSE_CITC,
4144
}
45+
LONG_OPTS = [HELP, VERBOSE, IGNORE_SECURE_DEVICE, FORCE_VIEW_SERVER_USE, DO_NOT_START_VIEW_SERVER,
46+
UNIQUE_ID, POSITION, CONTENT_DESCRIPTION, CENTER]
4247

43-
def usage():
44-
print >> sys.stderr, 'usage: dump.py [-V|--%s] [-F|--%s] [-u|--%s] [-x|--%s] [-d|--%s] [-c|--%s] [serialno]' % \
45-
(VERBOSE, FORCE_VIEW_SERVER_USE, UNIQUE_ID, POSITION, CONTENT_DESCRIPTION, CENTER)
46-
sys.exit(1)
48+
def usage(exitVal=1):
49+
print >> sys.stderr, 'usage: dump.py [-H|--%s] [-V|--%s] [-I|--%s] [-F|--%s] [-S|--%s] [-u|--%s] [-x|--%s] [-d|--%s] [-c|--%s] [serialno]' % \
50+
tuple(LONG_OPTS)
51+
sys.exit(exitVal)
4752

4853
try:
49-
opts, args = getopt.getopt(sys.argv[1:], 'VFuxdc',
50-
[VERBOSE, FORCE_VIEW_SERVER_USE, UNIQUE_ID, POSITION, CONTENT_DESCRIPTION, CENTER])
54+
opts, args = getopt.getopt(sys.argv[1:], 'HVIFSuxdc', LONG_OPTS)
5155
except getopt.GetoptError, e:
5256
print >>sys.stderr, 'ERROR:', str(e)
5357
usage()
5458

55-
verbose = False
56-
kwargs = {'forceviewserveruse': False}
59+
kwargs1 = {VERBOSE: False, 'ignoresecuredevice': False}
60+
kwargs2 = {'forceviewserveruse': False, 'startviewserver': True}
5761
transform = ViewClient.TRAVERSE_CIT
5862
for o, a in opts:
5963
o = o.strip('-')
60-
if o in ['V', VERBOSE]:
61-
verbose = True
64+
if o in ['H', HELP]:
65+
usage(0)
66+
elif o in ['V', VERBOSE]:
67+
kwargs1[VERBOSE] = True
68+
elif o in ['I', IGNORE_SECURE_DEVICE]:
69+
kwargs1['ignoresecuredevice'] = True
6270
elif o in ['F', FORCE_VIEW_SERVER_USE]:
63-
kwargs['forceviewserveruse'] = True
71+
kwargs2['forceviewserveruse'] = True
72+
elif o in ['S', DO_NOT_START_VIEW_SERVER]:
73+
kwargs2['startviewserver'] = False
6474
else:
6575
transform = MAP[o]
6676

67-
ViewClient(*ViewClient.connectToDeviceOrExit(verbose=verbose), **kwargs).traverse(transform=transform)
77+
ViewClient(*ViewClient.connectToDeviceOrExit(**kwargs1), **kwargs2).traverse(transform=transform)

AndroidViewClient/src/com/dtmilano/android/viewclient.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
@author: diego
1818
'''
1919

20-
__version__ = '2.3.5'
20+
__version__ = '2.3.6'
2121

2222
import sys
2323
import subprocess
@@ -1481,7 +1481,7 @@ def dump(self, windowId=-1, sleep=1):
14811481
if not output:
14821482
raise RuntimeError('ERROR: Getting UIAutomator dump')
14831483
if not re.search('dumped', output):
1484-
raise RuntimeError("ERROR: UIAutomator dump doesn't containt 'dumped'")
1484+
raise RuntimeError("ERROR: UIAutomator dump output doesn't containt 'dumped' (%s)" % output)
14851485
received = self.device.shell('cat %s 2>/dev/null' % windowDump)
14861486
if received:
14871487
received = received.encode('ascii', 'ignore')

AndroidViewClient/tests/com/dtmilano/android/viewclient-with-real-device-connected.py renamed to AndroidViewClient/tests/com/dtmilano/android/viewclient-with-real-devices-connected.py

File renamed without changes.

AndroidViewClient/tests/com/dtmilano/android/viewclientconnected.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,17 @@
2323
pass
2424

2525
from com.dtmilano.android.viewclient import *
26+
from mocks import MockDevice
2627

27-
VERBOSE = False
28+
VERBOSE = True
2829

2930
# NOTE:
3031
# Because there's no way of disconnect a MonkeyDevice and there's no
3132
# either the alternative of connecting twice from the same script
3233
# this is the only alternative
3334
SERIALNO = 'emulator-5554'
3435
sys.argv = ['ViewClientConnectedTest', SERIALNO]
35-
device, serialno = ViewClient.connectToDeviceOrExit(verbose=True)
36+
device, serialno = ViewClient.connectToDeviceOrExit(verbose=VERBOSE, serialno=SERIALNO)
3637

3738
class ViewClientConnectedTest(unittest.TestCase):
3839

@@ -49,11 +50,11 @@ def tearDown(self):
4950

5051
def testInit_adbNone(self):
5152
device = MockDevice()
52-
vc = ViewClient(device, adb=None, autodump=False)
53+
vc = ViewClient(device, serialno, adb=None, autodump=False)
5354
self.assertNotEqual(None, vc)
5455

5556
def testAutodumpVsDump(self):
56-
vc = ViewClient(self.device, self.serialno)
57+
vc = ViewClient(self.device, self.serialno, forceviewserveruse=True)
5758
ids = vc.getViewIds()
5859
views = vc.dump()
5960
self.assertEquals(len(ids), len(views))
@@ -65,7 +66,7 @@ def testNewViewClientInstancesDontDuplicateTreeConnected(self):
6566
d = {}
6667

6768
for i in range(10):
68-
vc[i] = ViewClient(self.device, self.serialno)
69+
vc[i] = ViewClient(self.device, self.serialno, forceviewserveruse=True)
6970
n[i] = len(vc[i].getViewIds())
7071
m[i] = len(vc[i].dump())
7172
d[i] = len(vc[i].getViewIds())

0 commit comments

Comments
 (0)