本文整理汇总了Python中mozdevice.DeviceManagerADB类的典型用法代码示例。如果您正苦于以下问题:Python DeviceManagerADB类的具体用法?Python DeviceManagerADB怎么用?Python DeviceManagerADB使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DeviceManagerADB类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run_firefox_for_android
def run_firefox_for_android(build_obj, params):
"""
Launch Firefox for Android on the connected device.
Optional 'params' allow parameters to be passed to Firefox.
"""
adb_path = _find_sdk_exe(build_obj.substs, 'adb', False)
if not adb_path:
adb_path = 'adb'
dm = DeviceManagerADB(autoconnect=False, adbPath=adb_path, retryLimit=1)
try:
#
# Construct an adb command similar to:
#
# $ adb shell am start -a android.activity.MAIN \
# -n org.mozilla.fennec_$USER \
# -d <url param> \
# --es args "<params>"
#
app = "%s/org.mozilla.gecko.BrowserApp" % build_obj.substs['ANDROID_PACKAGE_NAME']
cmd = ['am', 'start', '-a', 'android.activity.MAIN', '-n', app]
if params:
for p in params:
if urlparse.urlparse(p).scheme != "":
cmd.extend(['-d', p])
params.remove(p)
break
if params:
cmd.extend(['--es', 'args', '"%s"' % ' '.join(params)])
_log_debug(cmd)
output = dm.shellCheckOutput(cmd, timeout=10)
_log_info(output)
except DMError:
_log_warning("unable to launch Firefox for Android")
return 1
return 0
示例2: remoteInit
def remoteInit(self):
if (self.remoteInitialized != None):
return
self.dm = DeviceManagerADB(self.config.remoteAddr, 5555)
self.appName = self.dm.packageName
self.appRoot = self.dm.getAppRoot(self.appName)
self.profileBase = self.appRoot + "/files/mozilla"
self.profiles = self.getProfiles()
# Install a signal handler that shuts down our external programs on SIGINT
signal.signal(signal.SIGINT, self.signal_handler)
if (len(self.profiles) == 0):
print "Failed to detect any valid profile, aborting..."
return 1
self.defaultProfile = self.profiles[0]
if (len(self.profiles) > 1):
print "Multiple profiles detected, using the first: " + self.defaultProfile
# Workaround for bug 754575. Avoid using DeviceManagerADB's "removeDir" because
# that calls "rm" on every single entry which takes a lot of additional time.
print "Purging possible cache leftover directories..."
self.dm.runCmd(['shell', 'rm', '-r', self.profileBase + "/" + self.defaultProfile + "/Cache.Trash*"]).communicate()
self.remoteInitialized = True
示例3: check_marionette_exists
def check_marionette_exists(adb="adb"):
dm = DeviceManagerADB(adbPath=adb)
if dm.dirExists(INSTALL_DIR):
return True
else:
dm.forward("tcp:2828", "tcp:2828")
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(('localhost', 2828))
data = sock.recv(16)
sock.close()
if 'root' in data:
return True
except socket.error:
return False
return False
示例4: __init__
def __init__(self, adb="adb", serial=None):
self.test_results = {}
self.test_results_file = None
self.m = None
self.gaia_apps = None
self.screenshot_path = None
self.logcat_path = None
self.app_name = None
self.attempt = None
self.num_apps = None
self.device = None
self.serial = serial
self.port = None
self.run_log = logging.getLogger('marketplace-test')
if self.serial:
self.dm = DeviceManagerADB(adbPath=adb, deviceSerial=serial)
else:
self.dm = DeviceManagerADB(adbPath=adb)
示例5: setUp
def setUp(self):
self.dm = DeviceManagerADB()
if not os.path.exists(self.tempLocalDir):
os.mkdir(self.tempLocalDir)
if not os.path.exists(self.tempLocalFile):
# Create empty file
open(self.tempLocalFile, 'w').close()
self.tempRemoteDir = self.dm.getTempDir()
self.tempRemoteFile = os.path.join(self.tempRemoteDir,
os.path.basename(self.tempLocalFile))
示例6: _get_device_platform
def _get_device_platform(substs):
# PIE executables are required when SDK level >= 21 - important for gdbserver
adb_path = _find_sdk_exe(substs, "adb", False)
if not adb_path:
adb_path = "adb"
dm = DeviceManagerADB(autoconnect=False, adbPath=adb_path, retryLimit=1)
sdk_level = None
try:
cmd = ["getprop", "ro.build.version.sdk"]
_log_debug(cmd)
output = dm.shellCheckOutput(cmd, timeout=10)
if output:
sdk_level = int(output)
except:
_log_warning("unable to determine Android sdk level")
pie = ""
if sdk_level and sdk_level >= 21:
pie = "-pie"
if substs["TARGET_CPU"].startswith("arm"):
return "arm%s" % pie
return "x86%s" % pie
示例7: _get_device_platform
def _get_device_platform(substs):
# PIE executables are required when SDK level >= 21 - important for gdbserver
adb_path = _find_sdk_exe(substs, 'adb', False)
if not adb_path:
adb_path = 'adb'
dm = DeviceManagerADB(autoconnect=False, adbPath=adb_path, retryLimit=1)
sdk_level = None
try:
cmd = ['getprop', 'ro.build.version.sdk']
_log_debug(cmd)
output = dm.shellCheckOutput(cmd, timeout=10)
if output:
sdk_level = int(output)
except:
_log_warning("unable to determine Android sdk level")
pie = ''
if sdk_level and sdk_level >= 21:
pie = '-pie'
if substs['TARGET_CPU'].startswith('arm'):
return 'arm%s' % pie
return 'x86%s' % pie
示例8: __init__
def __init__(self, avd_type="4.3", verbose=False, substs=None):
self.emulator_log = None
self.emulator_path = "emulator"
self.verbose = verbose
self.substs = substs
self.avd_type = self._get_avd_type(avd_type)
self.avd_info = AVD_DICT[self.avd_type]
adb_path = self._find_sdk_exe("adb", False)
if not adb_path:
adb_path = "adb"
self.dm = DeviceManagerADB(autoconnect=False, adbPath=adb_path, retryLimit=1)
self.dm.default_timeout = 10
self._log_debug("Emulator created with type %s" % self.avd_type)
示例9: DeviceManagerADBTestCase
class DeviceManagerADBTestCase(unittest.TestCase):
tempLocalDir = "tempDir"
tempLocalFile = os.path.join(tempLocalDir, "tempfile.txt")
tempRemoteDir = None
tempRemoteFile = None
def setUp(self):
self.dm = DeviceManagerADB()
if not os.path.exists(self.tempLocalDir):
os.mkdir(self.tempLocalDir)
if not os.path.exists(self.tempLocalFile):
# Create empty file
open(self.tempLocalFile, 'w').close()
self.tempRemoteDir = self.dm.getTempDir()
self.tempRemoteFile = os.path.join(self.tempRemoteDir,
os.path.basename(self.tempLocalFile))
def tearDown(self):
os.remove(self.tempLocalFile)
os.rmdir(self.tempLocalDir)
if self.dm.dirExists(self.tempRemoteDir):
self.dm.removeDir(self.tempRemoteDir)
示例10: reset
def reset(self, prefFile):
self.dm = DeviceManagerADB(self.config.remoteAddr, 5555)
# Install a signal handler that shuts down our external programs on SIGINT
signal.signal(signal.SIGINT, self.signal_handler)
# Standard init stuff
self.appName = self.dm.packageName
self.appRoot = self.dm.getAppRoot(self.appName)
self.profileBase = self.appRoot + "/files/mozilla"
# Ensure no Fennec instance is running
self.stopFennec()
# Now try to get the old profile(s)
self.profiles = self.getProfiles()
for profile in self.profiles:
self.dm.removeDir(self.profileBase + "/" + profile)
self.dm.removeFile(self.profileBase + "/profiles.ini")
# Start Fennec, so a new profile is created
self.startFennec(blank=True)
# Grant some time to create profile
time.sleep(self.config.runTimeout * 2)
# Stop Fennec again
self.stopFennec()
# Now try to get the profile(s) again
self.profiles = self.getProfiles()
if (len(self.profiles) == 0):
print "Failed to detect any valid profile, aborting..."
return 1
self.defaultProfile = self.profiles[0]
if (len(self.profiles) > 1):
print "Multiple profiles detected, using the first: " + self.defaultProfile
# Push prefs.js to profile
self.dm.pushFile(prefFile, self.profileBase + "/" + self.defaultProfile + "/prefs.js")
# Try to install addon if requested by configuration
if self.config.addon != None:
self.ensureExtensionInstalled(self.config.addon)
print "Successfully resetted profile."
示例11: __init__
def __init__(self, avd_type="4.3", verbose=False, substs=None, device_serial=None):
global verbose_logging
self.emulator_log = None
self.emulator_path = "emulator"
verbose_logging = verbose
self.substs = substs
self.avd_type = self._get_avd_type(avd_type)
self.avd_info = AVD_DICT[self.avd_type]
adb_path = _find_sdk_exe(substs, "adb", False)
if not adb_path:
adb_path = "adb"
self.dm = DeviceManagerADB(autoconnect=False, adbPath=adb_path, retryLimit=1, deviceSerial=device_serial)
self.dm.default_timeout = 10
_log_debug("Emulator created with type %s" % self.avd_type)
示例12: __init__
def __init__(self, avd_type='4.3', verbose=False, substs=None):
global verbose_logging
self.emulator_log = None
self.emulator_path = 'emulator'
verbose_logging = verbose
self.substs = substs
self.avd_type = self._get_avd_type(avd_type)
self.avd_info = AVD_DICT[self.avd_type]
adb_path = self._find_sdk_exe('adb', False)
if not adb_path:
adb_path = 'adb'
self.dm = DeviceManagerADB(autoconnect=False, adbPath=adb_path, retryLimit=1)
self.dm.default_timeout = 10
_log_debug("Emulator created with type %s" % self.avd_type)
示例13: __init__
def __init__(self, avd_type='4.3', verbose=False, substs=None, device_serial=None):
global verbose_logging
self.emulator_log = None
self.emulator_path = 'emulator'
verbose_logging = verbose
self.substs = substs
self.avd_type = self._get_avd_type(avd_type)
self.avd_info = AVD_DICT[self.avd_type]
self.gpu = True
self.restarted = False
adb_path = _find_sdk_exe(substs, 'adb', False)
if not adb_path:
adb_path = 'adb'
self.dm = DeviceManagerADB(autoconnect=False, adbPath=adb_path, retryLimit=1,
deviceSerial=device_serial)
self.dm.default_timeout = 10
_log_debug("Running on %s" % platform.platform())
_log_debug("Emulator created with type %s" % self.avd_type)
示例14: DeviceManagerADBTestCase
class DeviceManagerADBTestCase(unittest.TestCase):
tempLocalDir = "tempDir"
tempLocalFile = os.path.join(tempLocalDir, "tempfile.txt")
tempRemoteDir = None
tempRemoteFile = None
tempRemoteSystemFile = None
def setUp(self):
self.assertTrue(find_mount_permissions(self.dm, "/system"), "ro")
self.assertTrue(os.path.exists(self.tempLocalDir))
self.assertTrue(os.path.exists(self.tempLocalFile))
if self.dm.fileExists(self.tempRemoteFile):
self.dm.removeFile(self.tempRemoteFile)
self.assertFalse(self.dm.fileExists(self.tempRemoteFile))
if self.dm.fileExists(self.tempRemoteSystemFile):
self.dm.removeFile(self.tempRemoteSystemFile)
self.assertTrue(self.dm.dirExists(self.tempRemoteDir))
@classmethod
def setUpClass(self):
self.dm = DeviceManagerADB()
if not os.path.exists(self.tempLocalDir):
os.mkdir(self.tempLocalDir)
if not os.path.exists(self.tempLocalFile):
# Create empty file
open(self.tempLocalFile, 'w').close()
self.tempRemoteDir = self.dm.getTempDir()
self.tempRemoteFile = os.path.join(self.tempRemoteDir,
os.path.basename(self.tempLocalFile))
self.tempRemoteSystemFile = \
os.path.join("/system", os.path.basename(self.tempLocalFile))
@classmethod
def tearDownClass(self):
os.remove(self.tempLocalFile)
os.rmdir(self.tempLocalDir)
if self.dm.dirExists(self.tempRemoteDir):
# self.tempRemoteFile will get deleted with it
self.dm.removeDir(self.tempRemoteDir)
if self.dm.fileExists(self.tempRemoteSystemFile):
self.dm.removeFile(self.tempRemoteSystemFile)
示例15: configure_devices
def configure_devices(self):
"""
Ensure devices.ini is set up.
"""
keep_going = True
device_ini = os.path.join(self.config['base-dir'], 'devices.ini')
if os.path.exists(device_ini):
response = raw_input(
"Use existing device configuration at %s? (Y/n) " % device_ini).strip()
if not 'n' in response.lower():
self.build_obj.log(logging.INFO, "autophone", {},
"Using device configuration at %s" % device_ini)
return keep_going
keep_going = False
self.build_obj.log(logging.INFO, "autophone", {},
"You must configure at least one Android device before running autophone.")
response = raw_input(
"Configure devices now? (Y/n) ").strip()
if response.lower().startswith('y') or response == '':
response = raw_input(
"Connect your rooted Android test device(s) with usb and press Enter ")
adb_path = 'adb'
try:
if os.path.exists(self.build_obj.substs["ADB"]):
adb_path = self.build_obj.substs["ADB"]
except:
if self.verbose:
self.build_obj.log(logging.ERROR, "autophone", {},
str(sys.exc_info()[0]))
# No build environment?
try:
adb_path = which.which('adb')
except which.WhichError:
adb_path = raw_input(
"adb not found. Enter path to adb: ").strip()
if self.verbose:
print("Using adb at %s" % adb_path)
dm = DeviceManagerADB(autoconnect=False, adbPath=adb_path, retryLimit=1)
device_index = 1
try:
with open(os.path.join(self.config['base-dir'], 'devices.ini'), 'w') as f:
for device in dm.devices():
serial = device[0]
if self.verify_device(adb_path, serial):
f.write("[device-%d]\nserialno=%s\n" % (device_index, serial))
device_index += 1
self.build_obj.log(logging.INFO, "autophone", {},
"Added '%s' to device configuration." % serial)
keep_going = True
else:
self.build_obj.log(logging.WARNING, "autophone", {},
"Device '%s' is not rooted - skipping" % serial)
except:
self.build_obj.log(logging.ERROR, "autophone", {},
"Failed to get list of connected Android devices.")
if self.verbose:
self.build_obj.log(logging.ERROR, "autophone", {},
str(sys.exc_info()[0]))
keep_going = False
if device_index <= 1:
self.build_obj.log(logging.ERROR, "autophone", {},
"No devices configured! (Can you see your rooted test device(s) in 'adb devices'?")
keep_going = False
if keep_going:
self.config['devices-configured'] = True
return keep_going