本文整理汇总了Python中uiautomator.Adb类的典型用法代码示例。如果您正苦于以下问题:Python Adb类的具体用法?Python Adb怎么用?Python Adb使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Adb类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: adb
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
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_forward_list
def test_forward_list(self):
adb = Adb()
os.name = 'posix'
adb.raw_cmd = MagicMock()
adb.raw_cmd.return_value.communicate.return_value = (b"014E05DE0F02000E tcp:9008 tcp:9008\r\n489328DKFL7DF tcp:9008 tcp:9008", b"")
self.assertEqual(adb.forward_list(), [['014E05DE0F02000E', 'tcp:9008', 'tcp:9008'], ['489328DKFL7DF', 'tcp:9008', 'tcp:9008']])
os.name = 'nt'
self.assertEqual(adb.forward_list(), [])
示例4: test_adb_cmd
def test_adb_cmd(self):
adb = Adb()
adb.device_serial = MagicMock()
adb.device_serial.return_value = "ANDROID_SERIAL"
adb.raw_cmd = MagicMock()
args = ["a", "b", "c"]
adb.cmd(*args)
adb.raw_cmd.assert_called_once_with("-s", "%s" % adb.device_serial(), *args)
adb.device_serial.return_value = "ANDROID SERIAL"
adb.raw_cmd = MagicMock()
args = ["a", "b", "c"]
adb.cmd(*args)
adb.raw_cmd.assert_called_once_with("-s", "'%s'" % adb.device_serial(), *args)
示例5: __init__
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()
示例6: __init__
def __init__(self):
'''
Constructor
'''
self.instAdb=Adb()
self.devSerialNoms= self.instAdb.devices().keys()
self.devcount = len(self.devSerialNoms)
self.devSerial = self.instAdb.device_serial()
示例7: __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"
示例8: test_adb_raw_cmd
def test_adb_raw_cmd(self):
import subprocess
adb = Adb()
adb.adb = MagicMock()
adb.adb.return_value = "adb"
args = ["a", "b", "c"]
with patch("subprocess.Popen") as Popen:
os.name = "posix"
adb.raw_cmd(*args)
Popen.assert_called_once_with(["%s %s" % (adb.adb(), " ".join(args))], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
with patch("subprocess.Popen") as Popen:
os.name = "nt"
adb.raw_cmd(*args)
Popen.assert_called_once_with([adb.adb()] + list(args), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
示例9: test_adb_from_env
def test_adb_from_env(self):
home_dir = '/android/home'
with patch.dict('os.environ', {'ANDROID_HOME': home_dir}):
with patch('os.path.exists') as exists:
exists.return_value = True
os.name = "posix" # linux
adb_obj = Adb()
adb_path = os.path.join(home_dir, "platform-tools", "adb")
self.assertEqual(adb_obj.adb(), adb_path)
exists.assert_called_once_with(adb_path)
self.assertEqual(adb_obj.adb(), adb_path)
exists.assert_called_once_with(adb_path) # the second call will return the __adb_cmd directly
os.name = "nt" # linux
adb_obj = Adb()
adb_path = os.path.join(home_dir, "platform-tools", "adb.exe")
self.assertEqual(adb_obj.adb(), adb_path)
exists.return_value = False
with self.assertRaises(EnvironmentError):
Adb().adb()
示例10: test_devices
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()
示例11: test_forward_list
def test_forward_list(self):
adb = Adb()
adb.version = MagicMock()
adb.version.return_value = ['1.0.31', '1', '0', '31']
adb.raw_cmd = MagicMock()
adb.raw_cmd.return_value.communicate.return_value = (b"014E05DE0F02000E tcp:9008 tcp:9008\r\n489328DKFL7DF tcp:9008 tcp:9008", b"")
self.assertEqual(adb.forward_list(), [['014E05DE0F02000E', 'tcp:9008', 'tcp:9008'], ['489328DKFL7DF', 'tcp:9008', 'tcp:9008']])
adb.version.return_value = ['1.0.29', '1', '0', '29']
with self.assertRaises(EnvironmentError):
adb.forward_list()
示例12: 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)
示例13: BaseClient
class BaseClient(object):
def __init__(self, device_id):
self._device_id = device_id
self._adb_commander = Adb(self._device_id)
self._logcat_thread = threading.Thread(target=self._start_logcat)
self._logcat_thread.start()
self._device = Device(self._device_id)
def open_app(self):
self._device.screen.on()
_package_name, _main_activity_name = utils.get_package_and_main_activity_name()
os.system('adb -s %s shell am force-stop %s' % (self._device_id, _package_name))
self._adb_commander.cmd('shell am start -W %s/%s' % (_package_name, _main_activity_name))
def _start_logcat(self):
log_file_path = os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir, 'log'))
self._adb_commander.cmd('logcat -c' % self._device_id)
self._adb_commander.cmd('logcat> %s/%s.log' % (log_file_path, self._device_id))
def stop_logcat(self):
os.system('ps -e | grep "adb -s %s logcat" | xargs kill' % self._device_id)
示例14: test_forward
def test_forward(self):
adb = Adb()
adb.cmd = MagicMock()
adb.forward(90, 91)
adb.cmd.assert_called_once_with("forward", "tcp:90", "tcp:91")
adb.cmd.return_value.wait.assert_called_once_with()
示例15: print
'''
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)