本文整理匯總了Python中uiautomator.Device.watcher方法的典型用法代碼示例。如果您正苦於以下問題:Python Device.watcher方法的具體用法?Python Device.watcher怎麽用?Python Device.watcher使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類uiautomator.Device
的用法示例。
在下文中一共展示了Device.watcher方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: Mobile
# 需要導入模塊: from uiautomator import Device [as 別名]
# 或者: from uiautomator.Device import watcher [as 別名]
#.........這裏部分代碼省略.........
screenshot_path = '%s%s%s.png' % (output_dir, os.sep, st)
self.device.screenshot(screenshot_path, scale, quality)
logger.info('\n<a href="%s">%s</a><br><img src="%s">' % (screenshot_path, st, screenshot_path), html=True)
#Watcher
# def register_click_watcher(self, watcher_name, attributes, *condition_list):
# """
# The watcher click on the object which has the attributes when conditions match
# """
# print type(attributes)
# watcher = self.device.watcher(watcher_name)
# for condition in condition_list:
# watcher.when(**condition)
# watcher.click(**attributes)
# self.device.watchers.run()
# print 'register watcher:%s' % watcher_name
# return
def __unicode_to_dict(self, a_unicode):
a_dict = dict()
dict_item_count = a_unicode.count('=')
for count in range(dict_item_count):
equal_sign_position = a_unicode.find('=')
comma_position = a_unicode.find(',')
a_key = a_unicode[0:equal_sign_position]
if comma_position == -1:
a_value = a_unicode[equal_sign_position + 1:]
else:
a_value = a_unicode[equal_sign_position + 1:comma_position]
a_unicode = a_unicode[comma_position + 1:]
a_dict[a_key] = a_value
return a_dict
def register_click_watcher(self, watcher_name, attributes, *condition_list):
"""
The watcher click on the object which has the *attributes* when conditions match
"""
watcher = self.device.watcher(watcher_name)
for condition in condition_list:
watcher.when(**self.__unicode_to_dict(condition))
watcher.click(**self.__unicode_to_dict(attributes))
self.device.watchers.run()
def register_press_watcher(self, watcher_name, press_keys, *condition_list):
"""
The watcher perform *press_keys* action sequentially when conditions match
"""
def unicode_to_list(a_unicode):
a_list = list()
comma_count = a_unicode.count(',')
for count in range(comma_count + 1):
comma_position = a_unicode.find(',')
if comma_position == -1:
a_list.append(str(a_unicode))
else:
a_list.append(a_unicode[0:comma_position])
a_unicode = a_unicode[comma_position + 1:]
return a_list
watcher = self.device.watcher(watcher_name)
for condition in condition_list:
watcher.when(**self.__unicode_to_dict(condition))
watcher.press(*unicode_to_list(press_keys))
self.device.watchers.run()
def remove_watchers(self, watcher_name = None):
示例2: Mobile
# 需要導入模塊: from uiautomator import Device [as 別名]
# 或者: from uiautomator.Device import watcher [as 別名]
#.........這裏部分代碼省略.........
screenshot_path = '%s%s%s.png' % (output_dir, os.sep, st)
self.device.screenshot(screenshot_path, scale, quality)
logger.info('\n<a href="%s">%s</a><br><img src="%s">' % (screenshot_path, st, screenshot_path), html=True)
#Watcher
# def register_click_watcher(self, watcher_name, selectors, *condition_list):
# """
# The watcher click on the object which has the selectors when conditions match
# """
# print type(selectors)
# watcher = self.device.watcher(watcher_name)
# for condition in condition_list:
# watcher.when(**condition)
# watcher.click(**selectors)
# self.device.watchers.run()
# print 'register watcher:%s' % watcher_name
# return
def __unicode_to_dict(self, a_unicode):
a_dict = dict()
dict_item_count = a_unicode.count('=')
for count in range(dict_item_count):
equal_sign_position = a_unicode.find('=')
comma_position = a_unicode.find(',')
a_key = a_unicode[0:equal_sign_position]
if comma_position == -1:
a_value = a_unicode[equal_sign_position + 1:]
else:
a_value = a_unicode[equal_sign_position + 1:comma_position]
a_unicode = a_unicode[comma_position + 1:]
a_dict[a_key] = a_value
return a_dict
def register_click_watcher(self, watcher_name, selectors, *condition_list):
"""
The watcher click on the object which has the *selectors* when conditions match
"""
watcher = self.device.watcher(watcher_name)
for condition in condition_list:
watcher.when(**self.__unicode_to_dict(condition))
watcher.click(**self.__unicode_to_dict(selectors))
self.device.watchers.run()
def register_press_watcher(self, watcher_name, press_keys, *condition_list):
"""
The watcher perform *press_keys* action sequentially when conditions match
"""
def unicode_to_list(a_unicode):
a_list = list()
comma_count = a_unicode.count(',')
for count in range(comma_count + 1):
comma_position = a_unicode.find(',')
if comma_position == -1:
a_list.append(str(a_unicode))
else:
a_list.append(a_unicode[0:comma_position])
a_unicode = a_unicode[comma_position + 1:]
return a_list
watcher = self.device.watcher(watcher_name)
for condition in condition_list:
watcher.when(**self.__unicode_to_dict(condition))
watcher.press(*unicode_to_list(press_keys))
self.device.watchers.run()
def remove_watchers(self, watcher_name = None):