Skip to content

Commit

Permalink
Loop over serials in ANDROID_SERIAL when pulling images (#140) (#214)
Browse files Browse the repository at this point in the history
Summary:
I didn't figure out how to properly test this, as `SimplePuller` isn't injected. I have verified manually that this works for all combinations (no variable set, variable set with 1 value, with multiple values).

I decided to use `ANDROID_SERIAL` instead of looping over all available devices since it's supposed to work with connected tests as well (https://issuetracker.google.com/issues/36990135#comment14).
Pull Request resolved: #214

Differential Revision: D14623111

Pulled By: xiphirx

fbshipit-source-id: 67763485cf84400f18c4a8914929f1bc90a0e2dc
  • Loading branch information
lwasyl authored and facebook-github-bot committed Mar 26, 2019
1 parent 429fae7 commit 3983392
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 17 deletions.
11 changes: 10 additions & 1 deletion plugin/src/py/android_screenshot_tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
# limitations under the License.

import os
import sys
import re
import subprocess
import sys

def get_image_file_name(name, x, y):
image_file = name
Expand Down Expand Up @@ -46,3 +47,11 @@ def assertRegex(testcase, regex, string):
testcase.assertRegex(regex, string)
else:
testcase.assertRegexpMatches(regex, string)

def get_connected_devices():
try:
output = check_output([get_adb(), "devices"]).splitlines()
target_pattern = re.compile(r"\b(device|emulator)\b")
return [line.split()[0] for line in output if target_pattern.search(line) and "offline" not in line]
except subprocess.CalledProcessError:
return None
42 changes: 26 additions & 16 deletions plugin/src/py/android_screenshot_tests/pull_screenshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,28 +543,38 @@ def main(argv):

should_perform_pull = ("--no-pull" not in opts)

puller_args = []
multiple_devices = opts.get('--multiple-devices')
device_calculator = DeviceNameCalculator() if multiple_devices else NoOpDeviceNameCalculator()

base_puller_args = []
if "-e" in opts:
puller_args.append("-e")
base_puller_args.append("-e")

if "-d" in opts:
puller_args.append("-d")
base_puller_args.append("-d")

if "-s" in opts:
puller_args += ["-s", opts["-s"]]

multiple_devices = opts.get('--multiple-devices')
device_calculator = DeviceNameCalculator() if multiple_devices else NoOpDeviceNameCalculator()
passed_serials = [opts['-s']]
elif "ANDROID_SERIAL" in os.environ:
passed_serials = os.environ.get('ANDROID_SERIAL').split(",")
else:
passed_serials = common.get_connected_devices()

return pull_screenshots(process,
perform_pull=should_perform_pull,
temp_dir=opts.get('--temp-dir'),
filter_name_regex=opts.get('--filter-name-regex'),
opt_generate_png=opts.get('--generate-png'),
record=opts.get('--record'),
verify=opts.get('--verify'),
adb_puller=SimplePuller(puller_args),
device_name_calculator=device_calculator)
if passed_serials:
puller_args_list = [base_puller_args + ["-s", serial] for serial in passed_serials]
else:
puller_args_list = [base_puller_args]

for puller_args in puller_args_list:
pull_screenshots(process,
perform_pull=should_perform_pull,
temp_dir=opts.get('--temp-dir'),
filter_name_regex=opts.get('--filter-name-regex'),
opt_generate_png=opts.get('--generate-png'),
record=opts.get('--record'),
verify=opts.get('--verify'),
adb_puller=SimplePuller(puller_args),
device_name_calculator=device_calculator)


if __name__ == '__main__':
Expand Down

0 comments on commit 3983392

Please sign in to comment.