Skip to content

Commit 9bb99fe

Browse files
committed
Preserve command line arguments in ViewClient.connectToDevice()
- dump.py: shift args - check for window ID in window parameter comparison - added testList()
1 parent 884d82b commit 9bb99fe

4 files changed

Lines changed: 28 additions & 11 deletions

File tree

AndroidViewClient/examples/dump.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def usage(exitVal=1):
5656

5757
try:
5858
opts, args = getopt.getopt(sys.argv[1:], SHORT_OPTS, LONG_OPTS)
59+
sys.argv[1:] = args
5960
except getopt.GetoptError, e:
6061
print >>sys.stderr, 'ERROR:', str(e)
6162
usage()

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

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,10 +1122,10 @@ def connectToDeviceOrExit(timeout=60, verbose=False, ignoresecuredevice=False, s
11221122
progname = os.path.basename(sys.argv[0])
11231123
if serialno is None:
11241124
# eat all the extra options the invoking script may have added
1125-
# FIXME: perhaps we should restore the popped arguments
1126-
while len(sys.argv) > 1 and sys.argv[1][0] == '-':
1127-
sys.argv.pop(1)
1128-
serialno = sys.argv[1] if len(sys.argv) > 1 else \
1125+
args = sys.argv
1126+
while len(args) > 1 and args[1][0] == '-':
1127+
args.pop(1)
1128+
serialno = args[1] if len(args) > 1 else \
11291129
os.environ['ANDROID_SERIAL'] if os.environ.has_key('ANDROID_SERIAL') \
11301130
else '.*'
11311131
if IP_RE.match(serialno):
@@ -1498,12 +1498,13 @@ def traverse(self, root="ROOT", indent="", transform=View.__str__, stream=sys.st
14981498
@type transform: method
14991499
@param transform: a method to use to transform the node before is printed
15001500
'''
1501-
if not root:
1502-
return
15031501

15041502
if type(root) == types.StringType and root == "ROOT":
15051503
root = self.root
15061504

1505+
if not root:
1506+
return
1507+
15071508
s = transform(root)
15081509
if s:
15091510
print >>stream, "%s%s" % (indent, s)
@@ -1563,10 +1564,13 @@ def dump(self, window=-1, sleep=1):
15631564
self.list(sleep=0)
15641565
found = False
15651566
for wId in self.windows:
1566-
if window == self.windows[wId]:
1567-
window = wId
1568-
found = True
1569-
break
1567+
try:
1568+
if window == self.windows[wId] or int(window) == wId:
1569+
window = wId
1570+
found = True
1571+
break
1572+
except ValueError:
1573+
pass
15701574
if not found:
15711575
raise RuntimeError("ERROR: Cannot find window '%s'" % window)
15721576

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@
370370
</hierarchy>
371371
"""
372372

373+
WINDOWS = {1:'Window1', 2: 'com.example.window', 3:'StatusBar'}
373374

374375
RUNNING = 1
375376
STOPPED = 0

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
from com.dtmilano.android.viewclient import *
2929
from mocks import MockDevice
30-
from mocks import DUMP, DUMP_SAMPLE_UI, VIEW_MAP, VIEW_MAP_API_8, RUNNING, STOPPED
30+
from mocks import DUMP, DUMP_SAMPLE_UI, VIEW_MAP, VIEW_MAP_API_8, RUNNING, STOPPED, WINDOWS
3131

3232
# this is probably the only reliable way of determining the OS in monkeyrunner
3333
os_name = java.lang.System.getProperty('os.name')
@@ -311,6 +311,13 @@ def __mockTree(self, dump=DUMP):
311311
vc.setViews(dump)
312312
return vc
313313

314+
def __mockWindows(self, windows=WINDOWS):
315+
device = MockDevice()
316+
vc = ViewClient(device, serialno=device.serialno, adb=TRUE, autodump=False)
317+
self.assertNotEquals(None, vc)
318+
vc.windows = windows
319+
return vc
320+
314321
def testRoot(self):
315322
vc = self.__mockTree()
316323
root = vc.root
@@ -444,6 +451,10 @@ def testServiceStoppedAfterDestructor(self):
444451
# Perhpas there are other ViewClients using the same server, we cannot expect it stops
445452
#self.assertTrue(device.service == STOPPED)
446453

454+
def testList(self):
455+
vc = self.__mockWindows()
456+
self.assertNotEqual(None, vc.windows)
457+
447458
def testFindViewByIdOrRaise(self):
448459
vc = self.__mockTree(dump=DUMP_SAMPLE_UI)
449460
vc.findViewByIdOrRaise('id/up')

0 commit comments

Comments
 (0)