# -*- coding:utf-8 -*- from UAT_log import error,info,debug ERROR = True INFO = True DEBUG = True ''' UIObject Info: { u 'contentDescription': None, u 'checked': False, u 'clickable': True, u 'scrollable': False, u 'text': None, u 'packageName': u 'com.android.tv', u 'selected': False, u 'enabled': True, u 'bounds': { u 'top': 491, u 'left': 75, u 'right': 264, u 'bottom': 619 }, u 'className': u 'android.widget.RelativeLayout', u 'focusable': True, u 'focused': True, u 'checkable': False, u 'resourceName': None, u 'longClickable': False, u 'visibleBounds': { u 'top': 491, u 'left': 75, u 'right': 264, u 'bottom': 619 }, u 'childCount': 3 } UATree中的UI param: ''' ''' UI界面组件参数的工具类 ''' class UIParamUtil: UIObjParam = { "text": None, # MASK_TEXT, "textContains": None, # MASK_TEXTCONTAINS, "textMatches": None, # MASK_TEXTMATCHES, "textStartsWith": None, # MASK_TEXTSTARTSWITH, "className": None, # MASK_CLASSNAME "classNameMatches": None, # MASK_CLASSNAMEMATCHES "description": None, # MASK_DESCRIPTION "descriptionContains": None, # MASK_DESCRIPTIONCONTAINS "descriptionMatches": None, # MASK_DESCRIPTIONMATCHES "descriptionStartsWith": None, # MASK_DESCRIPTIONSTARTSWITH "checkable": None, # MASK_CHECKABLE "checked": None, # MASK_CHECKED "clickable": None, # MASK_CLICKABLE "longClickable": None, # MASK_LONGCLICKABLE, "scrollable": None, # MASK_SCROLLABLE, "enabled": None, # MASK_ENABLED, "focusable": None, # MASK_FOCUSABLE, "focused": None, # MASK_FOCUSED, "selected": None, # MASK_SELECTED, "packageName": None, # MASK_PACKAGENAME, "packageNameMatches": None, # MASK_PACKAGENAMEMATCHES, "resourceId": None, # MASK_RESOURCEID, "resourceIdMatches": None, # MASK_RESOURCEIDMATCHES, "index": None, # MASK_INDEX, "instance": None # MASK_INSTANCE, } UATParamMap = { "text": "text", # MASK_TEXT, "textContains": "textContains", # MASK_TEXTCONTAINS, "textMatch": "textMatches", # MASK_TEXTMATCHES, "textSWith": "textStartsWith", # MASK_TEXTSTARTSWITH, "class": "className", # MASK_CLASSNAME "classMatches": "classNameMatches", # MASK_CLASSNAMEMATCHES "desc": "description", # MASK_DESCRIPTION "descContain": "descriptionContains", # MASK_DESCRIPTIONCONTAINS "descMatch": "descriptionMatches", # MASK_DESCRIPTIONMATCHES "descSWith": "descriptionStartsWith", # MASK_DESCRIPTIONSTARTSWITH "checkable": "checkable", # MASK_CHECKABLE "checked": "checked", # MASK_CHECKED "clickable": "clickable", # MASK_CLICKABLE "lClickable": "longClickable", # MASK_LONGCLICKABLE, "scrollable": "scrollable", # MASK_SCROLLABLE, "enable": "enabled", # MASK_ENABLED, "focusable": "focusable", # MASK_FOCUSABLE, "focus": "focused", # MASK_FOCUSED, "select": "selected", # MASK_SELECTED, "pkg": "packageName", # MASK_PACKAGENAME, "pkgMatch": "packageNameMatches", # MASK_PACKAGENAMEMATCHES, "resid": "resourceId", # MASK_RESOURCEID, "residMatch": "resourceIdMatches", # MASK_RESOURCEIDMATCHES, "index": "index", # MASK_INDEX, "instance": "instance" # MASK_INSTANCE, } global cls cls = "UIObjParam" def __init__(self): pass ''' 将atx抓取到的bounds字典:'visibleBounds': { u 'top': 491, u 'left': 75, u 'right': 264, u 'bottom': 619 } 转换成UATree格式的: [[75,491][264,619]] ''' @staticmethod def atxBounds2UATBounds(atxBounds): try: bounds = [[atxBounds['left'], atxBounds['top']], [atxBounds['right'], atxBounds['bottom']]] except Exception,e: error(self.cls, "atxBounds2UATBounds", "atxBounds has error format:"+str(atxBounds),ERROR) bounds=[] return bounds '''' UATree格式的:[[75,491][264,619]] 转换成: atx抓取到的bounds字典:'visibleBounds': { u 'top': 491, u 'left': 75, u 'right': 264, u 'bottom': 619 } ''' @staticmethod def uatBounds2ATXBounds(uatBounds): bounds = {} try: bounds['left'] = uatBounds[0][0] bounds["top"] = uatBounds[0][1] bounds['right'] = uatBounds[1][0] bounds['bottom'] = uatBounds[1][1] except Exception,e: error(cls, "uatBounds2ATXBounds", "uatBounds has error format:"+str(uatBounds),ERROR) bounds={} return bounds ''' 根据传入的uat界面界面参数(例如:optionView、UIView),转换成UIObject参数 参数均用字典存储。 ''' @staticmethod def setObjParam(uatObjParam): uiObjParam = {} if uatObjParam is None: return uiObjParam for uatKey in uatObjParam: uatParam = uatObjParam[uatKey] if UIParamUtil.UATParamMap.has_key(uatKey) and uatParam is not None and str(uatParam).__len__() > 0: uiObjParam[UIParamUtil.UATParamMap[uatKey]] = uatParam return uiObjParam ''' 比对两个UIObject参数,是否一样,采用字典逐个比对方式。 objParam1, objParam2必须是同一中字典格式 return :True/False. True表示相同,False标识不同 ''' @staticmethod def cmpObjParam(objParam1, objParam2): for key in objParam1: if "sambounds" == key: #sambounds只用于相对位置计算,不做重复考虑 break try: value1 = objParam1[key] value2 = objParam2[key] if value1 <> value2: return False except Exception,e: error(cls, "cmpObjParam", "objParam1 and objParam2 are different", ERROR) return False return True