123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- 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,
- "textContains": None,
- "textMatches": None,
- "textStartsWith": None,
- "className": None,
- "classNameMatches": None,
- "description": None,
- "descriptionContains": None,
- "descriptionMatches": None,
- "descriptionStartsWith": None,
- "checkable": None,
- "checked": None,
- "clickable": None,
- "longClickable": None,
- "scrollable": None,
- "enabled": None,
- "focusable": None,
- "focused": None,
- "selected": None,
- "packageName": None,
- "packageNameMatches": None,
- "resourceId": None,
- "resourceIdMatches": None,
- "index": None,
- "instance": None
- }
- UATParamMap = {
- "text": "text",
- "textContains": "textContains",
- "textMatch": "textMatches",
- "textSWith": "textStartsWith",
- "class": "className",
- "classMatches": "classNameMatches",
- "desc": "description",
- "descContain": "descriptionContains",
- "descMatch": "descriptionMatches",
- "descSWith": "descriptionStartsWith",
- "checkable": "checkable",
- "checked": "checked",
- "clickable": "clickable",
- "lClickable": "longClickable",
- "scrollable": "scrollable",
- "enable": "enabled",
- "focusable": "focusable",
- "focus": "focused",
- "select": "selected",
- "pkg": "packageName",
- "pkgMatch": "packageNameMatches",
- "resid": "resourceId",
- "residMatch": "resourceIdMatches",
- "index": "index",
- "instance": "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:
- 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
|