Skip to content

Commit

Permalink
Fixed problem with window id as '-1' (str) in dump using ViewServer
Browse files Browse the repository at this point in the history
- Version 5.6.2
- Corrected tests
- Added testFindViewWithTextOrRaise_root_disappearingView
- Fixed type problem in culebra
  • Loading branch information
dtmilano committed May 21, 2014
1 parent 1c72574 commit 1b64647
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 35 deletions.
2 changes: 1 addition & 1 deletion AndroidViewClient/setup.py
Expand Up @@ -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.
Expand Down
59 changes: 31 additions & 28 deletions AndroidViewClient/src/com/dtmilano/android/viewclient.py
Expand Up @@ -18,7 +18,7 @@
@author: Diego Torres Milano
'''

__version__ = '5.4.7'
__version__ = '5.6.2'

import sys
import warnings
Expand Down Expand Up @@ -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:
Expand Down
45 changes: 42 additions & 3 deletions AndroidViewClient/tests/com/dtmilano/android/viewclient.py
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions AndroidViewClient/tools/culebra
Expand Up @@ -19,7 +19,7 @@ ___________________/ /__/ /__/ /__/ /________________________________
'''

__version__ = '5.6.0'
__version__ = '5.6.1'

import re
import sys
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit 1b64647

Please sign in to comment.