Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to record from multiple devices even if they connected at same time #238

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions plugin/src/py/android_screenshot_tests/device_name_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@

class DeviceNameCalculator:

def __init__(self, executor=AdbExecutor()):
def __init__(self, executor=AdbExecutor(), args = []):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of arbitrary args, I think it would be better if we explicitly had a property for the serial no

self.executor = executor
self.args = args

def name(self):
api_version_text = self._api_version_text()
Expand Down Expand Up @@ -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
Expand All @@ -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()
18 changes: 11 additions & 7 deletions plugin/src/py/android_screenshot_tests/pull_screenshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand All @@ -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'),
Expand All @@ -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"))


Expand Down