UIParamUtil.py 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. # -*- coding:utf-8 -*-
  2. from UAT_log import error,info,debug
  3. ERROR = True
  4. INFO = True
  5. DEBUG = True
  6. '''
  7. UIObject Info:
  8. {
  9. u 'contentDescription': None,
  10. u 'checked': False,
  11. u 'clickable': True,
  12. u 'scrollable': False,
  13. u 'text': None,
  14. u 'packageName': u 'com.android.tv',
  15. u 'selected': False,
  16. u 'enabled': True,
  17. u 'bounds': {
  18. u 'top': 491,
  19. u 'left': 75,
  20. u 'right': 264,
  21. u 'bottom': 619
  22. },
  23. u 'className': u 'android.widget.RelativeLayout',
  24. u 'focusable': True,
  25. u 'focused': True,
  26. u 'checkable': False,
  27. u 'resourceName': None,
  28. u 'longClickable': False,
  29. u 'visibleBounds': {
  30. u 'top': 491,
  31. u 'left': 75,
  32. u 'right': 264,
  33. u 'bottom': 619
  34. },
  35. u 'childCount': 3
  36. }
  37. UATree中的UI param:
  38. '''
  39. '''
  40. UI界面组件参数的工具类
  41. '''
  42. class UIParamUtil:
  43. UIObjParam = {
  44. "text": None, # MASK_TEXT,
  45. "textContains": None, # MASK_TEXTCONTAINS,
  46. "textMatches": None, # MASK_TEXTMATCHES,
  47. "textStartsWith": None, # MASK_TEXTSTARTSWITH,
  48. "className": None, # MASK_CLASSNAME
  49. "classNameMatches": None, # MASK_CLASSNAMEMATCHES
  50. "description": None, # MASK_DESCRIPTION
  51. "descriptionContains": None, # MASK_DESCRIPTIONCONTAINS
  52. "descriptionMatches": None, # MASK_DESCRIPTIONMATCHES
  53. "descriptionStartsWith": None, # MASK_DESCRIPTIONSTARTSWITH
  54. "checkable": None, # MASK_CHECKABLE
  55. "checked": None, # MASK_CHECKED
  56. "clickable": None, # MASK_CLICKABLE
  57. "longClickable": None, # MASK_LONGCLICKABLE,
  58. "scrollable": None, # MASK_SCROLLABLE,
  59. "enabled": None, # MASK_ENABLED,
  60. "focusable": None, # MASK_FOCUSABLE,
  61. "focused": None, # MASK_FOCUSED,
  62. "selected": None, # MASK_SELECTED,
  63. "packageName": None, # MASK_PACKAGENAME,
  64. "packageNameMatches": None, # MASK_PACKAGENAMEMATCHES,
  65. "resourceId": None, # MASK_RESOURCEID,
  66. "resourceIdMatches": None, # MASK_RESOURCEIDMATCHES,
  67. "index": None, # MASK_INDEX,
  68. "instance": None # MASK_INSTANCE,
  69. }
  70. UATParamMap = {
  71. "text": "text", # MASK_TEXT,
  72. "textContains": "textContains", # MASK_TEXTCONTAINS,
  73. "textMatch": "textMatches", # MASK_TEXTMATCHES,
  74. "textSWith": "textStartsWith", # MASK_TEXTSTARTSWITH,
  75. "class": "className", # MASK_CLASSNAME
  76. "classMatches": "classNameMatches", # MASK_CLASSNAMEMATCHES
  77. "desc": "description", # MASK_DESCRIPTION
  78. "descContain": "descriptionContains", # MASK_DESCRIPTIONCONTAINS
  79. "descMatch": "descriptionMatches", # MASK_DESCRIPTIONMATCHES
  80. "descSWith": "descriptionStartsWith", # MASK_DESCRIPTIONSTARTSWITH
  81. "checkable": "checkable", # MASK_CHECKABLE
  82. "checked": "checked", # MASK_CHECKED
  83. "clickable": "clickable", # MASK_CLICKABLE
  84. "lClickable": "longClickable", # MASK_LONGCLICKABLE,
  85. "scrollable": "scrollable", # MASK_SCROLLABLE,
  86. "enable": "enabled", # MASK_ENABLED,
  87. "focusable": "focusable", # MASK_FOCUSABLE,
  88. "focus": "focused", # MASK_FOCUSED,
  89. "select": "selected", # MASK_SELECTED,
  90. "pkg": "packageName", # MASK_PACKAGENAME,
  91. "pkgMatch": "packageNameMatches", # MASK_PACKAGENAMEMATCHES,
  92. "resid": "resourceId", # MASK_RESOURCEID,
  93. "residMatch": "resourceIdMatches", # MASK_RESOURCEIDMATCHES,
  94. "index": "index", # MASK_INDEX,
  95. "instance": "instance" # MASK_INSTANCE,
  96. }
  97. cls = "UIObjParam"
  98. def __init__(self):
  99. pass
  100. '''
  101. 将atx抓取到的bounds字典:'visibleBounds': {
  102. u 'top': 491,
  103. u 'left': 75,
  104. u 'right': 264,
  105. u 'bottom': 619
  106. }
  107. 转换成UATree格式的:
  108. [[75,491][264,619]]
  109. '''
  110. @staticmethod
  111. def atxBounds2UATBounds(atxBounds):
  112. try:
  113. bounds = [[atxBounds['left'], atxBounds['top']], [atxBounds['right'], atxBounds['bottom']]]
  114. except Exception,e:
  115. error(self.cls, "atxBounds2UATBounds", "atxBounds has error format:"+str(atxBounds),ERROR)
  116. bounds=[]
  117. return bounds
  118. ''''
  119. UATree格式的:[[75,491][264,619]]
  120. 转换成:
  121. atx抓取到的bounds字典:'visibleBounds': {
  122. u 'top': 491,
  123. u 'left': 75,
  124. u 'right': 264,
  125. u 'bottom': 619
  126. }
  127. '''
  128. @staticmethod
  129. def uatBounds2ATXBounds(uatBounds):
  130. bounds = {}
  131. try:
  132. bounds['left'] = uatBounds[0][0]
  133. bounds["top"] = uatBounds[0][1]
  134. bounds['right'] = uatBounds[1][0]
  135. bounds['bottom'] = uatBounds[1][1]
  136. except Exception,e:
  137. error(self.cls, "uatBounds2ATXBounds", "uatBounds has error format:"+str(uatBounds),ERROR)
  138. bounds={}
  139. return bounds
  140. '''
  141. 根据传入的uat界面界面参数(例如:optionView、UIView),转换成UIObject参数
  142. 参数均用字典存储。
  143. '''
  144. @staticmethod
  145. def setObjParam(uatObjParam):
  146. uiObjParam = {}
  147. if uatObjParam is None:
  148. return uiObjParam
  149. for uatKey in uatObjParam:
  150. uatParam = uatObjParam[uatKey]
  151. if UIParamUtil.UATParamMap.has_key(uatKey) and uatParam is not None and str(uatParam).__len__() > 0:
  152. uiObjParam[UIParamUtil.UATParamMap[uatKey]] = uatParam
  153. return uiObjParam
  154. '''
  155. 比对两个UIObject参数,是否一样,采用字典逐个比对方式。
  156. objParam1, objParam2必须是同一中字典格式
  157. return :True/False. True表示相同,False标识不同
  158. '''
  159. @staticmethod
  160. def cmpObjParam(objParam1, objParam2):
  161. for key in objParam1:
  162. if "sambounds" == key: #sambounds只用于相对位置计算,不做重复考虑
  163. break
  164. try:
  165. value1 = objParam1[key]
  166. value2 = objParam2[key]
  167. if value1 <> value2:
  168. return False
  169. except Exception,e:
  170. error(self.cls, "cmpObjParam", "objParam1 and objParam2 are different", ERROR)
  171. return False
  172. return True