本文整理汇总了Python中uiautomator.Adb.devices方法的典型用法代码示例。如果您正苦于以下问题:Python Adb.devices方法的具体用法?Python Adb.devices怎么用?Python Adb.devices使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类uiautomator.Adb
的用法示例。
在下文中一共展示了Adb.devices方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: adb
# 需要导入模块: from uiautomator import Adb [as 别名]
# 或者: from uiautomator.Adb import devices [as 别名]
class adb(object):
'''
classdocs
'''
def __init__(self):
'''
Constructor
'''
self.instAdb=Adb()
self.devSerialNoms= self.instAdb.devices().keys()
self.devcount = len(self.devSerialNoms)
self.devSerial = self.instAdb.device_serial()
def getSerials(self):
return self.devSerialNoms
#return self.devSerialNoms
def getDeviceCount(self):
return self.devcount
def getSerial(self):
return self.devSerial
示例2: test_serial
# 需要导入模块: from uiautomator import Adb [as 别名]
# 或者: from uiautomator.Adb import devices [as 别名]
def test_serial(self):
serial = "abcdef1234567890"
adb = Adb(serial)
self.assertEqual(adb.default_serial, serial)
adb.devices = MagicMock()
adb.devices.return_value = [serial, "123456"]
self.assertEqual(adb.device_serial(), serial)
示例3: test_device_serial
# 需要导入模块: from uiautomator import Adb [as 别名]
# 或者: from uiautomator.Adb import devices [as 别名]
def test_device_serial(self):
with patch.dict('os.environ', {'ANDROID_SERIAL': "ABCDEF123456"}):
adb = Adb()
adb.devices = MagicMock()
adb.devices.return_value = {"ABCDEF123456": "device"}
self.assertEqual(adb.device_serial(), "ABCDEF123456")
with patch.dict('os.environ', {'ANDROID_SERIAL': "ABCDEF123456"}):
adb = Adb()
adb.devices = MagicMock()
adb.devices.return_value = {"ABCDEF123456": "device", "123456ABCDEF": "device"}
self.assertEqual(adb.device_serial(), "ABCDEF123456")
with patch.dict('os.environ', {'ANDROID_SERIAL': "HIJKLMN098765"}):
adb = Adb()
adb.devices = MagicMock()
adb.devices.return_value = {"ABCDEF123456": "device", "123456ABCDEF": "device"}
with self.assertRaises(EnvironmentError):
adb.device_serial()
with patch.dict('os.environ', {}, clear=True):
adb = Adb()
adb.devices = MagicMock()
adb.devices.return_value = {"ABCDEF123456": "device", "123456ABCDEF": "device"}
with self.assertRaises(EnvironmentError):
adb.device_serial()
with patch.dict('os.environ', {}, clear=True):
adb = Adb()
adb.devices = MagicMock()
adb.devices.return_value = {"ABCDEF123456": "device"}
print(adb.devices())
self.assertEqual(adb.device_serial(), "ABCDEF123456")
with self.assertRaises(EnvironmentError):
adb = Adb()
adb.devices = MagicMock()
adb.devices.return_value = {}
adb.device_serial()
示例4: test_devices
# 需要导入模块: from uiautomator import Adb [as 别名]
# 或者: from uiautomator.Adb import devices [as 别名]
def test_devices(self):
adb = Adb()
adb.raw_cmd = MagicMock()
adb.raw_cmd.return_value.communicate.return_value = (b"List of devices attached \r\n014E05DE0F02000E device\r\n489328DKFL7DF device", b"")
self.assertEqual(adb.devices(), {"014E05DE0F02000E": "device", "489328DKFL7DF": "device"})
adb.raw_cmd.assert_called_once_with("devices")
adb.raw_cmd.return_value.communicate.return_value = (b"List of devices attached \n\r014E05DE0F02000E device\n\r489328DKFL7DF device", b"")
self.assertEqual(adb.devices(), {"014E05DE0F02000E": "device", "489328DKFL7DF": "device"})
adb.raw_cmd.return_value.communicate.return_value = (b"List of devices attached \r014E05DE0F02000E device\r489328DKFL7DF device", b"")
self.assertEqual(adb.devices(), {"014E05DE0F02000E": "device", "489328DKFL7DF": "device"})
adb.raw_cmd.return_value.communicate.return_value = (b"List of devices attached \n014E05DE0F02000E device\n489328DKFL7DF device", b"")
self.assertEqual(adb.devices(), {"014E05DE0F02000E": "device", "489328DKFL7DF": "device"})
adb.raw_cmd.return_value.communicate.return_value = (b"not match", "")
with self.assertRaises(EnvironmentError):
adb.devices()
示例5: UiHub
# 需要导入模块: from uiautomator import Adb [as 别名]
# 或者: from uiautomator.Adb import devices [as 别名]
class UiHub(object):
"""
represents a set of Device
"""
def __init__(self,config=None):
"""
:return:
"""
self.config = config
# dict of devices connected to the hub, key is the device_id
self.connected_devices = {}
# dict of active devices , key is alias
self._devices = {}
# device_ids available ( eg not actice)
self.available_devices = []
self.adb = Adb()
def device_list(self):
"""
:return: list : list of android connected device
"""
self.connected_devices = self.adb.devices()
return self.connected_devices
def device(self,alias):
"""
return the given connected device info
:param alias:
:return:
"""
try:
c = self.connected_devices
assert c != {}
except:
self.device_list()
return self.connected_devices[alias]
def add_device(self,alias,serial=None,applications=None):
"""
add a device , make it active
if no serial is specified take a random device_it (not used ) amoung the connected devices
:param allias:
:param serial:
:param applications:
:return:
"""
if not serial:
# no serial specified: take a random one
raise NotImplementedError
self._devices[alias]= UiDevice(alias,serial=serial,applications=applications,config=self.config)
return self._devices[alias]
def iter_device(self):
"""
iteration over active devices
:return:
"""
def find_device(self,**kwargs):
"""
示例6: len
# 需要导入模块: from uiautomator import Adb [as 别名]
# 或者: from uiautomator.Adb import devices [as 别名]
Created on 2015. 10. 22.
@author: User
'''
import os, sys
from Libs import ClsActivity as CLS
from uiautomator import Device, Adb, AutomatorDevice
from Libs import SaveToLog as saveLog
from Libs import ModelInfo
import Libs.ClsKeyCode
instAdb=Adb()
devSerials= instAdb.devices().keys()
print(type(devSerials))
osType = sys.platform
sndLog = saveLog()
#sndLog = CLS("test", "test")
if len(devSerials) == 1:
devSerials = instAdb.device_serial()
mstrDevice = Device(devSerials)
mstrInfo = mstrDevice.info
else:
mstrDevSerial, slavDevSerial = devSerials
mstrDevice = Device(mstrDevSerial)
slvDevice = Device(slavDevSerial)
mstrInfo = mstrDevice.info