Added the --screenshot-directory option for Android instrumentation tests.

--screenshot option was broken for instrumentation tests. In this cl,
the option is enabled. With argument --screenshot, the device will take
a screenshot whenever an instrumentation test fails.

BUG=613405

Review-Url: https://codereview.chromium.org/1998383002
Cr-Original-Commit-Position: refs/heads/master@{#395662}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: 35d5e3dd14ae616db29806f3052b400f2de1945a
This commit is contained in:
hzl 2016-05-24 12:02:59 -07:00 коммит произвёл Commit bot
Родитель d2ab5bf923
Коммит 12e9cc4d86
3 изменённых файлов: 15 добавлений и 1 удалений

Просмотреть файл

@ -389,6 +389,7 @@ class InstrumentationTestInstance(test_instance.TestInstance):
self._driver_apk = None self._driver_apk = None
def _initializeTestControlAttributes(self, args): def _initializeTestControlAttributes(self, args):
self._screenshot_dir = args.screenshot_dir
self._timeout_scale = args.timeout_scale or 1 self._timeout_scale = args.timeout_scale or 1
def _initializeTestCoverageAttributes(self, args): def _initializeTestCoverageAttributes(self, args):
@ -430,6 +431,10 @@ class InstrumentationTestInstance(test_instance.TestInstance):
def package_info(self): def package_info(self):
return self._package_info return self._package_info
@property
def screenshot_dir(self):
return self._screenshot_dir
@property @property
def suite(self): def suite(self):
return self._suite return self._suite

Просмотреть файл

@ -274,6 +274,15 @@ class LocalDeviceInstrumentationTestRun(
if any(r.GetType() not in (base_test_result.ResultType.PASS, if any(r.GetType() not in (base_test_result.ResultType.PASS,
base_test_result.ResultType.SKIP) base_test_result.ResultType.SKIP)
for r in results): for r in results):
if self._test_instance.screenshot_dir:
file_name = '%s-%s.png' % (
test_display_name,
time.strftime('%Y%m%dT%H%M%S', time.localtime()))
saved_dir = device.TakeScreenshot(
os.path.join(self._test_instance.screenshot_dir, file_name))
logging.info(
'Saved screenshot for %s to %s.',
test_display_name, saved_dir)
logging.info('detected failure in %s. raw output:', test_display_name) logging.info('detected failure in %s. raw output:', test_display_name)
for l in output: for l in output:
logging.info(' %s', l) logging.info(' %s', l)

Просмотреть файл

@ -337,7 +337,7 @@ def AddJavaTestOptions(argument_group):
help=('Comma-separated list of annotations. Exclude tests with these ' help=('Comma-separated list of annotations. Exclude tests with these '
'annotations.')) 'annotations.'))
argument_group.add_argument( argument_group.add_argument(
'--screenshot', dest='screenshot_failures', action='store_true', '--screenshot-directory', dest='screenshot_dir',
help='Capture screenshots of test failures') help='Capture screenshots of test failures')
argument_group.add_argument( argument_group.add_argument(
'--save-perf-json', action='store_true', '--save-perf-json', action='store_true',