From 8849355f6db4eb3eae0ad19f91f9c8b6007f76c1 Mon Sep 17 00:00:00 2001 From: Alexander Guryanov Date: Fri, 7 Feb 2020 12:18:07 +0700 Subject: [PATCH] Allow to record from multiple devices even if they connected in same time --- .../device_name_calculator.py | 17 +++++++++-------- .../pull_screenshots.py | 18 +++++++++++------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/plugin/src/py/android_screenshot_tests/device_name_calculator.py b/plugin/src/py/android_screenshot_tests/device_name_calculator.py index 44865369..31e5bbcb 100644 --- a/plugin/src/py/android_screenshot_tests/device_name_calculator.py +++ b/plugin/src/py/android_screenshot_tests/device_name_calculator.py @@ -20,8 +20,9 @@ class DeviceNameCalculator: - def __init__(self, executor=AdbExecutor()): + def __init__(self, executor=AdbExecutor(), args = []): self.executor = executor + self.args = args def name(self): api_version_text = self._api_version_text() @@ -64,20 +65,20 @@ def _screen_density_text(self): return 'XXXHDPI' def _screen_density(self): - result = self.executor.execute(['shell', 'wm', 'density']) + result = self.executor.execute(self.args + ['shell', 'wm', 'density']) density = re.search('[0-9]+', result) if density: return density.group(0) def _screen_size_text(self): - result = self.executor.execute(['shell', 'wm', 'size']) + result = self.executor.execute(self.args + ['shell', 'wm', 'size']) density = re.search('[0-9]+x[0-9]+', result) if density: return density.group(0) def _has_play_services(self): try: - output = self.executor.execute(['shell', 'pm', 'path', 'com.google.android.gms']) + output = self.executor.execute(self.args + ['shell', 'pm', 'path', 'com.google.android.gms']) return True if output else False except subprocess.CalledProcessError: return False @@ -87,16 +88,16 @@ def _play_services_text(self): return 'GP' if play_services else 'NO_GP' def _api_version(self): - return self.executor.execute(['shell', 'getprop', 'ro.build.version.sdk']) + return self.executor.execute(self.args + ['shell', 'getprop', 'ro.build.version.sdk']) def _api_version_text(self): return 'API_{0}'.format(int(self._api_version())) def _architecture_text(self): - architecture = self.executor.execute(['shell', 'getprop', 'ro.product.cpu.abi']) + architecture = self.executor.execute(self.args + ['shell', 'getprop', 'ro.product.cpu.abi']) return architecture.rstrip() def _locale(self): - persist_locale = self.executor.execute(['shell', 'getprop', 'persist.sys.locale']) - product_locale = self.executor.execute(['shell', 'getprop', 'ro.product.locale']) + persist_locale = self.executor.execute(self.args + ['shell', 'getprop', 'persist.sys.locale']) + product_locale = self.executor.execute(self.args + ['shell', 'getprop', 'ro.product.locale']) return persist_locale.rstrip() if persist_locale else product_locale.rstrip() diff --git a/plugin/src/py/android_screenshot_tests/pull_screenshots.py b/plugin/src/py/android_screenshot_tests/pull_screenshots.py index 88e20bf9..03057b18 100755 --- a/plugin/src/py/android_screenshot_tests/pull_screenshots.py +++ b/plugin/src/py/android_screenshot_tests/pull_screenshots.py @@ -506,6 +506,7 @@ def pull_screenshots(process, path_to_html = generate_html(temp_dir, test_img_api, old_imgs_data) device_name = device_name_calculator.name() if device_name_calculator else None + record_dir = join(record, device_name) if record and device_name else record verify_dir = join(verify, device_name) if verify and device_name else verify @@ -566,7 +567,6 @@ def main(argv): should_perform_pull = ("--no-pull" not in opts) multiple_devices = opts.get('--multiple-devices') - device_calculator = DeviceNameCalculator() if multiple_devices else NoOpDeviceNameCalculator() base_puller_args = [] if "-e" in opts: @@ -582,12 +582,16 @@ def main(argv): else: passed_serials = common.get_connected_devices() - if passed_serials: - puller_args_list = [base_puller_args + ["-s", serial] for serial in passed_serials] - else: - puller_args_list = [base_puller_args] + puller_args_list = [] + device_calculator_list = [] + for serial in (passed_serials or []): + puller_args_list.append(base_puller_args + ["-s", serial]) + device_calculator_list.append(DeviceNameCalculator(args=["-s", serial]) if multiple_devices else NoOpDeviceNameCalculator()) + if not len(puller_args_list): + puller_args_list.append(base_puller_args) + device_calculator_list.append(NoOpDeviceNameCalculator()) - for puller_args in puller_args_list: + for index, puller_args in enumerate(puller_args_list): pull_screenshots(process, perform_pull=should_perform_pull, temp_dir=opts.get('--temp-dir'), @@ -596,7 +600,7 @@ def main(argv): record=opts.get('--record'), verify=opts.get('--verify'), adb_puller=SimplePuller(puller_args), - device_name_calculator=device_calculator, + device_name_calculator=device_calculator_list[index], failure_dir=opts.get("--failure-dir"))