本文整理汇总了Python中uiautomator.Device.exists方法的典型用法代码示例。如果您正苦于以下问题:Python Device.exists方法的具体用法?Python Device.exists怎么用?Python Device.exists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类uiautomator.Device
的用法示例。
在下文中一共展示了Device.exists方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Monitor
# 需要导入模块: from uiautomator import Device [as 别名]
# 或者: from uiautomator.Device import exists [as 别名]
class Monitor():
def __init__(self):
self.serial = self._get_serial()
self.automation_handle = Device(self.serial)
self.name = self._get_monitor_name()
def _get_serial(self):
output = subprocess.check_output(["adb", "devices"])
starting_time = time.time()
while "offline" in output and time.time() < starting_time + 20:
subprocess.check_output(["adb", "kill-server"])
time.sleep(1)
subprocess.check_output(["adb", "start-server"])
time.sleep(5)
output = subprocess.check_output(["adb", "devices"])
serial = output.rsplit("\n")[1].rsplit("\t")[0].strip()
print "Device serial: %s" % serial
return serial
def _get_monitor_name(self):
output = subprocess.check_output(["adb", "shell", "dumpsys", "|", "findstr", "wifiP2pDevice=Device"], shell=True)
start_index = output.rfind('Device: ', 0)
start_index = start_index + 8
end_index = output.rfind("\n", 0)
name = output[start_index : end_index].strip()
return name
def is_mac_address(self, address):
boo = False
boo = self.automation_handle.exists(description='VideoView ' + address)
return boo
def reboot(self):
checkBootComp = subprocess.check_output('adb {} shell getprop sys.boot_completed'.format(self.serial))
print('start rebbot monitor')
os.system('adb {} reboot'.format(self.serial))
self.is_boot_completed(checkBootComp)
print('reboot monitor completed')
def is_boot_completed(self , bootCompCmd):
screenUp = '-1'
while screenUp != bootCompCmd:
time.sleep(1)
try:
screenUp = subprocess.check_output('adb {} shell getprop sys.boot_completed'.format(self.serial))
except Exception:
print('waiting for monitor' )
print('Screen up and fully loaded')
return True
示例2: ModelInfo
# 需要导入模块: from uiautomator import Device [as 别名]
# 或者: from uiautomator.Device import exists [as 别名]
#.........这里部分代码省略.........
d.orientation = 'n' or 'natural'
return : None
'''
self.mstrDevice.orientation = scrAct
def setFreezeRotation(self,condition=False,choiceDevice='mstr'):
'''
param:
condition : False un-freeze rotation
return : None
'''
self.mstrDevice.freeze_rotation(condition)
def takeScreenShot(self, choiceDevice = 'mstr'):
'''
Description:
take screenshot and save to local file 'home.png' can work until android 4.2
param
image name
'''
def dumpWindowHeirarchy(self,filename='./log/hierachy.xml'):
return self.mstrDevice.dump(filename)
def dumpWindowHeirarchyStream(self):
return self.mstrDevice.dump()
def notification(self):
'''
Open notification, can not work until android 4.3
return : Boolean
'''
return self.mstrDevice.open.Notification()
def quickSettings(self):
'''
open quick settins, can not work until android 4.3
return : Boolean
'''
return self.mstrDevice.open.quick_settings()
def waitidle(self):
'''
wait for current window to idle
return : None
'''
self.mstrDevice.wait.idle()
def waitWindowUpdate(self):
'''
wait until window upate event occurs
return : Boolean
'''
self.mstrDevice.wait.update()
def getCurrentActivityInfo(self, text):
'''
INFOMATION:
{ u'contentDescription': u'',
u'checked': False,
u'scrollable': False,
u'text': u'Settings',
u'packageName': u'com.android.launcher',
u'selected': False,
u'enabled': True,
u'bounds': {u'top': 385,
u'right': 360,
u'bottom': 585,
u'left': 200},
u'className': u'android.widget.TextView',
u'focused': False,
u'focusable': True,
u'clickable': True,
u'chileCount': 0,
u'longClickable': True,
u'visibleBounds': {u'top': 385,
u'right': 360,
u'bottom': 585,
u'left': 200},
u'checkable': False
}
'''
return self.mstrDevice(text).info
def uiObjExist(self,text):
'''
ture if exists, else False
'''
return self.mstrDevice.exists(text)
def watcher(self):
pass
def handler(self):
pass
def selector(self):
pass
def __del__(self):
pass
示例3: AndroidDevice
# 需要导入模块: from uiautomator import Device [as 别名]
# 或者: from uiautomator.Device import exists [as 别名]
#.........这里部分代码省略.........
Perform a click event on the center point on the expected screen region.
If the screen region want to click not found in the current screen snapshot will do nothing
rotation: 0, 90, 180, 270
'''
if args:
if isinstance(args[0], types.IntType):
self.__click_point(*args, **kwargs)
return self
if isinstance(args[0], types.StringType):
self.__click_image(*args, **kwargs)
return self
def __click_point(self, x, y, waittime=1):
'''
click x,y
'''
self.d.click(x, y)
time.sleep(waittime)
def __click_image(self, imagename, waittime=1, threshold=0.01, rotation=0):
'''
if the wanted image found on current screen click it.
if the wanted image not found raise exception and set test to be failure.
'''
expect_image_path = None
current_image_path = None
if os.path.isabs(imagename):
expect_image_path = imagename
current_image_path = join(self.report_dir_path, os.path.basenme(imagename))
else:
expect_image_path = join(self.right_dir_path, imagename)
current_image_path = join(self.report_dir_path, imagename)
assert os.path.exists(expect_image_path), 'the local expected image %s not found!' % expect_image_path
self.d.screenshot(current_image_path)
assert os.path.exists(current_image_path), 'fetch current screen shot image %s failed!' % imagename
pos = getMatchedCenterOffset(subPath=expect_image_path, srcPath=current_image_path, threshold=0.01, rotation=rotation)
if not pos:
reason = 'Fail Reason: The wanted image \'%s\' not found on screen!' % imagename
raise ExpectException(expect_image_path, current_image_path, reason)
self.d.click(pos[0], pos[1])
time.sleep(waittime)
def screenshot_common(self, filename):
'''
if SK version <= 16
Capture the screenshot via adb and store it in the specified location.
'''
png = os.path.basename(filename)
if self.serial:
shell('adb -s %s shell screencap %s%s' % (self.serial, self._internal_storage_dir, png))
shell('adb -s %s pull %s%s %s' % (self.serial, self._internal_storage_dir, png, filename))
else:
shell('adb shell screencap %s%s' % (self._internal_storage_dir, png))
shell('adb pull %s%s %s' % (self._internal_storage_dir, png, filename))
return True
#inspect
def exists(self, **kwargs):
'''
if the expected component exists on current screen layout return true else return false.
'''
return self.d.exists(**kwargs)
def expect(self, imagename, interval=2, timeout=4, threshold=0.01, msg=''):
示例4: AndroidDevice
# 需要导入模块: from uiautomator import Device [as 别名]
# 或者: from uiautomator.Device import exists [as 别名]
#.........这里部分代码省略.........
pkgname = kwargs.pop('packagename')
for k, v in kwargs.items():
if k and v:
shellcmd.append('-e')
shellcmd.append(k)
shellcmd.append(str(v))
shellcmd.append(pkgname)
result = self.d.server.adb.cmd(*shellcmd).communicate()
return result
def TODOinstallPackage(self, **kwargs):
pass
def TODOremovePackage(self, **kwargs):
pass
def press(self, keyname, waittime=1):
#hard, soft key: home,back,up,down,right,left,center,menu,power or ANDROID_KEYEVENT
self.d.press(keyname)
time.sleep(waittime)
return self
def click(self, x, y, waittime=1):
self.d.click(x, y)
time.sleep(waittime)
return self
def click_image(self, imagename, waittime=1, threshold=0.01):
'''
if the wanted image found on current screen click it.
if the wanted image not found raise exception and set test to be failure.
'''
expect_image_path = os.path.join(configer['right_dir_path'], imagename)
assert os.path.exists(expect_image_path), 'the local expected image %s not found!' % imagename
current_image_path = os.path.join(configer['report_dir_path'], imagename)
self.d.screenshot(current_image_path)
assert os.path.exists(current_image_path), 'fetch current screen shot image %s failed!' % imagename
pos = getMatchedCenterOffset(expect_image_path, current_image_path, threshold)
assert pos, 'Fail Reason: The wanted image \'%s\' not found on screen!' % imagename
self.d.click(pos[0], pos[1])
time.sleep(waittime)
return self
def swipe(self, sx, sy, ex, ey, steps=100, waittime=1):
self.d.swipe(sx, sy, ex, ey, steps)
time.sleep(waittime)
return self
def drag(self, sx, sy, ex, ey, steps=100, waittime=1):
self.d.drag(sx, sy, ex, ey, steps)
time.sleep(waittime)
return self
#inspect
def exists(self, **kwargs):
'''
if the expected component exists on current screen layout return true else return false.
'''
return self.d.exists(**kwargs)
#device snapshot
def screenshot(self, filename, waittime=1):
path = os.path.join(configer['report_dir_path'], filename)
self.d.screenshot(path)
return self
示例5: __init__
# 需要导入模块: from uiautomator import Device [as 别名]
# 或者: from uiautomator.Device import exists [as 别名]
#.........这里部分代码省略.........
return output.split(':')[1].strip()
def install_build(self):
os.system("adb -s {} root".format(self.monitor_serial))
os.system("adb -s {} wait-for-device remount".format(self.monitor_serial))
time.sleep(6)
commandToExecute = ("adb -s {} push {} /system/".format(self.monitor_serial, self.build_location))
os.system(commandToExecute)
time.sleep(1)
self.reboot_mon()
def reboot_mon(self):
checkBootComp = 'adb {} shell getprop sys.boot_completed'.format(self.specifying_monitor)
output = subprocess.check_output([c for c in checkBootComp.split()])
print('start rebbot monitor')
os.system('adb {} reboot'.format(self.specifying_monitor))
self.is_boot_completed(output)
print('reboot monitor completed')
def is_boot_completed(self, bootCompCmd):
output = '-1'
while output != bootCompCmd:
time.sleep(1)
try:
screenUp = 'adb {} shell getprop sys.boot_completed'.format(self.specifying_monitor)
output = subprocess.check_output([s for s in screenUp.split()])
except Exception:
print('waiting for monitor')
print('Screen up and fully loaded')
return True
def do_factory_reset(self):
checkBootComp = 'adb {} shell getprop sys.boot_completed'.format(self.specifying_monitor)
output = subprocess.check_output([c for c in checkBootComp.split()])
print('Start doing reboot to the monitor')
self.device(resourceId="com.screenovate.dell.monitorserver:id/settings").click()
self.device(resourceId="com.screenovate.dell.monitorserver:id/reset").click()
self.device(resourceId="com.screenovate.dell.monitorserver:id/reset_ok").click()
print('Start doing factory rest...')
os.system("adb {} logcat".format(self.specifying_monitor))
self.is_boot_completed(output)
def set_wifi_channel(self, channel):
print('Setting wifi channel to {} '.format(channel))
self.device(resourceId="com.screenovate.dell.monitorserver:id/settings").click()
self.device(resourceId="com.screenovate.dell.monitorserver:id/set_wifi_channel").click()
auto_is_checked = self.device(resourceId="com.screenovate.dell.monitorserver:id/channel_auto_checkbox").info['checked']
channel_24_is_checked = self.device(resourceId="com.screenovate.dell.monitorserver:id/channel_auto24_checkbox").info['checked']
channel_5_is_checked = self.device(resourceId="com.screenovate.dell.monitorserver:id/channel_auto5_checkbox").info['checked']
if auto_is_checked or channel_5_is_checked or channel_24_is_checked:
self.device(resourceId="com.screenovate.dell.monitorserver:id/show_advanced").click()
self.device(resourceId="com.screenovate.dell.monitorserver:id/channel_custom_checkbox").click()
self.device(text=channel, className="android.widget.TextView").click()
self.device(resourceId="com.screenovate.dell.monitorserver:id/channel_ok").click()
def get_build_version(self):
build_name = self.build_location
return build_name[build_name.find('K-') + 2:build_name.find("/sys")]
def check_build_version(self):
print('checking version of the build')
build_version = 'adb {} shell dumpsys package com.screenovate.dell.monitorserver'.format(
self.specifying_monitor)
output = subprocess.check_output([b for b in build_version.split()])
return ("versionName={}".format(self.build_version) in output)
def get_monitor_name_by_adb(self):
dumpsys = "adb shell dumpsys | {} wifiP2pDevice=Device".format(self.find_command)
output = subprocess.check_output([c for c in dumpsys.split()])
start_index = output.rfind('Device: ', 0)
start_index = start_index + 8
end_index = output.rfind("\n", 0)
name = output[start_index: end_index].strip()
return name
def verify_nothing_connected(self):
print('verifying nothing connected')
if self.device.exists(resourceId="com.screenovate.dell.monitorserver:id/video_view"):
print('some device connected to monitor , stsrt rebooting monitor')
self.reboot_mon()
print('no device currently connected to monitor')
def get_monitor_name_by_ui(self):
self.verify_nothing_connected()
print("get name from " + self.monitor_serial)
self.monitor_name = self.device(resourceId="com.screenovate.dell.monitorserver:id/ssid").info[
"text"]
return self.monitor_name
def screen_on(self):
print("turning monitor screen on")
os.system("adb {} shell input keyevent 82".format(self.specifying_monitor))
def take_screenshot_test(self):
self.device.screenshot("pictures-test/monitor.png")