|
@@ -41,7 +41,7 @@ self.pyUIAutomator = PyUIAutomator()
|
|
class PyUIAutomator():
|
|
class PyUIAutomator():
|
|
def __init__(self, serial=None):
|
|
def __init__(self, serial=None):
|
|
try:
|
|
try:
|
|
- self.u = u2.connect_usb(serial)
|
|
|
|
|
|
+ self.u = u2.connect_usb(serial) #得到UIAutomatorServer实例对象
|
|
self.serial = serial
|
|
self.serial = serial
|
|
except Exception,e:
|
|
except Exception,e:
|
|
print e
|
|
print e
|
|
@@ -98,6 +98,18 @@ class PyUIAutomator():
|
|
self.listenAdbConnected()
|
|
self.listenAdbConnected()
|
|
self.u.pressKeyTimes(key, times, duration)
|
|
self.u.pressKeyTimes(key, times, duration)
|
|
|
|
|
|
|
|
+ '''
|
|
|
|
+ 用uiautomator view属性键作为paramDIct的键,传入的paramDict里的参数,必须有效。
|
|
|
|
+ 参考session.Selector里的__fields字典
|
|
|
|
+ '''
|
|
|
|
+ def getUiObject2(self, paramDict):
|
|
|
|
+ # print "getUiObject2,paramDict:",paramDict
|
|
|
|
+ uiObject = None
|
|
|
|
+ if paramDict.__len__>0:
|
|
|
|
+ uiObject = self.u(**paramDict)
|
|
|
|
+ # print uiObject,uiObject.info
|
|
|
|
+ return uiObject
|
|
|
|
+
|
|
'''
|
|
'''
|
|
作用:获取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()
|
|
self.listenAdbConnected()
|
|
# print 'className:', className
|
|
# print 'className:', className
|
|
# print 'resourceId:', resourceId
|
|
# print 'resourceId:', resourceId
|
|
@@ -131,117 +143,260 @@ class PyUIAutomator():
|
|
uiObject = None
|
|
uiObject = None
|
|
try:
|
|
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 "没有参数带入,找不到对象"
|
|
print "没有参数带入,找不到对象"
|
|
return uiObject
|
|
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,
|
|
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:
|
|
|
|
|
|
+ # 缺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,
|
|
|
|
+ description=description)
|
|
|
|
+ # 缺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, instance=instance)
|
|
|
|
+ # 缺description
|
|
|
|
+ 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)
|
|
|
|
+ # 缺text
|
|
|
|
+ if className != "" and resourceId != "" and text == "" and description != "" and \
|
|
|
|
+ bounds != "" and instance != -1:
|
|
uiObject = self.u(className=className, resourceId=resourceId, description=description,
|
|
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)
|
|
|
|
+ # 缺resouceId
|
|
|
|
+ if className != "" and resourceId == "" and text != "" and description != "" and \
|
|
|
|
+ bounds != "" and instance != -1:
|
|
uiObject = self.u(className=className, text=text, description=description,
|
|
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)
|
|
|
|
+ # lack of className
|
|
|
|
+ if className == "" and resourceId != "" and text != "" and description != "" and \
|
|
|
|
+ bounds != "" and instance != -1:
|
|
uiObject = self.u(resourceId=resourceId, text=text, description=description,
|
|
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,
|
|
|
|
|
|
+ # lack of className and resourceId
|
|
|
|
+ if className == "" and resourceId == "" and text != "" and description != "" and \
|
|
|
|
+ bounds != "" and instance != -1:
|
|
|
|
+ uiObject = self.u(text=text, description=description, bounds=bounds,
|
|
instance=instance)
|
|
instance=instance)
|
|
-
|
|
|
|
- if className == "" and resourceId != "" and text == "" and description != "" and instance != -1:
|
|
|
|
- uiObject = self.u(resourceId=resourceId, description=description,
|
|
|
|
|
|
+ # lack of className and text
|
|
|
|
+ if className == "" and resourceId != "" and text == "" and description != "" and \
|
|
|
|
+ bounds != "" and instance != -1:
|
|
|
|
+ uiObject = self.u(resourceId=resourceId, description=description, bounds=bounds,
|
|
instance=instance)
|
|
instance=instance)
|
|
-
|
|
|
|
- if className == "" and resourceId != "" and text != "" and description == "" and instance != -1:
|
|
|
|
- uiObject = self.u(resourceId=resourceId, text=text,
|
|
|
|
|
|
+ # lack of className and description
|
|
|
|
+ if className == "" and resourceId != "" and text != "" and description == "" and \
|
|
|
|
+ bounds != "" and instance != -1:
|
|
|
|
+ uiObject = self.u(resourceId=resourceId, text=text, bounds=bounds,
|
|
instance=instance)
|
|
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,
|
|
|
|
|
|
+ # lack of className and bounds
|
|
|
|
+ if className == "" and resourceId != "" and text != "" and description != "" and \
|
|
|
|
+ bounds == "" and instance != -1:
|
|
|
|
+ uiObject = self.u(resourceId=resourceId, text=text, description=description,
|
|
instance=instance)
|
|
instance=instance)
|
|
-
|
|
|
|
- if className != "" and resourceId == "" and text != "" and description == "" and instance != -1:
|
|
|
|
- uiObject = self.u(className=className, text=text,
|
|
|
|
|
|
+ # lack of className and instance
|
|
|
|
+ if className == "" and resourceId != "" and text != "" and description != "" and \
|
|
|
|
+ bounds != "" and instance == -1:
|
|
|
|
+ uiObject = self.u(resourceId=resourceId, text=text, description=description,
|
|
|
|
+ bounds=bounds)
|
|
|
|
+ # lack of resourceId and text
|
|
|
|
+ if className != "" and resourceId == "" and text == "" and description != "" and \
|
|
|
|
+ bounds != "" and instance != -1:
|
|
|
|
+ uiObject = self.u(className=className, description=description, bounds=bounds,
|
|
instance=instance)
|
|
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:
|
|
|
|
|
|
+ # lack of resourceId and description
|
|
|
|
+ if className != "" and resourceId == "" and text != "" and description == "" and \
|
|
|
|
+ bounds != "" and instance != -1:
|
|
|
|
+ uiObject = self.u(className=className, text=text, bounds=bounds,
|
|
|
|
+ instance=instance)
|
|
|
|
+ # lack of resourceId and bounds
|
|
|
|
+ if className != "" and resourceId != "" and text == "" and description != "" and \
|
|
|
|
+ bounds == "" and instance != -1:
|
|
|
|
+ uiObject = self.u(className=className, text=text, description=description,
|
|
|
|
+ instance=instance)
|
|
|
|
+ # lack of resourceId and 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)
|
|
|
|
+ # lack of text and description
|
|
|
|
+ if className != "" and resourceId != "" and text == "" and description == "" and \
|
|
|
|
+ bounds != "" and instance != -1:
|
|
|
|
+ uiObject = self.u(className=className, resourceId=resourceId, bounds=bounds,
|
|
|
|
+ instance=instance)
|
|
|
|
+ # lack of text and bounds
|
|
|
|
+ if className != "" and resourceId != "" and text == "" and description != "" and \
|
|
|
|
+ bounds == "" and instance != -1:
|
|
uiObject = self.u(className=className, resourceId=resourceId,
|
|
uiObject = self.u(className=className, resourceId=resourceId,
|
|
|
|
+ description=description, instance=instance)
|
|
|
|
+ # lack of text and 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)
|
|
|
|
+ # lack of description and 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)
|
|
instance=instance)
|
|
|
|
+ # lack of description and 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)
|
|
|
|
+ # lack of bounds and instance
|
|
|
|
+ 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:
|
|
|
|
|
|
+ # 缺少3个元素
|
|
|
|
+ # lack of className and resourceId and text
|
|
|
|
+ if className == "" and resourceId == "" and text == "" and description != "" and \
|
|
|
|
+ bounds != "" and instance != -1:
|
|
|
|
+ uiObject = self.u(description=description, bounds=bounds, instance=instance)
|
|
|
|
+ # lack of className and resourceId and description
|
|
|
|
+ if className == "" and resourceId == "" and text != "" and description == "" and \
|
|
|
|
+ bounds != "" and instance != -1:
|
|
|
|
+ uiObject = self.u(text=text, bounds=bounds, instance=instance)
|
|
|
|
+ # lack of className and resourceId and bounds
|
|
|
|
+ if className == "" and resourceId == "" and text != "" and description != "" and \
|
|
|
|
+ bounds == "" and instance != -1:
|
|
|
|
+ uiObject = self.u(text=text, description=description, instance=instance)
|
|
|
|
+ # lack of className and resourceId and instance
|
|
|
|
+ if className == "" and resourceId == "" and text != "" and description != "" and \
|
|
|
|
+ bounds != "" and instance == -1:
|
|
|
|
+ uiObject = self.u(text=text, description=description, bounds=bounds)
|
|
|
|
+ # lack of className and text and description
|
|
|
|
+ if className == "" and resourceId != "" and text == "" and description == "" and \
|
|
|
|
+ bounds != "" and instance != -1:
|
|
|
|
+ uiObject = self.u(resourceId=resourceId, bounds=bounds, instance=instance)
|
|
|
|
+ # lack of className and text and bounds
|
|
|
|
+ if className == "" and resourceId != "" and text == "" and description != "" and \
|
|
|
|
+ bounds == "" and instance != -1:
|
|
|
|
+ uiObject = self.u(resourceId=resourceId, description=description, instance=instance)
|
|
|
|
+ # lack of className and text and instance
|
|
|
|
+ if className == "" and resourceId != "" and text == "" and description != "" and \
|
|
|
|
+ bounds != "" and instance == -1:
|
|
|
|
+ uiObject = self.u(resourceId=resourceId, description=description, bounds=bounds)
|
|
|
|
+ # lack of className and description and bounds
|
|
|
|
+ if className == "" and resourceId != "" and text != "" and description == "" and \
|
|
|
|
+ bounds == "" and instance != -1:
|
|
|
|
+ uiObject = self.u(resourceId=resourceId, text=text, instance=instance)
|
|
|
|
+ # lack of className and description and instance
|
|
|
|
+ if className == "" and resourceId != "" and text != "" and description == "" and \
|
|
|
|
+ bounds != "" and instance == -1:
|
|
|
|
+ uiObject = self.u(resourceId=resourceId, text=text, bounds=bounds)
|
|
|
|
+ # lack of resourceId and text and description
|
|
|
|
+ if className != "" and resourceId == "" and text == "" and description == "" and \
|
|
|
|
+ bounds != "" and instance != -1:
|
|
|
|
+ uiObject = self.u(className=className, bounds=bounds, instance=instance)
|
|
|
|
+ # lack of resourceId and text and bounds
|
|
|
|
+ if className != "" and resourceId == "" and text == "" and description != "" and \
|
|
|
|
+ bounds == "" and instance != -1:
|
|
|
|
+ uiObject = self.u(className=className, description=description, instance=instance)
|
|
|
|
+ # lack of resourceId and text and instance
|
|
|
|
+ if className != "" and resourceId == "" and text == "" and description != "" and \
|
|
|
|
+ bounds != "" and instance == -1:
|
|
|
|
+ uiObject = self.u(className=className, description=description, bounds=bounds)
|
|
|
|
+ # lack of resourceId and description and bounds
|
|
|
|
+ if className != "" and resourceId == "" and text != "" and description == "" and \
|
|
|
|
+ bounds == "" and instance != -1:
|
|
|
|
+ uiObject = self.u(className=className, text=text, instance=instance)
|
|
|
|
+ # lack of resourceId and description and instance
|
|
|
|
+ if className != "" and resourceId == "" and text != "" and description == "" and \
|
|
|
|
+ bounds != "" and instance == -1:
|
|
|
|
+ uiObject = self.u(className=className, text=text, bounds=bounds)
|
|
|
|
+ # lack of resourceId and bounds and instance
|
|
|
|
+ if className != "" and resourceId == "" and text != "" and description != "" and \
|
|
|
|
+ bounds == "" and instance == -1:
|
|
|
|
+ uiObject = self.u(className=className, text=text, description=description)
|
|
|
|
+ # lack of text and description and bounds
|
|
|
|
+ if className != "" and resourceId != "" and text == "" and description == "" and \
|
|
|
|
+ bounds == "" and instance != -1:
|
|
|
|
+ uiObject = self.u(className=className, resourceId=resourceId, instance=instance)
|
|
|
|
+ # lack of text and description and instance
|
|
|
|
+ if className != "" and resourceId != "" and text == "" and description == "" and \
|
|
|
|
+ bounds != "" and instance == -1:
|
|
|
|
+ uiObject = self.u(className=className, resourceId=resourceId, bounds=bounds)
|
|
|
|
+ # lack of description and bounds and instance
|
|
|
|
+ if className != "" and resourceId != "" and text != "" and description == "" and \
|
|
|
|
+ bounds == "" and instance == -1:
|
|
uiObject = self.u(className=className, resourceId=resourceId, text=text)
|
|
uiObject = self.u(className=className, resourceId=resourceId, text=text)
|
|
|
|
|
|
- # 缺少3个元素
|
|
|
|
- if className == "" and resourceId == "" and text == "" and description != "" and instance != -1:
|
|
|
|
|
|
+ # 缺少4个元素
|
|
|
|
+ # lack of className and resourceId and text and description
|
|
|
|
+ if className == "" and resourceId == "" and text == "" and description == "" and \
|
|
|
|
+ bounds != "" and instance != -1:
|
|
|
|
+ uiObject = self.u(bounds=bounds, instance=instance)
|
|
|
|
+ # lack of className and resourceId and text and bounds
|
|
|
|
+ if className == "" and resourceId == "" and text == "" and description != "" and \
|
|
|
|
+ bounds == "" and instance != -1:
|
|
uiObject = self.u(description=description, instance=instance)
|
|
uiObject = self.u(description=description, instance=instance)
|
|
-
|
|
|
|
- if className == "" and resourceId == "" and text != "" and description == "" and instance != -1:
|
|
|
|
|
|
+ # lack of className and resourceId and text and instance
|
|
|
|
+ if className == "" and resourceId == "" and text == "" and description != "" and \
|
|
|
|
+ bounds != "" and instance == -1:
|
|
|
|
+ uiObject = self.u(description=description, bounds=bounds)
|
|
|
|
+ # lack of className and resourceId and description and bounds
|
|
|
|
+ if className == "" and resourceId == "" and text != "" and description == "" and \
|
|
|
|
+ bounds == "" and instance != -1:
|
|
uiObject = self.u(text=text, instance=instance)
|
|
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:
|
|
|
|
|
|
+ # lack of className and resourceId and description and instance
|
|
|
|
+ if className == "" and resourceId == "" and text != "" and description == "" and \
|
|
|
|
+ bounds != "" and instance == -1:
|
|
|
|
+ uiObject = self.u(text=text, bounds=bounds)
|
|
|
|
+ # lack of resourceid and text and description and bounds
|
|
|
|
+ if className != "" and resourceId == "" and text == "" and description == "" and \
|
|
|
|
+ bounds == "" and instance != -1:
|
|
uiObject = self.u(className=className, instance=instance)
|
|
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:
|
|
|
|
|
|
+ # lack of resourceid and text and description and instance
|
|
|
|
+ if className != "" and resourceId == "" and text == "" and description == "" and \
|
|
|
|
+ bounds != "" and instance == -1:
|
|
|
|
+ uiObject = self.u(className=className, bounds=bounds)
|
|
|
|
+ # lack of text and description and bounds and instance
|
|
|
|
+ if className != "" and resourceId != "" and text == "" and description == "" and \
|
|
|
|
+ bounds == "" and instance == -1:
|
|
uiObject = self.u(className=className, resourceId=resourceId)
|
|
uiObject = self.u(className=className, resourceId=resourceId)
|
|
|
|
|
|
- # 缺少4个元素
|
|
|
|
- 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:
|
|
|
|
|
|
+ # 缺少5个元素的
|
|
|
|
+ # only className
|
|
|
|
+ if className != "" and resourceId == "" and text == "" and description == "" and \
|
|
|
|
+ bounds == "" and instance == -1:
|
|
uiObject = self.u(className=className)
|
|
uiObject = self.u(className=className)
|
|
|
|
+ # only resourceid
|
|
|
|
+ if className == "" and resourceId != "" and text == "" and description == "" and \
|
|
|
|
+ bounds == "" and instance == -1:
|
|
|
|
+ uiObject = self.u(resourceId=resourceId)
|
|
|
|
+ # only text
|
|
|
|
+ if className == "" and resourceId == "" and text != "" and description == "" and \
|
|
|
|
+ bounds == "" and instance == -1:
|
|
|
|
+ uiObject = self.u(text=text)
|
|
|
|
+ # only description
|
|
|
|
+ if className == "" and resourceId == "" and text == "" and description != "" and \
|
|
|
|
+ bounds == "" and instance == -1:
|
|
|
|
+ uiObject = self.u(description=description)
|
|
|
|
+ # only bounds
|
|
|
|
+ if className == "" and resourceId == "" and text == "" and description == "" and \
|
|
|
|
+ bounds != "" and instance == -1:
|
|
|
|
+ uiObject = self.u(bounds=bounds)
|
|
|
|
+ # only instance
|
|
|
|
+ if className == "" and resourceId == "" and text == "" and description == "" and \
|
|
|
|
+ bounds == "" and instance == -1:
|
|
|
|
+ uiObject = self.u(instance=instance)
|
|
return uiObject
|
|
return uiObject
|
|
except Exception, e:
|
|
except Exception, e:
|
|
- print e
|
|
|
|
|
|
+ print "异常:",e
|
|
return uiObject
|
|
return uiObject
|
|
|
|
|
|
'''
|
|
'''
|
|
@@ -438,12 +593,11 @@ class PyUIAutomator():
|
|
print e
|
|
print e
|
|
|
|
|
|
'''
|
|
'''
|
|
- 作用:根据传入的chooseType,获取当前界面聚焦的对象
|
|
|
|
- 参数:
|
|
|
|
- 注意:
|
|
|
|
- 例子:self.pyUIAutomator.getChoosedUIObject("focus")
|
|
|
|
- '''
|
|
|
|
-
|
|
|
|
|
|
+ 作用:根据传入的chooseType,获取当前界面聚焦的对象
|
|
|
|
+ 参数:
|
|
|
|
+ 注意:
|
|
|
|
+ 例子:self.pyUIAutomator.getChoosedUIObject("focus")
|
|
|
|
+ '''
|
|
def getChoosedUIObject(self, chooseType, resourceId='', text=''):
|
|
def getChoosedUIObject(self, chooseType, resourceId='', text=''):
|
|
if chooseType.lower() == "focus":
|
|
if chooseType.lower() == "focus":
|
|
return self.getFocusedUIObject(resourceId=resourceId, text=text)
|
|
return self.getFocusedUIObject(resourceId=resourceId, text=text)
|
|
@@ -1095,6 +1249,230 @@ class FocusManageAndroid():
|
|
print "执行%s 次查找,仍未找到目标焦点!!" % (str(Max_Try))
|
|
print "执行%s 次查找,仍未找到目标焦点!!" % (str(Max_Try))
|
|
return False
|
|
return False
|
|
|
|
|
|
|
|
+ # zhouyi
|
|
|
|
+ # 在RecyclerView 中 focused控件包含bounds控件
|
|
|
|
+ def toDestFocusByBounds_for_RecyclerView(self, bounds, boundsResourceId="", findDirection="down",
|
|
|
|
+ Max_Try=10, keyType=UATTree.Key_Event, hb_keyDict={}):
|
|
|
|
+ # 按照传入的方向寻找Max_Try次,如果仍未聚焦到选中area,则按照传入方向的反方向 反向寻找 2*Max_Try 次
|
|
|
|
+ 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)
|
|
|
|
+ # 如果界面中没有目标文字的控件出现,则按照传入的方向寻找Max_Try次;仍然未找到 则反方向寻找2*Max_Try次
|
|
|
|
+ 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
|
|
|
|
+
|
|
|
|
+ # class&Bounds
|
|
|
|
+ def toDestFocusByClassBounds_for_RecyclerView(self, className, bounds,classResourceId="", findDirection="down",
|
|
|
|
+ Max_Try=10, keyType=UATTree.Key_Event, hb_keyDict={}):
|
|
|
|
+ # 按照传入的方向寻找Max_Try次,如果仍未聚焦到选中area,则按照传入方向的反方向 反向寻找 2*Max_Try 次
|
|
|
|
+ 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
|
|
|
|
+ # print "destUIObject.info",destUIObjectInfo
|
|
|
|
+ try:
|
|
|
|
+ # destBounds = destUIObject.info['bounds']
|
|
|
|
+ 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)
|
|
|
|
+ # 如果界面中没有目标文字的控件出现,则按照传入的方向寻找Max_Try次;仍然未找到 则反方向寻找2*Max_Try次
|
|
|
|
+ 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
|
|
|
|
+
|
|
|
|
+ # class
|
|
|
|
+ def toDestFocusByClass_for_RecyclerView(self, className, classResourceId="", findDirection="down",
|
|
|
|
+ Max_Try=10, keyType=UATTree.Key_Event, hb_keyDict={}):
|
|
|
|
+ # 按照传入的方向寻找Max_Try次,如果仍未聚焦到选中area,则按照传入方向的反方向 反向寻找 2*Max_Try 次
|
|
|
|
+ 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
|
|
|
|
+ # print "destUIObject.info",destUIObjectInfo
|
|
|
|
+ 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)
|
|
|
|
+ # 如果界面中没有目标文字的控件出现,则按照传入的方向寻找Max_Try次;仍然未找到 则反方向寻找2*Max_Try次
|
|
|
|
+ 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
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ # zhouyi
|
|
|
|
+ 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)
|
|
|
|
+ # targetUIObject = self.u.getUiObject(bounds=bounds)
|
|
|
|
+ # print "targetUIObject",targetUIObject
|
|
|
|
+ # print "zhouyibounds",bounds
|
|
|
|
+ # print "targetUIObject.info:", targetUIObject.info
|
|
|
|
+ # destBounds = targetUIObject.info['bounds']
|
|
|
|
+ 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控件属性,
|
|
作用:在界面中 中 focused控件中既没有包含content-des控件属性,也没有text控件属性,
|
|
采用单张图片模板匹配 用于聚焦目标焦点
|
|
采用单张图片模板匹配 用于聚焦目标焦点
|
|
@@ -1881,6 +2259,7 @@ class FocusManageAndroid():
|
|
|
|
|
|
|
|
|
|
def pressKeyByType(self, keyName, keyType = UATTree.Key_Event, times = 1, duration = 1.0):
|
|
def pressKeyByType(self, keyName, keyType = UATTree.Key_Event, times = 1, duration = 1.0):
|
|
|
|
+ print "pressKeyByType:",keyName,keyType
|
|
if keyType == UATTree.Key_Event:
|
|
if keyType == UATTree.Key_Event:
|
|
return self.u.pressKeyTimes(keyName, times, duration)
|
|
return self.u.pressKeyTimes(keyName, times, duration)
|
|
elif keyType == UATTree.Key_IR:
|
|
elif keyType == UATTree.Key_IR:
|