diff --git a/AndroidViewClient/setup.py b/AndroidViewClient/setup.py index 23e5b649..7d4279aa 100644 --- a/AndroidViewClient/setup.py +++ b/AndroidViewClient/setup.py @@ -3,7 +3,7 @@ from setuptools import setup, find_packages setup(name='androidviewclient', - version='5.6.0', + version='5.6.2', description='''AndroidViewClient is a 100% pure python tool that simplifies test script creation providing higher level operations and the ability of obtaining the tree of Views present at any given moment on the device or emulator screen. diff --git a/AndroidViewClient/src/com/dtmilano/android/viewclient.py b/AndroidViewClient/src/com/dtmilano/android/viewclient.py index 9ca65d98..f6460deb 100644 --- a/AndroidViewClient/src/com/dtmilano/android/viewclient.py +++ b/AndroidViewClient/src/com/dtmilano/android/viewclient.py @@ -18,7 +18,7 @@ @author: Diego Torres Milano ''' -__version__ = '5.4.7' +__version__ = '5.6.2' import sys import warnings @@ -1894,33 +1894,36 @@ def dump(self, window=-1, sleep=1): self.setViewsFromUiAutomatorDump(received) else: if isinstance(window, str): - self.list(sleep=0) - found = False - for wId in self.windows: - try: - if window == self.windows[wId]: - window = wId - found = True - break - except: - pass - try: - if int(window) == wId: - window = wId - found = True - break - except: - pass - try: - if int(window, 16) == wId: - window = wId - found = True - break - except: - pass - - if not found: - raise RuntimeError("ERROR: Cannot find window '%s' in %s" % (window, self.windows)) + if window != '-1': + self.list(sleep=0) + found = False + for wId in self.windows: + try: + if window == self.windows[wId]: + window = wId + found = True + break + except: + pass + try: + if int(window) == wId: + window = wId + found = True + break + except: + pass + try: + if int(window, 16) == wId: + window = wId + found = True + break + except: + pass + + if not found: + raise RuntimeError("ERROR: Cannot find window '%s' in %s" % (window, self.windows)) + else: + window = -1 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: diff --git a/AndroidViewClient/tests/com/dtmilano/android/viewclient.py b/AndroidViewClient/tests/com/dtmilano/android/viewclient.py index 66eee596..debbb0fe 100644 --- a/AndroidViewClient/tests/com/dtmilano/android/viewclient.py +++ b/AndroidViewClient/tests/com/dtmilano/android/viewclient.py @@ -310,18 +310,28 @@ def testConnectToDeviceOrExit_environ(self): try: ViewClient.connectToDeviceOrExit(timeout=1, verbose=True) except RuntimeError, e: - self.assertTrue(re.search("couldn't find device that matches 'ABC123'", str(e))) + msg = str(e) + if re.search('Is adb running on your computer?', msg): + # This test required adb running + self.fail(msg) + elif not re.search("couldn't find device that matches 'ABC123'", msg): + self.fail(msg) except exceptions.SystemExit, e: self.assertEquals(3, e.code) except Exception, e: #FIXME: java.lang.NullPointerException: - self.fail('Serialno was not taken from environment: ' + str(e)) + self.fail('Serialno was not taken from environment: ' + msg) def testConnectToDeviceOrExit_serialno(self): sys.argv = [''] try: ViewClient.connectToDeviceOrExit(timeout=1, verbose=True, serialno='ABC123') except RuntimeError, e: - self.assertTrue(re.search("couldn't find device that matches 'ABC123'", str(e))) + msg = str(e) + if re.search('Is adb running on your computer?', msg): + # This test required adb running + self.fail(msg) + elif not re.search("couldn't find device that matches 'ABC123'", msg): + self.fail(msg) except exceptions.SystemExit, e: self.assertEquals(3, e.code) except Exception, e: #FIXME: java.lang.NullPointerException: @@ -756,6 +766,35 @@ def testFindViewWithTextOrRaise_root(self): v5 = vc.findViewWithTextOrRaise('5', root=v3) self.assertEqual('v35', v5.getTag()) + def testFindViewWithTextOrRaise_root_disappearingView(self): + device = None + root = View({'text:mText':'0'}, device) + root.add(View({'text:mText':'1'}, device)) + root.add(View({'text:mText':'2'}, device)) + v3 = View({'text:mText':'3'}, device) + root.add(v3) + v35 = View({'text:mText':'5', 'getTag()':'v35'}, device) + v3.add(v35) + v4 = View({'text:mText':'4'}, device) + root.add(v4) + v45 = View({'text:mText':'5', 'getTag()':'v45'}, device) + v4.add(v45) + device = MockDevice() + vc = ViewClient(device, device.serialno, adb=TRUE, autodump=False) + self.assertNotEquals(None, vc) + vc.root = root + v5 = vc.findViewWithTextOrRaise('5') + self.assertEqual('v35', v5.getTag()) + v5 = vc.findViewWithTextOrRaise('5', root=v4) + self.assertEqual('v45', v5.getTag()) + v5 = vc.findViewWithTextOrRaise('5', root=v3) + self.assertEqual('v35', v5.getTag()) + # Then remove v4 and its children + root.children.remove(v4) + #vc.dump() + v4 = vc.findViewWithText('4') + self.assertEqual(v4, None, "v4 has not disappeared") + def testFindViewWithTextOrRaise_rootNonExistent(self): device = None root = View({'text:mText':'0'}, device) diff --git a/AndroidViewClient/tools/culebra b/AndroidViewClient/tools/culebra index b720d0ae..483e50d2 100755 --- a/AndroidViewClient/tools/culebra +++ b/AndroidViewClient/tools/culebra @@ -19,7 +19,7 @@ ___________________/ /__/ /__/ /__/ /________________________________ ''' -__version__ = '5.6.0' +__version__ = '5.6.1' import re import sys @@ -263,9 +263,9 @@ def printFindViewWithText(view, useregexp): if autoRegexp.match(text): text = autoRegexp.pattern break - text = "re.compile(%c'%s')" % (u, text) + text = "re.compile(%s'%s')" % (u, text) else: - text = "%c'%s'" % (u, text) + text = "%s'%s'" % (u, text) print '%s%s = vc.findViewWithTextOrRaise(%s)' % (indent, var, text) elif kwargs1[VERBOSE]: warnings.warn('View with id=%s has no text' % view.getUniqueId())