Skip to content

Commit 68d3f85

Browse files
committed
Use 'resource-id' value if available.
- Version 5.3.0 - resource-id provides a more descriptive id if available, compared to uinqueId
1 parent ae40fdd commit 68d3f85

3 files changed

Lines changed: 24 additions & 13 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.2.0',
6+
version='5.3.0',
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: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
@author: Diego Torres Milano
1919
'''
2020

21-
__version__ = '5.2.0'
21+
__version__ = '5.3.0'
2222

2323
import sys
2424
import warnings
@@ -444,6 +444,11 @@ def getId(self):
444444
@see: L{getUniqueId()}
445445
'''
446446

447+
try:
448+
return self.map['resource-id']
449+
except:
450+
pass
451+
447452
try:
448453
return self.map[self.idProperty]
449454
except:
@@ -877,13 +882,18 @@ def isClickable(self):
877882
return self.__getattr__('isClickable')()
878883

879884
def variableNameFromId(self):
880-
m = ID_RE.match(self.getUniqueId())
881-
if m:
882-
var = m.group(1)
883-
if m.group(3):
884-
var += m.group(3)
885-
if re.match('^\d', var):
886-
var = 'id_' + var
885+
_id = self.getId()
886+
if _id:
887+
var = _id.replace('.', '_').replace(':', '___').replace('/', '_')
888+
else:
889+
_id = self.getUniqueId()
890+
m = ID_RE.match(_id)
891+
if m:
892+
var = m.group(1)
893+
if m.group(3):
894+
var += m.group(3)
895+
if re.match('^\d', var):
896+
var = 'id_' + var
887897
return var
888898

889899
def writeImageToFile(self, filename, format="PNG"):

AndroidViewClient/tools/culebra

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ ___________________/ /__/ /__/ /__/ /________________________________
1818
1919
'''
2020

21-
__version__ = '5.0.0'
21+
__version__ = '5.3.0'
2222

2323
import re
2424
import sys
@@ -242,9 +242,9 @@ def printFindViewWithContentDescription(view, useregexp):
242242
if autoRegexp.match(contentDescription):
243243
contentDescription = autoRegexp.pattern
244244
break
245-
contentDescription = "re.compile('''%s''')" % contentDescription
245+
contentDescription = "re.compile(u'''%s''')" % contentDescription
246246
else:
247-
contentDescription = "'''%s'''" % contentDescription
247+
contentDescription = "u'''%s'''" % contentDescription
248248
print '%s = %svc.findViewWithContentDescriptionOrRaise(%s)' % (var, prefix, contentDescription)
249249
elif kwargs1[VERBOSE]:
250250
warnings.warn('View with id=%s has no content-description' % view.getUniqueId())
@@ -258,7 +258,8 @@ def printFindViewById(view):
258258
'''
259259

260260
var = variableNameFromIdOrKey(view)
261-
print '%s = %svc.findViewByIdOrRaise("%s")' % (var, prefix, view.getUniqueId())
261+
_id = view.getId() if view.getId() else view.getUniqueId()
262+
print '%s = %svc.findViewByIdOrRaise("%s")' % (var, prefix, _id)
262263

263264
def traverseAndPrint(view):
264265
'''

0 commit comments

Comments
 (0)