Skip to content

Commit

Permalink
Added more verbose output to UiAutomator 'dumped' error
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
dtmilano committed Feb 4, 2013
1 parent 5343b8e commit b645bd9
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 19 deletions.
34 changes: 22 additions & 12 deletions AndroidViewClient/examples/dump.py
Expand Up @@ -28,8 +28,11 @@


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


HELP = 'help'
VERBOSE = 'verbose' VERBOSE = 'verbose'
IGNORE_SECURE_DEVICE = 'ignore-secure-device'
FORCE_VIEW_SERVER_USE = 'force-view-server-use' FORCE_VIEW_SERVER_USE = 'force-view-server-use'
DO_NOT_START_VIEW_SERVER = 'do-not-start-view-server'
UNIQUE_ID = 'uniqueId' UNIQUE_ID = 'uniqueId'
POSITION = 'position' POSITION = 'position'
CONTENT_DESCRIPTION = 'content-description' CONTENT_DESCRIPTION = 'content-description'
Expand All @@ -39,29 +42,36 @@
'd':ViewClient.TRAVERSE_CITCD, CONTENT_DESCRIPTION:ViewClient.TRAVERSE_CITCD, 'd':ViewClient.TRAVERSE_CITCD, CONTENT_DESCRIPTION:ViewClient.TRAVERSE_CITCD,
'c':ViewClient.TRAVERSE_CITC, CENTER:ViewClient.TRAVERSE_CITC, 'c':ViewClient.TRAVERSE_CITC, CENTER:ViewClient.TRAVERSE_CITC,
} }
LONG_OPTS = [HELP, VERBOSE, IGNORE_SECURE_DEVICE, FORCE_VIEW_SERVER_USE, DO_NOT_START_VIEW_SERVER,
UNIQUE_ID, POSITION, CONTENT_DESCRIPTION, CENTER]


def usage(): def usage(exitVal=1):
print >> sys.stderr, 'usage: dump.py [-V|--%s] [-F|--%s] [-u|--%s] [-x|--%s] [-d|--%s] [-c|--%s] [serialno]' % \ 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]' % \
(VERBOSE, FORCE_VIEW_SERVER_USE, UNIQUE_ID, POSITION, CONTENT_DESCRIPTION, CENTER) tuple(LONG_OPTS)
sys.exit(1) sys.exit(exitVal)


try: try:
opts, args = getopt.getopt(sys.argv[1:], 'VFuxdc', opts, args = getopt.getopt(sys.argv[1:], 'HVIFSuxdc', LONG_OPTS)
[VERBOSE, FORCE_VIEW_SERVER_USE, UNIQUE_ID, POSITION, CONTENT_DESCRIPTION, CENTER])
except getopt.GetoptError, e: except getopt.GetoptError, e:
print >>sys.stderr, 'ERROR:', str(e) print >>sys.stderr, 'ERROR:', str(e)
usage() usage()


verbose = False kwargs1 = {VERBOSE: False, 'ignoresecuredevice': False}
kwargs = {'forceviewserveruse': False} kwargs2 = {'forceviewserveruse': False, 'startviewserver': True}
transform = ViewClient.TRAVERSE_CIT transform = ViewClient.TRAVERSE_CIT
for o, a in opts: for o, a in opts:
o = o.strip('-') o = o.strip('-')
if o in ['V', VERBOSE]: if o in ['H', HELP]:
verbose = True usage(0)
elif o in ['V', VERBOSE]:
kwargs1[VERBOSE] = True
elif o in ['I', IGNORE_SECURE_DEVICE]:
kwargs1['ignoresecuredevice'] = True
elif o in ['F', FORCE_VIEW_SERVER_USE]: elif o in ['F', FORCE_VIEW_SERVER_USE]:
kwargs['forceviewserveruse'] = True kwargs2['forceviewserveruse'] = True
elif o in ['S', DO_NOT_START_VIEW_SERVER]:
kwargs2['startviewserver'] = False
else: else:
transform = MAP[o] transform = MAP[o]


ViewClient(*ViewClient.connectToDeviceOrExit(verbose=verbose), **kwargs).traverse(transform=transform) ViewClient(*ViewClient.connectToDeviceOrExit(**kwargs1), **kwargs2).traverse(transform=transform)
4 changes: 2 additions & 2 deletions AndroidViewClient/src/com/dtmilano/android/viewclient.py
Expand Up @@ -17,7 +17,7 @@
@author: diego @author: diego
''' '''


__version__ = '2.3.5' __version__ = '2.3.6'


import sys import sys
import subprocess import subprocess
Expand Down Expand Up @@ -1481,7 +1481,7 @@ def dump(self, windowId=-1, sleep=1):
if not output: if not output:
raise RuntimeError('ERROR: Getting UIAutomator dump') raise RuntimeError('ERROR: Getting UIAutomator dump')
if not re.search('dumped', output): if not re.search('dumped', output):
raise RuntimeError("ERROR: UIAutomator dump doesn't containt 'dumped'") raise RuntimeError("ERROR: UIAutomator dump output doesn't containt 'dumped' (%s)" % output)
received = self.device.shell('cat %s 2>/dev/null' % windowDump) received = self.device.shell('cat %s 2>/dev/null' % windowDump)
if received: if received:
received = received.encode('ascii', 'ignore') received = received.encode('ascii', 'ignore')
Expand Down
Expand Up @@ -23,16 +23,17 @@
pass pass


from com.dtmilano.android.viewclient import * from com.dtmilano.android.viewclient import *
from mocks import MockDevice


VERBOSE = False VERBOSE = True


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


class ViewClientConnectedTest(unittest.TestCase): class ViewClientConnectedTest(unittest.TestCase):


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


def testInit_adbNone(self): def testInit_adbNone(self):
device = MockDevice() device = MockDevice()
vc = ViewClient(device, adb=None, autodump=False) vc = ViewClient(device, serialno, adb=None, autodump=False)
self.assertNotEqual(None, vc) self.assertNotEqual(None, vc)


def testAutodumpVsDump(self): def testAutodumpVsDump(self):
vc = ViewClient(self.device, self.serialno) vc = ViewClient(self.device, self.serialno, forceviewserveruse=True)
ids = vc.getViewIds() ids = vc.getViewIds()
views = vc.dump() views = vc.dump()
self.assertEquals(len(ids), len(views)) self.assertEquals(len(ids), len(views))
Expand All @@ -65,7 +66,7 @@ def testNewViewClientInstancesDontDuplicateTreeConnected(self):
d = {} d = {}


for i in range(10): for i in range(10):
vc[i] = ViewClient(self.device, self.serialno) vc[i] = ViewClient(self.device, self.serialno, forceviewserveruse=True)
n[i] = len(vc[i].getViewIds()) n[i] = len(vc[i].getViewIds())
m[i] = len(vc[i].dump()) m[i] = len(vc[i].dump())
d[i] = len(vc[i].getViewIds()) d[i] = len(vc[i].getViewIds())
Expand Down

0 comments on commit b645bd9

Please sign in to comment.