本文整理汇总了Python中uiautomator.Device类的典型用法代码示例。如果您正苦于以下问题:Python Device类的具体用法?Python Device怎么用?Python Device使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Device类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, serialno=None, **kwargs):
"""Initial AndroidDevice
Args:
serialno: string specify which device
Returns:
AndroidDevice object
Raises:
EnvironmentError
"""
self.__display = None
serialno = serialno or getenv('ATX_ADB_SERIALNO', None)
self._host = kwargs.get('host', getenv('ATX_ADB_HOST', '127.0.0.1'))
self._port = kwargs.get('port', getenv('ATX_ADB_PORT', 5037, type=int))
self._adb = adb.Adb(serialno, self._host, self._port)
serialno = self._adb.device_serial()
kwargs['adb_server_host'] = kwargs.pop('host', self._host)
kwargs['adb_server_port'] = kwargs.pop('port', self._port)
UiaDevice.__init__(self, serialno, **kwargs)
DeviceMixin.__init__(self)
self._randid = base.id_generator(5)
self._serial = serialno
self._uiauto = super(AndroidDevice, self)
self.screen_rotation = None
self.screenshot_method = consts.SCREENSHOT_METHOD_AUTO
self.last_screenshot = None
示例2: __init__
def __init__(self, seral=None):
self.serial = os.environ[ANDROID_SERIAL] if os.environ.has_key(ANDROID_SERIAL) else None
self.working_dir_path = WORKING_DIR_PATH
self.report_dir_path = REPORT_DIR_PATH
self.right_dir_path = WORKING_DIR_PATH
self._internal_storage_dir = DEFAULT_DEVICE_INTERNAL_STORAGE
self.d = Device(self.serial)
示例3: set_serial
def set_serial(self, android_serial):
"""
Set device serial
"""
self.adb = ADB(android_serial)
self.device = Device(android_serial)
self.test_helper = TestHelper(android_serial)
示例4: __init__
def __init__(self, android_serial = None):
# logger.info("Importing Android library")
# print "Importing Android library"
# clm.message("Importing Android library")
self.adb = ADB(android_serial)
self.device = Device(android_serial)
self.test_helper = TestHelper(android_serial)
示例5: __init__
def __init__(self, serial=None):
"""
"""
logger.info("<p>Device=%s>" % serial, html=True)
print "<p>Device=%s>" % serial
self._result = ""
self.starttime = 0
self.d = Device(serial)
self.adb = Adb(serial)
self.debug = "True"
示例6: __init__
def __init__(self):
'''
create device instance.
'''
self.serial = os.environ[ANDROID_SERIAL] if os.environ.has_key(ANDROID_SERIAL) else None
self.working_dir_path = WORKING_DIR_PATH
self.report_dir_path = REPORT_DIR_PATH
self.right_dir_path = RIGHT_DIR_PATH
self.d = Device(self.serial)
self.d.screenshot = self.screenshot_common
示例7: __init__
def __init__(self, environment, monitor_serial):
self.monitor_serial = monitor_serial
self.specifying_monitor = '-s {}'.format(self.monitor_serial)
self.device = Device(self.monitor_serial)
self.build_location ="mon_test\Apps\monitor_build\dev-dell-release-SINK-0.0.3143.7736342\system"
self.build_version = self.get_build_version()
self.monitor_name = self.get_monitor_name_by_ui()
self.find_command = " | findstr" if platform.platform() == "Windows" else "| grep"
print 'Monitor:init - orientation=%s' % self.device.orientation
示例8: Monitor
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
示例9: __init__
def __init__(self, deviceserial):
'''
Constructor
'''
#sndLog = CLS("test", "test")
self.osType = sys.platform
self.mstrInfo = {}
#self.devSerials = self.instAdb.device_serial()
self.mstrDevice = Device(deviceserial)
self.mstrInfo = self.mstrDevice.info
示例10: __init__
def __init__(self,sn,app):
self.dev_sn = sn
self.device = Device(self.dev_sn)
self.dev_displayHeight = self.device.info['displayHeight']
self.dev_displayWidth = self.device.info['displayWidth']
self.icon_x = self.dev_displayWidth * 12 / 100
self.icon_y = self.dev_displayHeight * 52 / 100
self.is_app_settings_done = False
if len(app) > 0 and app[0] != '':
self.app_name = app[0]
if len(app) > 1 and app[1] != '':
self.app_path = app[1]
self.app_package_name = self.get_package_name()
self.install_app()
if len(app) > 2 and app[2] != '':
self.app_package_name = app[2]
else:
self.app_package_name = os.popen("adb -s %s shell pm list package | grep -i %s | awk -F ':' '{print$2}'"%(self.dev_sn,self.app_name)).read().strip("\r\n")
self.set_app_settings_done_flag()
self.clean_result()
self.load_resource()
示例11: set_serial
def set_serial(self, serial):
"""Specify given *serial* device to perform test.
or export ANDROID_SERIAL=CXFS42343 if you have many devices connected but you don't use this
interface
When you need to use multiple devices, do not use this keyword to switch between devices in test execution.
And set the serial to each library.
Using different library name when importing this library according to
http://robotframework.googlecode.com/hg/doc/userguide/RobotFrameworkUserGuide.html?r=2.8.5.
Examples:
| Setting | Value | Value | Value |
| Library | UiTestLib | WITH NAME | Mobile1 |
| Library | UiTestLib | WITH NAME | Mobile2 |
And set the serial to each library.
| Test Case | Action | Argument |
| Multiple Devices | Mobile1.Set Serial | device_1's serial |
| | Mobile2.Set Serial | device_2's serial |
"""
self.d = Device(serial)
self.adb = Adb(serial)
示例12: set_serial
def set_serial(self, android_serial):
"""
Specify given *android_serial* device to perform test.
You do not have to specify the device when there is only one device connects to the computer.
When you need to use multiple devices, do not use this keyword to switch between devices in test execution.
Using different library name when importing this library according to http://robotframework.googlecode.com/hg/doc/userguide/RobotFrameworkUserGuide.html?r=2.8.4#setting-custom-name-to-test-library.
| ==Setting== | ==Value== | ==Value== | ==Value== |
| Library | Mobile | WITH NAME | Mobile1 |
| Library | Mobile | WITH NAME | Mobile2 |
And set the serial to each library.
| Test Case | Action | Argument |
| Multiple Devices | Mobile1.Set Serial | device_1's serial |
| | Mobile2.Set Serial | device_2's serial |
"""
self.adb = ADB(android_serial)
self.device = Device(android_serial)
self.test_helper = TestHelper(self.adb)
示例13: AndroidDevice
class AndroidDevice(object):
'''
wrapper for android uiautomator-server binding(pip install uiautomator).
provide android device event inject, ui object inspect and image comparison.
'''
def __init__(self, seral=None):
'''
create device instance.
'''
self.serial = os.environ[ANDROID_SERIAL] if os.environ.has_key(ANDROID_SERIAL) else None
self.working_dir_path = WORKING_DIR_PATH
self.report_dir_path = REPORT_DIR_PATH
self.right_dir_path = WORKING_DIR_PATH
self._internal_storage_dir = DEFAULT_DEVICE_INTERNAL_STORAGE
self.d = Device(self.serial)
#try:
# if int(self.d.info['sdkInt']) <= 17:
# self.d.screenshot = self.screenshot_common
#except:
# pass
def set_internal_storage_dir(self, path):
self._internal_storage_dir = path
def __getattr__(self, attr):
'''
forward method/attrbuite to uiautomator device if method support by uiautomator.
'''
if hasattr(self.d, attr):
if attr == 'screenshot':
return self.screenshot_common
m = getattr(self.d, attr)
if inspect.ismethod(m):
def wrapper(*args, **kwargs):
return m(*args, **kwargs)
return wrapper
else:
return m
raise AttributeError(attr)
def __call__(self, *args, **kwargs):
'''
selector support:
d(text="Settings").click()
'''
return self.d(*args, **kwargs)
@property
def orientation(self):
return self.d.orientation
@orientation.setter
def orientation(self, v):
self.d.orientation = v
def serial(self):
'''
device serial number from $ANDROID_SERIAL
'''
return self.serial
def sleep(self, sec):
time.sleep(sec)
#device event inject
def start_activity(self, **intent_params):
'''
Starts an Activity on the device by sending an Intent which constructed from the specified parameters.
The params of Intent supported from adb docs:
<INTENT> specifications include these flags:
[-a <ACTION>] [-d <DATA_URI>] [-t <MIME_TYPE>]
[-c <CATEGORY> [-c <CATEGORY>] ...]
[-e|--es <EXTRA_KEY> <EXTRA_STRING_VALUE> ...]
[--esn <EXTRA_KEY> ...]
[--ez <EXTRA_KEY> <EXTRA_BOOLEAN_VALUE> ...]
[-e|--ei <EXTRA_KEY> <EXTRA_INT_VALUE> ...]
[-n <COMPONENT>] [-f <FLAGS>]
[<URI>]
@type intent_params: dictionary
@param intent_params: the properties of an Intent.
property support: component/action/data/mimetype/categories/extras/flags/uri
@rtype: AndroidDevice
@return: a instance of AndroidDevice.
'''
#d.server.adb.cmd('shell','am', 'start', '-a', 'android.intent.action.DIAL','tel:13581739891').communicate()
#sys.stderr.write(str(intent_params))
keys = intent_params.keys()
shellcmd = ['shell', 'am', 'start']
if 'component' in keys:
shellcmd.append('-n')
shellcmd.append(intent_params['component'])
if 'action' in keys:
shellcmd.append('-a')
shellcmd.append(intent_params['action'])
if 'data' in keys:
shellcmd.append('-d')
#.........这里部分代码省略.........
示例14: enable_developer_setting
from uiautomator import Device
import utility.common as u
def enable_developer_setting(self, name):
checkbox = self(className="android.widget.ListView",resourceId="android:id/list").\
child_by_text(name,className="android.widget.LinearLayout").\
child(className="android.widget.CheckBox")
if checkbox.checked == False:
print (name + " is not enabled, enabling it")
checkbox.click()
else:
print(name + " enabled")
def ChangeDeveloper_settings(self):
package = 'com.android.settings'
activity = '.DevelopmentSettings'
component_name = package + '/' + activity
u.start_activity(self,component_name)
self.wait.update()
enable_developer_setting(self,u'Stay awake')
enable_developer_setting(self,u'Allow mock locations')
if __name__ == '__main__':
d = Device()
d.wakeup()
# Press the HOME button to start the test from the home screen
d.press.home()
ChangeDeveloper_settings(d)
# Press the HOME button to start the test from the home screen
# d.press.home()
示例15: test
class test(object):
dev_sn = ""
dev_displayHeight = 0
dev_displayWidth = 0
icon_x = 0
icon_y = 0
app_name = ""
app_path = ""
app_package_name = ""
class_name = ""
result = ""
install_time = ""
device = Device();
DIR_VERT, DIR_HORIZ ,DIR_NONE = range(3)
SWIPE_DIR_UP, SWIPE_DIR_DOWN, SWIPE_DIR_LEFT, SWIPE_DIR_RIGHT = range(4)
def __init__(self,sn,app):
self.dev_sn = sn
self.device = Device(self.dev_sn)
self.dev_displayHeight = self.device.info['displayHeight']
self.dev_displayWidth = self.device.info['displayWidth']
self.icon_x = self.dev_displayWidth * 12 / 100
self.icon_y = self.dev_displayHeight * 52 / 100
self.is_app_settings_done = False
if len(app) > 0 and app[0] != '':
self.app_name = app[0]
if len(app) > 1 and app[1] != '':
self.app_path = app[1]
self.app_package_name = self.get_package_name()
self.install_app()
if len(app) > 2 and app[2] != '':
self.app_package_name = app[2]
else:
self.app_package_name = os.popen("adb -s %s shell pm list package | grep -i %s | awk -F ':' '{print$2}'"%(self.dev_sn,self.app_name)).read().strip("\r\n")
self.set_app_settings_done_flag()
self.clean_result()
self.load_resource()
def get_package_name(self):
p = re.compile(r"package: name=\'([\w+.]*)\'")
s = os.popen("./aapt dump badging %s | grep -i package"%(self.app_path)).read()
package_name = re.findall(p,s)
return ''.join(package_name)
def icon_click(self):
os.system("adb -s %s shell input tap %s %s"%(self.dev_sn,self.icon_x,self.icon_y))
def my_func_name(self):
return inspect.stack()[1][3]
def logout(self,function_name,log):
print ">>> (%s) [%s.%s] :"%(self.app_name, self.__class__.__name__, function_name)+log
def is_AppBench_root_page(self):
if self.device(text="AppBench").exists and self.device(text="Tutorial").exists:
return True
else:
return False
def wait_for_fps_result(self):
self.logout(self.my_func_name(),"...")
while True:
if self.is_AppBench_root_page() == False:
if self.device(text="AppBench").exists:
return True
else:
continue
else:
return False
def swipe_vert(self,swipe_times,direction):
if direction == self.SWIPE_DIR_UP:
src_x = self.dev_displayWidth / 2
src_y = self.dev_displayHeight * 4 / 5
des_x = self.dev_displayWidth / 2
des_y = self.dev_displayHeight * 1 / 5
elif direction == self.SWIPE_DIR_DOWN:
src_x = self.dev_displayWidth / 2
src_y = self.dev_displayHeight * 1 / 5
des_x = self.dev_displayWidth / 2
des_y = self.dev_displayHeight * 4 / 5
else:
self.logout(self.my_func_name(),"direction is error...")
return False
for i in range(swipe_times):
self.device.swipe(src_x,src_y,des_x,des_y,steps=20)
return True
def swipe_horiz(self,swipe_times,direction):
if direction == self.SWIPE_DIR_RIGHT:
src_x = self.dev_displayWidth * 1 / 5
src_y = self.dev_displayHeight / 3
des_x = self.dev_displayWidth * 4 / 5
des_y = self.dev_displayHeight / 2
elif direction == self.SWIPE_DIR_LEFT:
src_x = self.dev_displayWidth * 4 / 5
src_y = self.dev_displayHeight / 3
des_x = self.dev_displayWidth * 1 / 5
#.........这里部分代码省略.........