How to use device_serial method in ATX

Best Python code snippet using ATX

device_errors.py

Source:device_errors.py Github

copy

Full Screen

1# Copyright 2014 The Chromium Authors. All rights reserved.2# Use of this source code is governed by a BSD-style license that can be3# found in the LICENSE file.4"""5Exception classes raised by AdbWrapper and DeviceUtils.6The class hierarchy for device exceptions is:7 base_error.BaseError8 +-- CommandFailedError9 | +-- AdbCommandFailedError10 | | +-- AdbShellCommandFailedError11 | +-- FastbootCommandFailedError12 | +-- DeviceVersionError13 | +-- DeviceChargingError14 +-- CommandTimeoutError15 +-- DeviceUnreachableError16 +-- NoDevicesError17 +-- MultipleDevicesError18 +-- NoAdbError19"""20from devil import base_error21from devil.utils import cmd_helper22from devil.utils import parallelizer23class CommandFailedError(base_error.BaseError):24 """Exception for command failures."""25 def __init__(self, message, device_serial=None):26 device_leader = '(device: %s)' % device_serial27 if device_serial is not None and not message.startswith(device_leader):28 message = '%s %s' % (device_leader, message)29 self.device_serial = device_serial30 super(CommandFailedError, self).__init__(message)31 def __eq__(self, other):32 return (super(CommandFailedError, self).__eq__(other)33 and self.device_serial == other.device_serial)34 def __ne__(self, other):35 return not self == other36class _BaseCommandFailedError(CommandFailedError):37 """Base Exception for adb and fastboot command failures."""38 def __init__(self, args, output, status=None, device_serial=None,39 message=None):40 self.args = args41 self.output = output42 self.status = status43 if not message:44 adb_cmd = ' '.join(cmd_helper.SingleQuote(arg) for arg in self.args)45 message = ['adb %s: failed ' % adb_cmd]46 if status:47 message.append('with exit status %s ' % self.status)48 if output:49 message.append('and output:\n')50 message.extend('- %s\n' % line for line in output.splitlines())51 else:52 message.append('and no output.')53 message = ''.join(message)54 super(_BaseCommandFailedError, self).__init__(message, device_serial)55 def __eq__(self, other):56 return (super(_BaseCommandFailedError, self).__eq__(other)57 and self.args == other.args58 and self.output == other.output59 and self.status == other.status)60 def __ne__(self, other):61 return not self == other62 def __reduce__(self):63 """Support pickling."""64 result = [None, None, None, None, None]65 super_result = super(_BaseCommandFailedError, self).__reduce__()66 for i in range(len(super_result)):67 result[i] = super_result[i]68 # Update the args used to reconstruct this exception.69 result[1] = (70 self.args, self.output, self.status, self.device_serial, self.message)71 return tuple(result)72class AdbCommandFailedError(_BaseCommandFailedError):73 """Exception for adb command failures."""74 def __init__(self, args, output, status=None, device_serial=None,75 message=None):76 super(AdbCommandFailedError, self).__init__(77 args, output, status=status, message=message,78 device_serial=device_serial)79class FastbootCommandFailedError(_BaseCommandFailedError):80 """Exception for fastboot command failures."""81 def __init__(self, args, output, status=None, device_serial=None,82 message=None):83 super(FastbootCommandFailedError, self).__init__(84 args, output, status=status, message=message,85 device_serial=device_serial)86class DeviceVersionError(CommandFailedError):87 """Exception for device version failures."""88 def __init__(self, message, device_serial=None):89 super(DeviceVersionError, self).__init__(message, device_serial)90class AdbShellCommandFailedError(AdbCommandFailedError):91 """Exception for shell command failures run via adb."""92 def __init__(self, command, output, status, device_serial=None):93 self.command = command94 message = ['shell command run via adb failed on the device:\n',95 ' command: %s\n' % command]96 message.append(' exit status: %s\n' % status)97 if output:98 message.append(' output:\n')99 if isinstance(output, basestring):100 output_lines = output.splitlines()101 else:102 output_lines = output103 message.extend(' - %s\n' % line for line in output_lines)104 else:105 message.append(" output: ''\n")106 message = ''.join(message)107 super(AdbShellCommandFailedError, self).__init__(108 ['shell', command], output, status, device_serial, message)109 def __reduce__(self):110 """Support pickling."""111 result = [None, None, None, None, None]112 super_result = super(AdbShellCommandFailedError, self).__reduce__()113 for i in range(len(super_result)):114 result[i] = super_result[i]115 # Update the args used to reconstruct this exception.116 result[1] = (self.command, self.output, self.status, self.device_serial)117 return tuple(result)118class CommandTimeoutError(base_error.BaseError):119 """Exception for command timeouts."""120 pass121class DeviceUnreachableError(base_error.BaseError):122 """Exception for device unreachable failures."""123 pass124class NoDevicesError(base_error.BaseError):125 """Exception for having no devices attached."""126 def __init__(self, msg=None):127 super(NoDevicesError, self).__init__(128 msg or 'No devices attached.', is_infra_error=True)129class MultipleDevicesError(base_error.BaseError):130 """Exception for having multiple attached devices without selecting one."""131 def __init__(self, devices):132 parallel_devices = parallelizer.Parallelizer(devices)133 descriptions = parallel_devices.pMap(134 lambda d: d.build_description).pGet(None)135 msg = ('More than one device available. Use -d/--device to select a device '136 'by serial.\n\nAvailable devices:\n')137 for d, desc in zip(devices, descriptions):138 msg += ' %s (%s)\n' % (d, desc)139 super(MultipleDevicesError, self).__init__(msg, is_infra_error=True)140class NoAdbError(base_error.BaseError):141 """Exception for being unable to find ADB."""142 def __init__(self, msg=None):143 super(NoAdbError, self).__init__(144 msg or 'Unable to find adb.', is_infra_error=True)145class DeviceChargingError(CommandFailedError):146 """Exception for device charging errors."""147 def __init__(self, message, device_serial=None):...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run ATX automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful