Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' of https://github.com/dtmilano/AndroidViewClient

  • Loading branch information...
commit dad25bd599d76cda53de20bc2cc66aa228f9b9b6 2 parents 797f707 + 4290172
@dtmilano authored
View
48 AndroidViewClient/src/com/dtmilano/android/viewclient.py
@@ -17,7 +17,7 @@
@author: diego
'''
-__version__ = '2.3.9'
+__version__ = '2.3.10'
import sys
import subprocess
@@ -37,7 +37,7 @@
DEBUG_RECEIVED = DEBUG and False
DEBUG_TREE = DEBUG and False
DEBUG_GETATTR = DEBUG and False
-DEBUG_COORDS = DEBUG and False
+DEBUG_COORDS = DEBUG and True
DEBUG_TOUCH = DEBUG and False
DEBUG_STATUSBAR = DEBUG and False
DEBUG_WINDOWS = DEBUG and False
@@ -73,6 +73,10 @@
TEXT_PROPERTY_API_10 = 'mText'
TEXT_PROPERTY_UI_AUTOMATOR = 'text'
WS = "\xfe" # the whitespace replacement char for TEXT_PROPERTY
+LEFT_PROPERTY = 'layout:mLeft'
+LEFT_PROPERTY_API_8 = 'mLeft'
+TOP_PROPERTY = 'layout:mTop'
+TOP_PROPERTY_API_8 = 'mTop'
GET_VISIBILITY_PROPERTY = 'getVisibility()'
LAYOUT_TOP_MARGIN_PROPERTY = 'layout:layout_topMargin'
@@ -231,21 +235,45 @@ def __init__(self, map, device, version=-1, forceviewserveruse=False):
''' The id property depending on the View attribute format '''
self.textProperty = None
''' The text property depending on the View attribute format '''
+ self.leftProperty = None
+ ''' The left property depending on the View attribute format '''
+ self.topProperty = None
+ ''' The top property depending on the View attribute format '''
if version >= 16 and self.useUiAutomator:
self.idProperty = ID_PROPERTY_UI_AUTOMATOR
self.textProperty = TEXT_PROPERTY_UI_AUTOMATOR
+ self.leftProperty = LEFT_PROPERTY
+ self.topProperty = TOP_PROPERTY
elif version > 10 and (version < 16 or self.useUiAutomator):
self.idProperty = ID_PROPERTY
self.textProperty = TEXT_PROPERTY
- elif version > 0 and version <= 10:
+ self.leftProperty = LEFT_PROPERTY
+ self.topProperty = TOP_PROPERTY
+ elif version == 10:
self.idProperty = ID_PROPERTY
self.textProperty = TEXT_PROPERTY_API_10
+ self.leftProperty = LEFT_PROPERTY
+ self.topProperty = TOP_PROPERTY
+ elif version >= 8 and version < 10:
+ self.idProperty = ID_PROPERTY
+ self.textProperty = TEXT_PROPERTY_API_10
+ self.leftProperty = LEFT_PROPERTY_API_8
+ self.topProperty = TOP_PROPERTY_API_8
+ elif version > 0 and version < 8:
+ self.idProperty = ID_PROPERTY
+ self.textProperty = TEXT_PROPERTY_API_10
+ self.leftProperty = LEFT_PROPERTY
+ self.topProperty = TOP_PROPERTY
elif version == -1:
self.idProperty = ID_PROPERTY
self.textProperty = TEXT_PROPERTY
+ self.leftProperty = LEFT_PROPERTY
+ self.topProperty = TOP_PROPERTY
else:
self.idProperty = ID_PROPERTY
self.textProperty = TEXT_PROPERTY
+ self.leftProperty = LEFT_PROPERTY
+ self.topProperty = TOP_PROPERTY
def __getitem__(self, key):
return self.map[key]
@@ -408,10 +436,11 @@ def getX(self):
else:
try:
if GET_VISIBILITY_PROPERTY in self.map and self.map[GET_VISIBILITY_PROPERTY] == 'VISIBLE':
- if DEBUG_COORDS: print >>sys.stderr, " getX: VISIBLE adding %d" % int(self.map['layout:mLeft'])
- x += int(self.map['layout:mLeft'])
+ _x = int(self.map[self.leftProperty])
+ if DEBUG_COORDS: print >>sys.stderr, " getX: VISIBLE adding %d" % _x
+ x += _x
except:
- warnings.warn("View %s has no 'layout:mLeft' property" % self.getId())
+ warnings.warn("View %s has no '%s' property" % (self.getId(), self.leftProperty))
if DEBUG_COORDS: print >>sys.stderr, " getX: returning %d" % (x)
return x
@@ -430,10 +459,11 @@ def getY(self):
else:
try:
if GET_VISIBILITY_PROPERTY in self.map and self.map[GET_VISIBILITY_PROPERTY] == 'VISIBLE':
- if DEBUG_COORDS: print >>sys.stderr, " getY: VISIBLE adding %d" % int(self.map['layout:mTop'])
- y += int(self.map['layout:mTop'])
+ _y = int(self.map[self.topProperty])
+ if DEBUG_COORDS: print >>sys.stderr, " getY: VISIBLE adding %d" % _y
+ y += _y
except:
- warnings.warn("View %s has no 'layout:mTop' property" % self.getId())
+ warnings.warn("View %s has no '%s' property" % (self.getId(), self.topProperty))
if DEBUG_COORDS: print >>sys.stderr, " getY: returning %d" % (y)
return y
View
2  AndroidViewClient/tests/com/dtmilano/android/mocks.py
@@ -123,6 +123,8 @@
VIEW_MAP = {'padding:mUserPaddingRight': '12', 'drawing:getSolidColor()': '0', 'getFilterTouchesWhenObscured()': 'false', 'drawing:isOpaque()': 'false', 'mPrivateFlags_DRAWING_CACHE_INVALID': '0x0', 'focus:isFocusable()': 'true', 'mSystemUiVisibility': '0', 'isSoundEffectsEnabled()': 'true', 'layout:layout_width': 'MATCH_PARENT', 'layout:getWidth()': '1140', 'drawing:isDrawingCacheEnabled()': 'false', 'mPrivateFlags_DRAWN': '0x20', 'text:getSelectionEnd()': '-1', 'getTag()': 'null', 'getEllipsize()': 'null', 'focus:hasFocus()': 'false', 'layout:getResolvedLayoutDirection()': 'RESOLVED_DIRECTION_LTR', 'measurement:mMinWidth': '64', 'padding:mUserPaddingEnd': '-1', 'isFocusableInTouchMode()': 'false', 'text:mTextDirection': 'INHERIT', 'isHovered()': 'false', 'layout:layout_leftMargin': '50', 'layout:layout_endMargin': '-2147483648', 'padding:mPaddingBottom': '4', 'measurement:mMeasuredHeight': '48', 'layout:getLayoutDirection()': 'INHERIT', 'layout:mBottom': '364', 'mSystemUiVisibility_SYSTEM_UI_FLAG_VISIBLE': '0x0', 'layout:layout_startMargin': '-2147483648', 'class': 'android.widget.ToggleButton', 'text:mText': 'Button with ID', 'padding:mPaddingRight': '12', 'mPrivateFlags': '-2130704336', 'layout:layout_bottomMargin': '10', 'layout:layout_height': 'WRAP_CONTENT', 'uniqueId': 'id/button_with_id', 'focus:isFocused()': 'false', 'measurement:mMeasuredWidth': '1140', 'padding:mUserPaddingRelative': 'false', 'text:getSelectionStart()': '-1', 'mViewFlags': '-1744814079', 'isClickable()': 'true', 'getScrollBarStyle()': 'INSIDE_OVERLAY', 'layout:layout_rightMargin': '50', 'padding:mUserPaddingLeft': '12', 'oid': 'b4781818', 'layout:getBaseline()': '29', 'isEnabled()': 'true', 'isChecked()': 'false', 'drawing:mLayerType': 'NONE', 'drawing:willNotDraw()': 'false', 'layout:mRight': '1190', 'drawing:willNotCacheDrawing()': 'false', 'layout:mTop': '316', 'isHapticFeedbackEnabled()': 'true', 'getVisibility()': 'VISIBLE', 'scrolling:mScrollX': '0', 'text:mResolvedTextDirection': 'FIRST_STRONG', 'isInTouchMode()': 'true', 'padding:mPaddingTop': '4', 'layout:layout_weight': '0.0', 'measurement:mMinHeight': '48', 'mID': 'id/button_with_id', 'layout:layout_topMargin': '50', 'padding:mUserPaddingStart': '-1', 'padding:mPaddingLeft': '12', 'isSelected()': 'false', 'isActivated()': 'false', 'padding:mUserPaddingBottom': '4', 'layout:layout_gravity': 'NONE', 'layout:mLeft': '50', 'layout:isLayoutRtl()': 'false', 'layout:getHeight()': '48', 'scrolling:mScrollY': '0'}
+VIEW_MAP_API_8 = {'padding:mUserPaddingRight': '12', 'drawing:getSolidColor()': '0', 'getFilterTouchesWhenObscured()': 'false', 'drawing:isOpaque()': 'false', 'mPrivateFlags_DRAWING_CACHE_INVALID': '0x0', 'focus:isFocusable()': 'true', 'mSystemUiVisibility': '0', 'isSoundEffectsEnabled()': 'true', 'layout:layout_width': 'MATCH_PARENT', 'layout:getWidth()': '1140', 'drawing:isDrawingCacheEnabled()': 'false', 'mPrivateFlags_DRAWN': '0x20', 'text:getSelectionEnd()': '-1', 'getTag()': 'null', 'getEllipsize()': 'null', 'focus:hasFocus()': 'false', 'layout:getResolvedLayoutDirection()': 'RESOLVED_DIRECTION_LTR', 'measurement:mMinWidth': '64', 'padding:mUserPaddingEnd': '-1', 'isFocusableInTouchMode()': 'false', 'text:mTextDirection': 'INHERIT', 'isHovered()': 'false', 'layout:layout_leftMargin': '50', 'layout:layout_endMargin': '-2147483648', 'padding:mPaddingBottom': '4', 'measurement:mMeasuredHeight': '48', 'layout:getLayoutDirection()': 'INHERIT', 'layout:mBottom': '364', 'mSystemUiVisibility_SYSTEM_UI_FLAG_VISIBLE': '0x0', 'layout:layout_startMargin': '-2147483648', 'class': 'android.widget.ToggleButton', 'text:mText': 'Button with ID', 'padding:mPaddingRight': '12', 'mPrivateFlags': '-2130704336', 'layout:layout_bottomMargin': '10', 'layout:layout_height': 'WRAP_CONTENT', 'uniqueId': 'id/button_with_id', 'focus:isFocused()': 'false', 'measurement:mMeasuredWidth': '1140', 'padding:mUserPaddingRelative': 'false', 'text:getSelectionStart()': '-1', 'mViewFlags': '-1744814079', 'isClickable()': 'true', 'getScrollBarStyle()': 'INSIDE_OVERLAY', 'layout:layout_rightMargin': '50', 'padding:mUserPaddingLeft': '12', 'oid': 'b4781818', 'layout:getBaseline()': '29', 'isEnabled()': 'true', 'isChecked()': 'false', 'drawing:mLayerType': 'NONE', 'drawing:willNotDraw()': 'false', 'layout:mRight': '1190', 'drawing:willNotCacheDrawing()': 'false', 'mTop': '316', 'isHapticFeedbackEnabled()': 'true', 'getVisibility()': 'VISIBLE', 'scrolling:mScrollX': '0', 'text:mResolvedTextDirection': 'FIRST_STRONG', 'isInTouchMode()': 'true', 'padding:mPaddingTop': '4', 'layout:layout_weight': '0.0', 'measurement:mMinHeight': '48', 'mID': 'id/button_with_id', 'layout:layout_topMargin': '50', 'padding:mUserPaddingStart': '-1', 'padding:mPaddingLeft': '12', 'isSelected()': 'false', 'isActivated()': 'false', 'padding:mUserPaddingBottom': '4', 'layout:layout_gravity': 'NONE', 'mLeft': '50', 'layout:isLayoutRtl()': 'false', 'layout:getHeight()': '48', 'scrolling:mScrollY': '0'}
+
DUMPSYS_WINDOW_WINDOWS = """
mock data
mock data
View
66 AndroidViewClient/tests/com/dtmilano/android/viewclient.py
@@ -27,7 +27,7 @@
from com.dtmilano.android.viewclient import *
from mocks import MockDevice
-from mocks import DUMP, DUMP_SAMPLE_UI, VIEW_MAP, RUNNING, STOPPED
+from mocks import DUMP, DUMP_SAMPLE_UI, VIEW_MAP, VIEW_MAP_API_8, RUNNING, STOPPED
# this is probably the only reliable way of determining the OS in monkeyrunner
os_name = java.lang.System.getProperty('os.name')
@@ -67,6 +67,10 @@ def testView_notSpecifiedSdkVersion(self):
view = View(VIEW_MAP, device, -1)
self.assertEqual(device.version, view.build[VERSION_SDK_PROPERTY])
+ def testView_specifiedSdkVersion_8(self):
+ view = View(VIEW_MAP_API_8, MockDevice(), 8)
+ self.assertEqual(8, view.build[VERSION_SDK_PROPERTY])
+
def testView_specifiedSdkVersion_10(self):
view = View(VIEW_MAP, MockDevice(), 10)
self.assertEqual(10, view.build[VERSION_SDK_PROPERTY])
@@ -98,23 +102,69 @@ def testGetId(self):
self.assertEqual('id/button_with_id', self.view.getId())
def testTextPropertyForDifferentSdkVersions(self):
- VTP = { -1:TEXT_PROPERTY, 8:TEXT_PROPERTY_API_10, 10:TEXT_PROPERTY_API_10, 15:TEXT_PROPERTY, 16:TEXT_PROPERTY_UI_AUTOMATOR, 17:TEXT_PROPERTY_UI_AUTOMATOR}
- for version, textProperty in VTP.items():
+ VP = { -1:TEXT_PROPERTY, 8:TEXT_PROPERTY_API_10, 10:TEXT_PROPERTY_API_10, 15:TEXT_PROPERTY, 16:TEXT_PROPERTY_UI_AUTOMATOR, 17:TEXT_PROPERTY_UI_AUTOMATOR}
+ for version, textProperty in VP.items():
view = View(None, None, version)
- self.assertEqual(textProperty, view.textProperty, msg='version %d' % version)
+ self.assertEqual(textProperty, view.textProperty, msg='version %d: expected: %s actual: %s' % (version, textProperty, view.textProperty))
def testTextPropertyForDifferentSdkVersions_device(self):
- VTP = { -1:TEXT_PROPERTY, 8:TEXT_PROPERTY_API_10, 10:TEXT_PROPERTY_API_10, 15:TEXT_PROPERTY, 16:TEXT_PROPERTY_UI_AUTOMATOR, 17:TEXT_PROPERTY_UI_AUTOMATOR}
- for version, textProperty in VTP.items():
+ VP = { -1:TEXT_PROPERTY, 8:TEXT_PROPERTY_API_10, 10:TEXT_PROPERTY_API_10, 15:TEXT_PROPERTY, 16:TEXT_PROPERTY_UI_AUTOMATOR, 17:TEXT_PROPERTY_UI_AUTOMATOR}
+ for version, textProperty in VP.items():
device = MockDevice(version=version)
view = View(None, device, -1)
self.assertEqual(textProperty, view.textProperty, msg='version %d' % version)
-
+
+ def testLeftPropertyForDifferentSdkVersions(self):
+ VP = { -1:LEFT_PROPERTY, 8:LEFT_PROPERTY_API_8, 10:LEFT_PROPERTY, 15:LEFT_PROPERTY, 16:LEFT_PROPERTY, 17:LEFT_PROPERTY}
+ for version, leftProperty in VP.items():
+ view = View(None, None, version)
+ self.assertEqual(leftProperty, view.leftProperty, msg='version %d' % version)
+
+ def testLeftPropertyForDifferentSdkVersions_device(self):
+ VP = { -1:LEFT_PROPERTY, 8:LEFT_PROPERTY_API_8, 10:LEFT_PROPERTY, 15:LEFT_PROPERTY, 16:LEFT_PROPERTY, 17:LEFT_PROPERTY}
+ for version, leftProperty in VP.items():
+ device = MockDevice(version=version)
+ view = View(None, device, -1)
+ self.assertEqual(leftProperty, view.leftProperty, msg='version %d' % version)
+
+ def testTopPropertyForDifferentSdkVersions(self):
+ VP = { -1:TOP_PROPERTY, 8:TOP_PROPERTY_API_8, 10:TOP_PROPERTY, 15:TOP_PROPERTY, 16:TOP_PROPERTY, 17:TOP_PROPERTY}
+ for version, topProperty in VP.items():
+ view = View(None, None, version)
+ self.assertEqual(topProperty, view.topProperty, msg='version %d' % version)
+
+ def testTopPropertyForDifferentSdkVersions_device(self):
+ VP = { -1:TOP_PROPERTY, 8:TOP_PROPERTY_API_8, 10:TOP_PROPERTY, 15:TOP_PROPERTY, 16:TOP_PROPERTY, 17:TOP_PROPERTY}
+ for version, topProperty in VP.items():
+ device = MockDevice(version=version)
+ view = View(None, device, -1)
+ self.assertEqual(topProperty, view.topProperty, msg='version %d' % version)
+
def testGetText(self):
self.assertTrue(self.view.map.has_key('text:mText'))
self.assertEqual('Button with ID', self.view.getText())
self.assertEqual('Button with ID', self.view['text:mText'])
-
+
+ def testGetX_specifiedSdkVersion_8(self):
+ view = View(VIEW_MAP_API_8, MockDevice(), 8)
+ self.assertEqual(8, view.build[VERSION_SDK_PROPERTY])
+ self.assertEqual(50, view.getX())
+
+ def testGetX_specifiedSdkVersion_10(self):
+ view = View(VIEW_MAP, MockDevice(), 10)
+ self.assertEqual(10, view.build[VERSION_SDK_PROPERTY])
+ self.assertEqual(50, view.getX())
+
+ def testGetY_specifiedSdkVersion_8(self):
+ view = View(VIEW_MAP_API_8, MockDevice(), 8)
+ self.assertEqual(8, view.build[VERSION_SDK_PROPERTY])
+ self.assertEqual(316, view.getY())
+
+ def testGetY_specifiedSdkVersion_10(self):
+ view = View(VIEW_MAP, MockDevice(), 10)
+ self.assertEqual(10, view.build[VERSION_SDK_PROPERTY])
+ self.assertEqual(316, view.getY())
+
def testGetWidth(self):
self.assertEqual(1140, self.view.getWidth())
Please sign in to comment.
Something went wrong with that request. Please try again.