Skip to content

Commit 1b64647

Browse files
committed
Fixed problem with window id as '-1' (str) in dump using ViewServer
- Version 5.6.2 - Corrected tests - Added testFindViewWithTextOrRaise_root_disappearingView - Fixed type problem in culebra
1 parent 1c72574 commit 1b64647

4 files changed

Lines changed: 77 additions & 35 deletions

File tree

AndroidViewClient/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from setuptools import setup, find_packages
44

55
setup(name='androidviewclient',
6-
version='5.6.0',
6+
version='5.6.2',
77
description='''AndroidViewClient is a 100% pure python tool that
88
simplifies test script creation providing higher level operations and the ability of
99
obtaining the tree of Views present at any given moment on the device or emulator screen.

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

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
@author: Diego Torres Milano
1919
'''
2020

21-
__version__ = '5.4.7'
21+
__version__ = '5.6.2'
2222

2323
import sys
2424
import warnings
@@ -1894,33 +1894,36 @@ def dump(self, window=-1, sleep=1):
18941894
self.setViewsFromUiAutomatorDump(received)
18951895
else:
18961896
if isinstance(window, str):
1897-
self.list(sleep=0)
1898-
found = False
1899-
for wId in self.windows:
1900-
try:
1901-
if window == self.windows[wId]:
1902-
window = wId
1903-
found = True
1904-
break
1905-
except:
1906-
pass
1907-
try:
1908-
if int(window) == wId:
1909-
window = wId
1910-
found = True
1911-
break
1912-
except:
1913-
pass
1914-
try:
1915-
if int(window, 16) == wId:
1916-
window = wId
1917-
found = True
1918-
break
1919-
except:
1920-
pass
1921-
1922-
if not found:
1923-
raise RuntimeError("ERROR: Cannot find window '%s' in %s" % (window, self.windows))
1897+
if window != '-1':
1898+
self.list(sleep=0)
1899+
found = False
1900+
for wId in self.windows:
1901+
try:
1902+
if window == self.windows[wId]:
1903+
window = wId
1904+
found = True
1905+
break
1906+
except:
1907+
pass
1908+
try:
1909+
if int(window) == wId:
1910+
window = wId
1911+
found = True
1912+
break
1913+
except:
1914+
pass
1915+
try:
1916+
if int(window, 16) == wId:
1917+
window = wId
1918+
found = True
1919+
break
1920+
except:
1921+
pass
1922+
1923+
if not found:
1924+
raise RuntimeError("ERROR: Cannot find window '%s' in %s" % (window, self.windows))
1925+
else:
1926+
window = -1
19241927

19251928
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
19261929
try:

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

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,18 +310,28 @@ def testConnectToDeviceOrExit_environ(self):
310310
try:
311311
ViewClient.connectToDeviceOrExit(timeout=1, verbose=True)
312312
except RuntimeError, e:
313-
self.assertTrue(re.search("couldn't find device that matches 'ABC123'", str(e)))
313+
msg = str(e)
314+
if re.search('Is adb running on your computer?', msg):
315+
# This test required adb running
316+
self.fail(msg)
317+
elif not re.search("couldn't find device that matches 'ABC123'", msg):
318+
self.fail(msg)
314319
except exceptions.SystemExit, e:
315320
self.assertEquals(3, e.code)
316321
except Exception, e: #FIXME: java.lang.NullPointerException:
317-
self.fail('Serialno was not taken from environment: ' + str(e))
322+
self.fail('Serialno was not taken from environment: ' + msg)
318323

319324
def testConnectToDeviceOrExit_serialno(self):
320325
sys.argv = ['']
321326
try:
322327
ViewClient.connectToDeviceOrExit(timeout=1, verbose=True, serialno='ABC123')
323328
except RuntimeError, e:
324-
self.assertTrue(re.search("couldn't find device that matches 'ABC123'", str(e)))
329+
msg = str(e)
330+
if re.search('Is adb running on your computer?', msg):
331+
# This test required adb running
332+
self.fail(msg)
333+
elif not re.search("couldn't find device that matches 'ABC123'", msg):
334+
self.fail(msg)
325335
except exceptions.SystemExit, e:
326336
self.assertEquals(3, e.code)
327337
except Exception, e: #FIXME: java.lang.NullPointerException:
@@ -756,6 +766,35 @@ def testFindViewWithTextOrRaise_root(self):
756766
v5 = vc.findViewWithTextOrRaise('5', root=v3)
757767
self.assertEqual('v35', v5.getTag())
758768

769+
def testFindViewWithTextOrRaise_root_disappearingView(self):
770+
device = None
771+
root = View({'text:mText':'0'}, device)
772+
root.add(View({'text:mText':'1'}, device))
773+
root.add(View({'text:mText':'2'}, device))
774+
v3 = View({'text:mText':'3'}, device)
775+
root.add(v3)
776+
v35 = View({'text:mText':'5', 'getTag()':'v35'}, device)
777+
v3.add(v35)
778+
v4 = View({'text:mText':'4'}, device)
779+
root.add(v4)
780+
v45 = View({'text:mText':'5', 'getTag()':'v45'}, device)
781+
v4.add(v45)
782+
device = MockDevice()
783+
vc = ViewClient(device, device.serialno, adb=TRUE, autodump=False)
784+
self.assertNotEquals(None, vc)
785+
vc.root = root
786+
v5 = vc.findViewWithTextOrRaise('5')
787+
self.assertEqual('v35', v5.getTag())
788+
v5 = vc.findViewWithTextOrRaise('5', root=v4)
789+
self.assertEqual('v45', v5.getTag())
790+
v5 = vc.findViewWithTextOrRaise('5', root=v3)
791+
self.assertEqual('v35', v5.getTag())
792+
# Then remove v4 and its children
793+
root.children.remove(v4)
794+
#vc.dump()
795+
v4 = vc.findViewWithText('4')
796+
self.assertEqual(v4, None, "v4 has not disappeared")
797+
759798
def testFindViewWithTextOrRaise_rootNonExistent(self):
760799
device = None
761800
root = View({'text:mText':'0'}, device)

AndroidViewClient/tools/culebra

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ ___________________/ /__/ /__/ /__/ /________________________________
1919
2020
'''
2121

22-
__version__ = '5.6.0'
22+
__version__ = '5.6.1'
2323

2424
import re
2525
import sys
@@ -263,9 +263,9 @@ def printFindViewWithText(view, useregexp):
263263
if autoRegexp.match(text):
264264
text = autoRegexp.pattern
265265
break
266-
text = "re.compile(%c'%s')" % (u, text)
266+
text = "re.compile(%s'%s')" % (u, text)
267267
else:
268-
text = "%c'%s'" % (u, text)
268+
text = "%s'%s'" % (u, text)
269269
print '%s%s = vc.findViewWithTextOrRaise(%s)' % (indent, var, text)
270270
elif kwargs1[VERBOSE]:
271271
warnings.warn('View with id=%s has no text' % view.getUniqueId())

0 commit comments

Comments
 (0)