Skip to content
Browse files

Default port (5555) added to IP if not specified in serialno paramete…

…r to ViewClient contructor

- Added tests
- __parseTree() invoked now in setViews()
  • Loading branch information...
1 parent 8e805a9 commit ca28135b3b79de2a8182559c7c2190cce45d1de7 @dtmilano committed Sep 20, 2012
View
12 AndroidViewClient/src/com/dtmilano/android/viewclient.py
@@ -658,8 +658,9 @@ def __init__(self, device, adb=os.path.join(ANDROID_HOME, 'platform-tools', ADB)
'This only works on emulator and devices running developer versions.\n'
'Does hierarchyviewer work on your device ?')
+ self.serialno = ViewClient.__mapSerialNo(serialno)
# FIXME: it seems there's no way of obtaining the serialno from the MonkeyDevice
- subprocess.check_call([adb, '-s', serialno, 'forward', 'tcp:%d' % VIEW_SERVER_PORT,
+ subprocess.check_call([adb, '-s', self.serialno, 'forward', 'tcp:%d' % VIEW_SERVER_PORT,
'tcp:%d' % VIEW_SERVER_PORT])
self.device = device
@@ -690,6 +691,13 @@ def __init__(self, device, adb=os.path.join(ANDROID_HOME, 'platform-tools', ADB)
self.dump()
@staticmethod
+ def __mapSerialNo(serialno):
+ ipRE = re.compile('\d+\.\d+.\d+.\d+')
+ if ipRE.match(serialno):
+ serialno += ':5555'
+ return serialno
+
+ @staticmethod
def connectToDeviceOrExit(timeout=60):
'''
Connects to a device which serial number is obtained from the script arguments if available
@@ -770,6 +778,7 @@ def setViews(self, received):
''' The list of Views represented as C{str} obtained after splitting it into lines after being received from the server. Done by L{self.setViews()}. '''
if DEBUG:
print >>sys.stderr, "there are %d views in this dump" % len(self.views)
+ self.__parseTree()
def __splitAttrs(self, strArgs, addViewToViewsById=False):
'''
@@ -974,7 +983,6 @@ def dump(self, windowId=-1, sleep=1):
print >>sys.stderr, received
print >>sys.stderr
self.setViews(received)
- self.__parseTree()
if DEBUG_TREE:
self.traverse(self.root)
View
9 AndroidViewClient/tests/com/dtmilano/android/viewclient.py
@@ -146,11 +146,18 @@ def testConstructor(self):
vc = ViewClient(MockDevice(), adb='/usr/bin/true', autodump=False)
self.assertNotEquals(None, vc)
+ def testMapSerialNo(self):
+ vc = ViewClient(MockDevice(), adb='/usr/bin/true', autodump=False, serialno='192.168.1.100')
+ self.assertEqual('192.168.1.100:5555', vc.serialno)
+
+ def testMapSerialNo_emulator(self):
+ vc = ViewClient(MockDevice(), adb='/usr/bin/true', autodump=False, serialno='emulator-5556')
+ self.assertEqual('emulator-5556', vc.serialno)
+
def __mockTree(self, dump=DUMP):
vc = ViewClient(MockDevice(), adb='/usr/bin/true', autodump=False)
self.assertNotEquals(None, vc)
vc.setViews(dump)
- vc.parseTree(vc.views)
return vc
def testRoot(self):

0 comments on commit ca28135

Please sign in to comment.
Something went wrong with that request. Please try again.