|
@@ -41,7 +41,7 @@ self.pyUIAutomator = PyUIAutomator()
|
|
|
class PyUIAutomator():
|
|
|
def __init__(self, serial=None):
|
|
|
try:
|
|
|
- self.u = u2.connect_usb(serial)
|
|
|
+ self.u = u2.connect_usb(serial)
|
|
|
self.serial = serial
|
|
|
except Exception,e:
|
|
|
print e
|
|
@@ -98,6 +98,18 @@ class PyUIAutomator():
|
|
|
self.listenAdbConnected()
|
|
|
self.u.pressKeyTimes(key, times, duration)
|
|
|
|
|
|
+ '''
|
|
|
+ 用uiautomator view属性键作为paramDIct的键,传入的paramDict里的参数,必须有效。
|
|
|
+ 参考session.Selector里的__fields字典
|
|
|
+ '''
|
|
|
+ def getUiObject2(self, paramDict):
|
|
|
+
|
|
|
+ uiObject = None
|
|
|
+ if paramDict.__len__>0:
|
|
|
+ uiObject = self.u(**paramDict)
|
|
|
+
|
|
|
+ return uiObject
|
|
|
+
|
|
|
'''
|
|
|
作用:获取UiObject对象
|
|
|
参数:
|
|
@@ -120,7 +132,7 @@ class PyUIAutomator():
|
|
|
|
|
|
'''
|
|
|
|
|
|
- def getUiObject(self, className='', resourceId='', text='', description='', instance=-1):
|
|
|
+ def getUiObject(self, className='', resourceId='', text='', description='', bounds='', instance=-1):
|
|
|
self.listenAdbConnected()
|
|
|
|
|
|
|
|
@@ -131,117 +143,260 @@ class PyUIAutomator():
|
|
|
uiObject = None
|
|
|
try:
|
|
|
|
|
|
- if className == "" and resourceId == "" and text == "" and description == "" and instance == -1:
|
|
|
+ if className == "" and resourceId == "" and text == "" and description == "" and \
|
|
|
+ bounds == "" and instance == -1:
|
|
|
print "没有参数带入,找不到对象"
|
|
|
return uiObject
|
|
|
|
|
|
- if className != "" and resourceId != "" and text != "" and description != "" and instance != -1:
|
|
|
+ if className != "" and resourceId != "" and text != "" and description != "" and \
|
|
|
+ bounds != "" and instance != -1:
|
|
|
uiObject = self.u(className=className, resourceId=resourceId, text=text, description=description,
|
|
|
- instance=instance)
|
|
|
+ bounds=bounds, instance=instance)
|
|
|
|
|
|
- if className != "" and resourceId != "" and text != "" and description != "" and instance == -1:
|
|
|
- uiObject = self.u(className=className, resourceId=resourceId, text=text, description=description)
|
|
|
-
|
|
|
- if className != "" and resourceId != "" and text != "" and description == "" and instance != -1:
|
|
|
- uiObject = self.u(className=className, resourceId=resourceId, text=text, instance=instance)
|
|
|
-
|
|
|
- if className != "" and resourceId != "" and text == "" and description != "" and instance != -1:
|
|
|
+
|
|
|
+ if className != "" and resourceId != "" and text != "" and description != "" and \
|
|
|
+ bounds != "" and instance == -1:
|
|
|
+ uiObject = self.u(className=className, resourceId=resourceId, text=text, bounds=bounds,
|
|
|
+ description=description)
|
|
|
+
|
|
|
+ if className != "" and resourceId != "" and text != "" and description != "" and \
|
|
|
+ bounds == "" and instance != -1:
|
|
|
+ uiObject = self.u(className=className, resourceId=resourceId, text=text,
|
|
|
+ description=description, instance=instance)
|
|
|
+
|
|
|
+ if className != "" and resourceId != "" and text != "" and description == "" and \
|
|
|
+ bounds != "" and instance != -1:
|
|
|
+ uiObject = self.u(className=className, resourceId=resourceId, text=text,
|
|
|
+ bounds=bounds, instance=instance)
|
|
|
+
|
|
|
+ if className != "" and resourceId != "" and text == "" and description != "" and \
|
|
|
+ bounds != "" and instance != -1:
|
|
|
uiObject = self.u(className=className, resourceId=resourceId, description=description,
|
|
|
- instance=instance)
|
|
|
-
|
|
|
- if className != "" and resourceId == "" and text != "" and description != "" and instance != -1:
|
|
|
+ bounds=bounds, instance=instance)
|
|
|
+
|
|
|
+ if className != "" and resourceId == "" and text != "" and description != "" and \
|
|
|
+ bounds != "" and instance != -1:
|
|
|
uiObject = self.u(className=className, text=text, description=description,
|
|
|
- instance=instance)
|
|
|
-
|
|
|
- if className == "" and resourceId != "" and text != "" and description != "" and instance != -1:
|
|
|
+ bounds=bounds, instance=instance)
|
|
|
+
|
|
|
+ if className == "" and resourceId != "" and text != "" and description != "" and \
|
|
|
+ bounds != "" and instance != -1:
|
|
|
uiObject = self.u(resourceId=resourceId, text=text, description=description,
|
|
|
- instance=instance)
|
|
|
+ bounds=bounds, instance=instance)
|
|
|
|
|
|
|
|
|
- if className == "" and resourceId == "" and text != "" and description != "" and instance != -1:
|
|
|
- uiObject = self.u(text=text, description=description,
|
|
|
+
|
|
|
+ if className == "" and resourceId == "" and text != "" and description != "" and \
|
|
|
+ bounds != "" and instance != -1:
|
|
|
+ uiObject = self.u(text=text, description=description, bounds=bounds,
|
|
|
instance=instance)
|
|
|
-
|
|
|
- if className == "" and resourceId != "" and text == "" and description != "" and instance != -1:
|
|
|
- uiObject = self.u(resourceId=resourceId, description=description,
|
|
|
+
|
|
|
+ if className == "" and resourceId != "" and text == "" and description != "" and \
|
|
|
+ bounds != "" and instance != -1:
|
|
|
+ uiObject = self.u(resourceId=resourceId, description=description, bounds=bounds,
|
|
|
instance=instance)
|
|
|
-
|
|
|
- if className == "" and resourceId != "" and text != "" and description == "" and instance != -1:
|
|
|
- uiObject = self.u(resourceId=resourceId, text=text,
|
|
|
+
|
|
|
+ if className == "" and resourceId != "" and text != "" and description == "" and \
|
|
|
+ bounds != "" and instance != -1:
|
|
|
+ uiObject = self.u(resourceId=resourceId, text=text, bounds=bounds,
|
|
|
instance=instance)
|
|
|
-
|
|
|
- if className == "" and resourceId != "" and text != "" and description != "" and instance == -1:
|
|
|
- uiObject = self.u(resourceId=resourceId, text=text, description=description)
|
|
|
-
|
|
|
- if className != "" and resourceId == "" and text == "" and description != "" and instance != -1:
|
|
|
- uiObject = self.u(className=className, description=description,
|
|
|
+
|
|
|
+ if className == "" and resourceId != "" and text != "" and description != "" and \
|
|
|
+ bounds == "" and instance != -1:
|
|
|
+ uiObject = self.u(resourceId=resourceId, text=text, description=description,
|
|
|
instance=instance)
|
|
|
-
|
|
|
- if className != "" and resourceId == "" and text != "" and description == "" and instance != -1:
|
|
|
- uiObject = self.u(className=className, text=text,
|
|
|
+
|
|
|
+ if className == "" and resourceId != "" and text != "" and description != "" and \
|
|
|
+ bounds != "" and instance == -1:
|
|
|
+ uiObject = self.u(resourceId=resourceId, text=text, description=description,
|
|
|
+ bounds=bounds)
|
|
|
+
|
|
|
+ if className != "" and resourceId == "" and text == "" and description != "" and \
|
|
|
+ bounds != "" and instance != -1:
|
|
|
+ uiObject = self.u(className=className, description=description, bounds=bounds,
|
|
|
instance=instance)
|
|
|
-
|
|
|
- if className != "" and resourceId != "" and text == "" and description != "" and instance == -1:
|
|
|
- uiObject = self.u(className=className, text=text, description=description)
|
|
|
- if className != "" and resourceId != "" and text == "" and description == "" and instance != -1:
|
|
|
+
|
|
|
+ if className != "" and resourceId == "" and text != "" and description == "" and \
|
|
|
+ bounds != "" and instance != -1:
|
|
|
+ uiObject = self.u(className=className, text=text, bounds=bounds,
|
|
|
+ instance=instance)
|
|
|
+
|
|
|
+ if className != "" and resourceId != "" and text == "" and description != "" and \
|
|
|
+ bounds == "" and instance != -1:
|
|
|
+ uiObject = self.u(className=className, text=text, description=description,
|
|
|
+ instance=instance)
|
|
|
+
|
|
|
+ if className != "" and resourceId == "" and text != "" and description != "" and \
|
|
|
+ bounds != "" and instance == -1:
|
|
|
+ uiObject = self.u(className=className, text=text, description=description,
|
|
|
+ bounds=bounds)
|
|
|
+
|
|
|
+ if className != "" and resourceId != "" and text == "" and description == "" and \
|
|
|
+ bounds != "" and instance != -1:
|
|
|
+ uiObject = self.u(className=className, resourceId=resourceId, bounds=bounds,
|
|
|
+ instance=instance)
|
|
|
+
|
|
|
+ if className != "" and resourceId != "" and text == "" and description != "" and \
|
|
|
+ bounds == "" and instance != -1:
|
|
|
uiObject = self.u(className=className, resourceId=resourceId,
|
|
|
+ description=description, instance=instance)
|
|
|
+
|
|
|
+ if className != "" and resourceId != "" and text == "" and description != "" and \
|
|
|
+ bounds != "" and instance == -1:
|
|
|
+ uiObject = self.u(className=className, resourceId=resourceId,
|
|
|
+ description=description, bounds=bounds)
|
|
|
+
|
|
|
+ if className != "" and resourceId != "" and text != "" and description == "" and \
|
|
|
+ bounds == "" and instance != -1:
|
|
|
+ uiObject = self.u(className=className, resourceId=resourceId, text=text,
|
|
|
instance=instance)
|
|
|
+
|
|
|
+ if className != "" and resourceId != "" and text != "" and description == "" and \
|
|
|
+ bounds != "" and instance == -1:
|
|
|
+ uiObject = self.u(className=className, resourceId=resourceId, text=text,
|
|
|
+ bounds=bounds)
|
|
|
+
|
|
|
+ if className != "" and resourceId != "" and text != "" and description != "" and \
|
|
|
+ bounds == "" and instance == -1:
|
|
|
+ uiObject = self.u(className=className, resourceId=resourceId, text=text,
|
|
|
+ description=description)
|
|
|
|
|
|
- if className != "" and resourceId != "" and text == "" and description == "" and instance != -1:
|
|
|
- uiObject = self.u(className=className, resourceId=resourceId, description=description)
|
|
|
-
|
|
|
- if className != "" and resourceId != "" and text != "" and description == "" and instance == -1:
|
|
|
+
|
|
|
+
|
|
|
+ if className == "" and resourceId == "" and text == "" and description != "" and \
|
|
|
+ bounds != "" and instance != -1:
|
|
|
+ uiObject = self.u(description=description, bounds=bounds, instance=instance)
|
|
|
+
|
|
|
+ if className == "" and resourceId == "" and text != "" and description == "" and \
|
|
|
+ bounds != "" and instance != -1:
|
|
|
+ uiObject = self.u(text=text, bounds=bounds, instance=instance)
|
|
|
+
|
|
|
+ if className == "" and resourceId == "" and text != "" and description != "" and \
|
|
|
+ bounds == "" and instance != -1:
|
|
|
+ uiObject = self.u(text=text, description=description, instance=instance)
|
|
|
+
|
|
|
+ if className == "" and resourceId == "" and text != "" and description != "" and \
|
|
|
+ bounds != "" and instance == -1:
|
|
|
+ uiObject = self.u(text=text, description=description, bounds=bounds)
|
|
|
+
|
|
|
+ if className == "" and resourceId != "" and text == "" and description == "" and \
|
|
|
+ bounds != "" and instance != -1:
|
|
|
+ uiObject = self.u(resourceId=resourceId, bounds=bounds, instance=instance)
|
|
|
+
|
|
|
+ if className == "" and resourceId != "" and text == "" and description != "" and \
|
|
|
+ bounds == "" and instance != -1:
|
|
|
+ uiObject = self.u(resourceId=resourceId, description=description, instance=instance)
|
|
|
+
|
|
|
+ if className == "" and resourceId != "" and text == "" and description != "" and \
|
|
|
+ bounds != "" and instance == -1:
|
|
|
+ uiObject = self.u(resourceId=resourceId, description=description, bounds=bounds)
|
|
|
+
|
|
|
+ if className == "" and resourceId != "" and text != "" and description == "" and \
|
|
|
+ bounds == "" and instance != -1:
|
|
|
+ uiObject = self.u(resourceId=resourceId, text=text, instance=instance)
|
|
|
+
|
|
|
+ if className == "" and resourceId != "" and text != "" and description == "" and \
|
|
|
+ bounds != "" and instance == -1:
|
|
|
+ uiObject = self.u(resourceId=resourceId, text=text, bounds=bounds)
|
|
|
+
|
|
|
+ if className != "" and resourceId == "" and text == "" and description == "" and \
|
|
|
+ bounds != "" and instance != -1:
|
|
|
+ uiObject = self.u(className=className, bounds=bounds, instance=instance)
|
|
|
+
|
|
|
+ if className != "" and resourceId == "" and text == "" and description != "" and \
|
|
|
+ bounds == "" and instance != -1:
|
|
|
+ uiObject = self.u(className=className, description=description, instance=instance)
|
|
|
+
|
|
|
+ if className != "" and resourceId == "" and text == "" and description != "" and \
|
|
|
+ bounds != "" and instance == -1:
|
|
|
+ uiObject = self.u(className=className, description=description, bounds=bounds)
|
|
|
+
|
|
|
+ if className != "" and resourceId == "" and text != "" and description == "" and \
|
|
|
+ bounds == "" and instance != -1:
|
|
|
+ uiObject = self.u(className=className, text=text, instance=instance)
|
|
|
+
|
|
|
+ if className != "" and resourceId == "" and text != "" and description == "" and \
|
|
|
+ bounds != "" and instance == -1:
|
|
|
+ uiObject = self.u(className=className, text=text, bounds=bounds)
|
|
|
+
|
|
|
+ if className != "" and resourceId == "" and text != "" and description != "" and \
|
|
|
+ bounds == "" and instance == -1:
|
|
|
+ uiObject = self.u(className=className, text=text, description=description)
|
|
|
+
|
|
|
+ if className != "" and resourceId != "" and text == "" and description == "" and \
|
|
|
+ bounds == "" and instance != -1:
|
|
|
+ uiObject = self.u(className=className, resourceId=resourceId, instance=instance)
|
|
|
+
|
|
|
+ if className != "" and resourceId != "" and text == "" and description == "" and \
|
|
|
+ bounds != "" and instance == -1:
|
|
|
+ uiObject = self.u(className=className, resourceId=resourceId, bounds=bounds)
|
|
|
+
|
|
|
+ if className != "" and resourceId != "" and text != "" and description == "" and \
|
|
|
+ bounds == "" and instance == -1:
|
|
|
uiObject = self.u(className=className, resourceId=resourceId, text=text)
|
|
|
|
|
|
-
|
|
|
- if className == "" and resourceId == "" and text == "" and description != "" and instance != -1:
|
|
|
+
|
|
|
+
|
|
|
+ if className == "" and resourceId == "" and text == "" and description == "" and \
|
|
|
+ bounds != "" and instance != -1:
|
|
|
+ uiObject = self.u(bounds=bounds, instance=instance)
|
|
|
+
|
|
|
+ if className == "" and resourceId == "" and text == "" and description != "" and \
|
|
|
+ bounds == "" and instance != -1:
|
|
|
uiObject = self.u(description=description, instance=instance)
|
|
|
-
|
|
|
- if className == "" and resourceId == "" and text != "" and description == "" and instance != -1:
|
|
|
+
|
|
|
+ if className == "" and resourceId == "" and text == "" and description != "" and \
|
|
|
+ bounds != "" and instance == -1:
|
|
|
+ uiObject = self.u(description=description, bounds=bounds)
|
|
|
+
|
|
|
+ if className == "" and resourceId == "" and text != "" and description == "" and \
|
|
|
+ bounds == "" and instance != -1:
|
|
|
uiObject = self.u(text=text, instance=instance)
|
|
|
-
|
|
|
- if className == "" and resourceId == "" and text != "" and description != "" and instance == -1:
|
|
|
- uiObject = self.u(text=text, description=description)
|
|
|
-
|
|
|
- if className == "" and resourceId != "" and text == "" and description == "" and instance != -1:
|
|
|
- uiObject = self.u(resourceId=resourceId, instance=instance)
|
|
|
-
|
|
|
- if className == "" and resourceId != "" and text == "" and description != "" and instance == -1:
|
|
|
- uiObject = self.u(resourceId=resourceId, description=description)
|
|
|
-
|
|
|
- if className == "" and resourceId != "" and text != "" and description == "" and instance == -1:
|
|
|
- uiObject = self.u(resourceId=resourceId, text=text)
|
|
|
-
|
|
|
- if className != "" and resourceId == "" and text == "" and description == "" and instance != -1:
|
|
|
+
|
|
|
+ if className == "" and resourceId == "" and text != "" and description == "" and \
|
|
|
+ bounds != "" and instance == -1:
|
|
|
+ uiObject = self.u(text=text, bounds=bounds)
|
|
|
+
|
|
|
+ if className != "" and resourceId == "" and text == "" and description == "" and \
|
|
|
+ bounds == "" and instance != -1:
|
|
|
uiObject = self.u(className=className, instance=instance)
|
|
|
-
|
|
|
- if className != "" and resourceId == "" and text == "" and description != "" and instance == -1:
|
|
|
- uiObject = self.u(className=className, description=description)
|
|
|
-
|
|
|
- if className != "" and resourceId == "" and text != "" and description == "" and instance == -1:
|
|
|
- uiObject = self.u(className=className, text=text)
|
|
|
-
|
|
|
- if className != "" and resourceId != "" and text == "" and description == "" and instance == -1:
|
|
|
+
|
|
|
+ if className != "" and resourceId == "" and text == "" and description == "" and \
|
|
|
+ bounds != "" and instance == -1:
|
|
|
+ uiObject = self.u(className=className, bounds=bounds)
|
|
|
+
|
|
|
+ if className != "" and resourceId != "" and text == "" and description == "" and \
|
|
|
+ bounds == "" and instance == -1:
|
|
|
uiObject = self.u(className=className, resourceId=resourceId)
|
|
|
|
|
|
-
|
|
|
- if className == "" and resourceId == "" and text == "" and description == "" and instance != -1:
|
|
|
- uiObject = self.u(instance=instance)
|
|
|
-
|
|
|
- if className == "" and resourceId == "" and text == "" and description != "" and instance == -1:
|
|
|
- uiObject = self.u(description=description)
|
|
|
-
|
|
|
- if className == "" and resourceId == "" and text != "" and description == "" and instance == -1:
|
|
|
- uiObject = self.u(text=text)
|
|
|
-
|
|
|
- if className == "" and resourceId != "" and text == "" and description == "" and instance == -1:
|
|
|
- uiObject = self.u(resourceId=resourceId)
|
|
|
-
|
|
|
- if className != "" and resourceId == "" and text == "" and description == "" and instance == -1:
|
|
|
+
|
|
|
+
|
|
|
+ if className != "" and resourceId == "" and text == "" and description == "" and \
|
|
|
+ bounds == "" and instance == -1:
|
|
|
uiObject = self.u(className=className)
|
|
|
+
|
|
|
+ if className == "" and resourceId != "" and text == "" and description == "" and \
|
|
|
+ bounds == "" and instance == -1:
|
|
|
+ uiObject = self.u(resourceId=resourceId)
|
|
|
+
|
|
|
+ if className == "" and resourceId == "" and text != "" and description == "" and \
|
|
|
+ bounds == "" and instance == -1:
|
|
|
+ uiObject = self.u(text=text)
|
|
|
+
|
|
|
+ if className == "" and resourceId == "" and text == "" and description != "" and \
|
|
|
+ bounds == "" and instance == -1:
|
|
|
+ uiObject = self.u(description=description)
|
|
|
+
|
|
|
+ if className == "" and resourceId == "" and text == "" and description == "" and \
|
|
|
+ bounds != "" and instance == -1:
|
|
|
+ uiObject = self.u(bounds=bounds)
|
|
|
+
|
|
|
+ if className == "" and resourceId == "" and text == "" and description == "" and \
|
|
|
+ bounds == "" and instance == -1:
|
|
|
+ uiObject = self.u(instance=instance)
|
|
|
return uiObject
|
|
|
except Exception, e:
|
|
|
- print e
|
|
|
+ print "异常:",e
|
|
|
return uiObject
|
|
|
|
|
|
'''
|
|
@@ -438,12 +593,11 @@ class PyUIAutomator():
|
|
|
print e
|
|
|
|
|
|
'''
|
|
|
- 作用:根据传入的chooseType,获取当前界面聚焦的对象
|
|
|
- 参数:
|
|
|
- 注意:
|
|
|
- 例子:self.pyUIAutomator.getChoosedUIObject("focus")
|
|
|
- '''
|
|
|
-
|
|
|
+ 作用:根据传入的chooseType,获取当前界面聚焦的对象
|
|
|
+ 参数:
|
|
|
+ 注意:
|
|
|
+ 例子:self.pyUIAutomator.getChoosedUIObject("focus")
|
|
|
+ '''
|
|
|
def getChoosedUIObject(self, chooseType, resourceId='', text=''):
|
|
|
if chooseType.lower() == "focus":
|
|
|
return self.getFocusedUIObject(resourceId=resourceId, text=text)
|
|
@@ -1095,6 +1249,230 @@ class FocusManageAndroid():
|
|
|
print "执行%s 次查找,仍未找到目标焦点!!" % (str(Max_Try))
|
|
|
return False
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+ def toDestFocusByBounds_for_RecyclerView(self, bounds, boundsResourceId="", findDirection="down",
|
|
|
+ Max_Try=10, keyType=UATTree.Key_Event, hb_keyDict={}):
|
|
|
+
|
|
|
+ count = 0
|
|
|
+ Max_Try = Max_Try
|
|
|
+ Reversecount = 0
|
|
|
+ Reverse_Max_Try = Max_Try * 2
|
|
|
+ while (True):
|
|
|
+ print "count:", count
|
|
|
+ if count >= Max_Try and Reversecount >= Reverse_Max_Try:
|
|
|
+ break
|
|
|
+
|
|
|
+ time.sleep(0.5)
|
|
|
+ if hb_keyDict != {}:
|
|
|
+
|
|
|
+ self.executeHeartBeatKey(hb_keyDict)
|
|
|
+ focusedUIObject = self.u.getFocusedUIObject()
|
|
|
+ focusedBounds = focusedUIObject.info['bounds']
|
|
|
+ if hb_keyDict != {}:
|
|
|
+
|
|
|
+ self.executeHeartBeatKey(hb_keyDict)
|
|
|
+ try:
|
|
|
+ destBounds = bounds
|
|
|
+ if self.directionManageAndroid.isHasAnotherBounds(focusedBounds,destBounds):
|
|
|
+ print "success to focus the target:",bounds
|
|
|
+ return True
|
|
|
+ else:
|
|
|
+ count = count + 1
|
|
|
+ direction = self.directionManageAndroid.getTargetDirection(focusedBounds,destBounds)
|
|
|
+ self.directionManageAndroid.goOneStep(self.u,direction,keyType)
|
|
|
+ except Exception,e:
|
|
|
+
|
|
|
+ if count < Max_Try:
|
|
|
+ count = count + 1
|
|
|
+ self.pressKeyByType(findDirection, keyType)
|
|
|
+ else:
|
|
|
+ Reversecount = Reversecount + 1
|
|
|
+ self.pressKeyByType(self.ReverseDirctionDict[findDirection], keyType)
|
|
|
+
|
|
|
+ else:
|
|
|
+ if count < Max_Try:
|
|
|
+ count = count + 1
|
|
|
+ self.pressKeyByType(findDirection, keyType)
|
|
|
+ else:
|
|
|
+ Reversecount = Reversecount + 1
|
|
|
+ self.pressKeyByType(self.ReverseDirctionDict[findDirection], keyType)
|
|
|
+
|
|
|
+ print "执行%s 次查找,仍未找到目标焦点!!" % (str(Max_Try))
|
|
|
+ return False
|
|
|
+
|
|
|
+
|
|
|
+ def toDestFocusByClassBounds_for_RecyclerView(self, className, bounds,classResourceId="", findDirection="down",
|
|
|
+ Max_Try=10, keyType=UATTree.Key_Event, hb_keyDict={}):
|
|
|
+
|
|
|
+ count = 0
|
|
|
+ Max_Try = Max_Try
|
|
|
+ Reversecount = 0
|
|
|
+ Reverse_Max_Try = Max_Try * 2
|
|
|
+ while (True):
|
|
|
+ print "count:", count
|
|
|
+ if count >= Max_Try and Reversecount >= Reverse_Max_Try:
|
|
|
+ break
|
|
|
+
|
|
|
+ time.sleep(0.5)
|
|
|
+ if hb_keyDict != {}:
|
|
|
+
|
|
|
+ self.executeHeartBeatKey(hb_keyDict)
|
|
|
+ focusedUIObject = self.u.getFocusedUIObject()
|
|
|
+ print "zhouyifocusedUIObject",focusedUIObject
|
|
|
+ print "zhouyifocusedUIObject.info", focusedUIObject.info
|
|
|
+ if hb_keyDict != {}:
|
|
|
+
|
|
|
+ self.executeHeartBeatKey(hb_keyDict)
|
|
|
+ destUIObject = self.u.getUiObject(className=className, bounds = bounds,resourceId=classResourceId)
|
|
|
+ print "destUIObject",destUIObject
|
|
|
+ try:
|
|
|
+ destUIObjectInfo = destUIObject.info
|
|
|
+ print "destUIObjectInfo",destUIObjectInfo
|
|
|
+ except Exception,e:
|
|
|
+ print "异常:",e
|
|
|
+
|
|
|
+ try:
|
|
|
+
|
|
|
+ destBounds = bounds
|
|
|
+ print "destBounds:", destBounds
|
|
|
+ if self.directionManageAndroid.isHasAnotherBounds(focusedBounds,destBounds):
|
|
|
+ print "c&b success to focus the target:",bounds
|
|
|
+ return True
|
|
|
+ else:
|
|
|
+ count = count + 1
|
|
|
+ direction = self.directionManageAndroid.getTargetDirection(focusedBounds,destBounds)
|
|
|
+ self.directionManageAndroid.goOneStep(self.u,direction,keyType)
|
|
|
+ except Exception,e:
|
|
|
+
|
|
|
+ if count < Max_Try:
|
|
|
+ count = count + 1
|
|
|
+ self.pressKeyByType(findDirection, keyType)
|
|
|
+ else:
|
|
|
+ Reversecount = Reversecount + 1
|
|
|
+ self.pressKeyByType(self.ReverseDirctionDict[findDirection], keyType)
|
|
|
+
|
|
|
+ else:
|
|
|
+ if count < Max_Try:
|
|
|
+ count = count + 1
|
|
|
+ self.pressKeyByType(findDirection, keyType)
|
|
|
+ else:
|
|
|
+ Reversecount = Reversecount + 1
|
|
|
+ self.pressKeyByType(self.ReverseDirctionDict[findDirection], keyType)
|
|
|
+
|
|
|
+ print "执行%s 次查找,仍未找到目标焦点!!" % (str(Max_Try))
|
|
|
+ return False
|
|
|
+
|
|
|
+
|
|
|
+ def toDestFocusByClass_for_RecyclerView(self, className, classResourceId="", findDirection="down",
|
|
|
+ Max_Try=10, keyType=UATTree.Key_Event, hb_keyDict={}):
|
|
|
+
|
|
|
+ count = 0
|
|
|
+ Max_Try = Max_Try
|
|
|
+ Reversecount = 0
|
|
|
+ Reverse_Max_Try = Max_Try * 2
|
|
|
+ while (True):
|
|
|
+ print "count:", count
|
|
|
+ if count >= Max_Try and Reversecount >= Reverse_Max_Try:
|
|
|
+ break
|
|
|
+
|
|
|
+ time.sleep(0.5)
|
|
|
+ if hb_keyDict != {}:
|
|
|
+
|
|
|
+ self.executeHeartBeatKey(hb_keyDict)
|
|
|
+ focusedUIObject = self.u.getFocusedUIObject()
|
|
|
+ print "zhouyifocusedUIObject", focusedUIObject
|
|
|
+ print "zhouyifocusedUIObject.info", focusedUIObject.info
|
|
|
+ if hb_keyDict != {}:
|
|
|
+
|
|
|
+ self.executeHeartBeatKey(hb_keyDict)
|
|
|
+ destUIObject = self.u.getUiObject(className=className, resourceId=classResourceId)
|
|
|
+ print "destUIObject", destUIObject
|
|
|
+ try:
|
|
|
+ destUIObjectInfo = destUIObject.info
|
|
|
+ print "destUIObjectInfo", destUIObjectInfo
|
|
|
+ except Exception, e:
|
|
|
+ print "异常:", e
|
|
|
+
|
|
|
+ try:
|
|
|
+ destBounds = destUIObject.info['bounds']
|
|
|
+ print "destBounds:", destBounds
|
|
|
+ if self.directionManageAndroid.isHasAnotherBounds(focusedBounds, destBounds):
|
|
|
+ print '成功聚焦到目标焦点:', bounds
|
|
|
+ return True
|
|
|
+ else:
|
|
|
+ count = count + 1
|
|
|
+ direction = self.directionManageAndroid.getTargetDirection(focusedBounds, destBounds)
|
|
|
+ self.directionManageAndroid.goOneStep(self.u, direction, keyType)
|
|
|
+ except Exception, e:
|
|
|
+
|
|
|
+ if count < Max_Try:
|
|
|
+ count = count + 1
|
|
|
+ self.pressKeyByType(findDirection, keyType)
|
|
|
+ else:
|
|
|
+ Reversecount = Reversecount + 1
|
|
|
+ self.pressKeyByType(self.ReverseDirctionDict[findDirection], keyType)
|
|
|
+
|
|
|
+ else:
|
|
|
+ if count < Max_Try:
|
|
|
+ count = count + 1
|
|
|
+ self.pressKeyByType(findDirection, keyType)
|
|
|
+ else:
|
|
|
+ Reversecount = Reversecount + 1
|
|
|
+ self.pressKeyByType(self.ReverseDirctionDict[findDirection], keyType)
|
|
|
+
|
|
|
+ print "执行%s 次查找,仍未找到目标焦点!!" % (str(Max_Try))
|
|
|
+ return False
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ def toDestTargetByBounds_for_RecyclerView(self, bounds, chooseType, Max_Try=20,
|
|
|
+ keyType=UATTree.Key_Event, findFocusCount=0, hb_keyDict={}):
|
|
|
+ count = 0
|
|
|
+ while (True):
|
|
|
+ if hb_keyDict != {}:
|
|
|
+
|
|
|
+ self.executeHeartBeatKey(hb_keyDict)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ destBounds = bounds
|
|
|
+ print "目标坐标:", destBounds
|
|
|
+ if hb_keyDict != {}:
|
|
|
+
|
|
|
+ self.executeHeartBeatKey(hb_keyDict)
|
|
|
+ try:
|
|
|
+ if chooseType.lower() == "focus":
|
|
|
+ choosingUIObject = self.u.getFocusedUIObject()
|
|
|
+ objBounds = choosingUIObject.info['bounds']
|
|
|
+ elif chooseType.lower() == "select":
|
|
|
+ choosingUIObject = self.u.getSelectedUIObject()
|
|
|
+ objBounds = choosingUIObject.info['bounds']
|
|
|
+ print "当前坐标:", objBounds
|
|
|
+ except Exception, e:
|
|
|
+ print "获取焦点失败!Error:", e
|
|
|
+ if findFocusCount < 3:
|
|
|
+ self.u.pressKeyTimes("down")
|
|
|
+ return self.toDestTargetByBounds_for_RecyclerView(bounds, chooseType,
|
|
|
+ findFocusCount=findFocusCount + 1)
|
|
|
+ else:
|
|
|
+ print "尝试%s次操作!!!仍未能找到聚焦点!!!无法聚焦到目标" % findFocusCount
|
|
|
+ return False
|
|
|
+ if self.directionManageAndroid.isHasAnotherBounds(objBounds, destBounds):
|
|
|
+ print "已聚焦至目标组件!!!"
|
|
|
+ return True
|
|
|
+ else:
|
|
|
+ if count >= Max_Try:
|
|
|
+ print "已尝试至最大次数%s次,仍未能聚焦至目标组件!!!" % Max_Try
|
|
|
+ return False
|
|
|
+ direction = self.directionManageAndroid.getTargetDirection(objBounds, destBounds)
|
|
|
+ print "目标方位:", direction
|
|
|
+ self.directionManageAndroid.goOneStep(self.u, direction, keyType)
|
|
|
+ count += 1
|
|
|
+
|
|
|
'''
|
|
|
作用:在界面中 中 focused控件中既没有包含content-des控件属性,也没有text控件属性,
|
|
|
采用单张图片模板匹配 用于聚焦目标焦点
|
|
@@ -1881,6 +2259,7 @@ class FocusManageAndroid():
|
|
|
|
|
|
|
|
|
def pressKeyByType(self, keyName, keyType = UATTree.Key_Event, times = 1, duration = 1.0):
|
|
|
+ print "pressKeyByType:",keyName,keyType
|
|
|
if keyType == UATTree.Key_Event:
|
|
|
return self.u.pressKeyTimes(keyName, times, duration)
|
|
|
elif keyType == UATTree.Key_IR:
|