def __call__(self, device, howmany=1, **locales): """ Takes one or more screenshots from specified device. :param device: string, device identifier (e.g. "TA9890AMTG"). """ locales = locales.values()[0] if device is None: devices = android.list_devices() + ios.list_devices() device = console.prompt_for_options("Choose device", devices) target_dir = os.getcwd() many_screenshots = howmany > 1 or (locales and len(locales) > 1) if many_screenshots: target_dir = os.path.join(target_dir, str(int(time.time() * 1000))) if not os.path.exists(target_dir): os.makedirs(target_dir) for i in range(0, howmany): if device in android.list_devices(): model = android.get_device_model(device).lower().replace( " ", "") manufacturer = android.get_manufacturer( device).lower().replace(" ", "") timestamp = str(int(time.time() * 1000)) screenshot_name = "{0}_{1}_{2}.png".format( model, manufacturer, timestamp) if locales: locale_before = android.get_locale(device) for locale in locales: android.set_locale(device, locale) android.take_screenshot(device, target_dir, locale + "_" + screenshot_name) android.set_locale(device, locale_before) else: android.take_screenshot(device, target_dir, screenshot_name) elif device in ios.list_devices(): model = ios.get_device_model(device).lower().replace(" ", "") timestamp = str(int(time.time() * 1000)) screenshot_name = "{0}_{1}.png".format(model, timestamp) ios.take_screenshot(device, target_dir, screenshot_name) else: log.error("Unknown device given: '{0}'", format(device)) sys.exit(1) # noinspection PyUnboundLocalVariable log.info("Find result at " + (target_dir if many_screenshots else os. path.join(target_dir, screenshot_name)))
def connected_device(): """ Discovers and returns connected device. :returns string: connected device Android or iOS (if single). """ devices = android.list_devices() + ios.list_devices() if not devices or len(devices) > 1: return None return devices[0]
def ios_devices(prefix, parsed_args, **kwargs): """ Returns all connected iOS devices. :param prefix: The prefix text of the last word before the cursor on the command line. :param parsed_args: The result of argument parsing so far. :param kwargs: keyword arguments. :returns list: list of all connected iOS devices. """ devices = ios.list_devices() if not devices: warn("No connected iOS devices") return devices
def connected_device(given_device): """ Validates given connected device. :param given_device Given device name """ devices = android.list_devices() + ios.list_devices() if not devices: raise argparse.ArgumentTypeError("No connected devices") if given_device is not None and given_device not in devices: raise argparse.ArgumentTypeError("Unknown device") if given_device is None and len(devices) > 1: raise argparse.ArgumentTypeError("More than one device") return given_device
def __call__(self, **kwargs): subaction = kwargs[LoggingAction.Meta.action] del kwargs[LoggingAction.Meta.action] if subaction == "start": device = kwargs["device"] if device is None: devices = android.list_devices() + ios.list_devices() device = console.prompt_for_options("Choose device: ", devices) log_file = android.get_log( device) if device in android.list_devices() else ios.get_log( device) log.info("\nFind log at " + log_file) else: log.error("Unknown subcommand given: '{0}'".format(subaction)) sys.exit(1)
def __call__(self, device, platform, hardware, software): """ Prints info for the given device or for all (if device is not specified). :param device: string, device identifier (e.g. "TA9890AMTG"). :param hardware: boolean, True if only hardware info is needed, otherwise False. :param software: boolean, True if only software info is needed, otherwise False. """ android_devices = android.list_devices() ios_devices = ios.list_devices() if device is None: devices = android_devices + ios_devices if not devices: log.error("No connected devices") sys.exit(1) show_hardware = hardware or (not hardware and not software) show_software = software or (not hardware and not software) for device in android_devices: if platform and platform != "android": break log.info("\nAndroid device: {0} ({1} {2})".format( device, android.get_manufacturer(device), android.get_device_model(device))) if show_software: log.info("Android version: {0}".format( android.get_android_version(device))) if show_hardware: log.info("CPU frequency: {0}GHz".format( android.get_cpu_frequency(device))) log.info("RAM size: {0}GB".format( android.get_ram_size(device))) log.info("Screen resolution: {0}".format( android.get_resolution(device))) log.info("SDK version: {0}".format( android.get_sdk_version(device))) log.info("IP address: {0}".format( android.get_ip_address(device))) for device in ios_devices: if platform and platform != "ios": break log.info("\niOS device: {0} ({1})".format( device, ios.get_device_model(device)))