本文整理汇总了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):