diff --git a/android/pylib/instrumentation/instrumentation_test_instance.py b/android/pylib/instrumentation/instrumentation_test_instance.py index 502167bc3..1d63f6b9a 100644 --- a/android/pylib/instrumentation/instrumentation_test_instance.py +++ b/android/pylib/instrumentation/instrumentation_test_instance.py @@ -389,6 +389,7 @@ class InstrumentationTestInstance(test_instance.TestInstance): self._driver_apk = None def _initializeTestControlAttributes(self, args): + self._screenshot_dir = args.screenshot_dir self._timeout_scale = args.timeout_scale or 1 def _initializeTestCoverageAttributes(self, args): @@ -430,6 +431,10 @@ class InstrumentationTestInstance(test_instance.TestInstance): def package_info(self): return self._package_info + @property + def screenshot_dir(self): + return self._screenshot_dir + @property def suite(self): return self._suite diff --git a/android/pylib/local/device/local_device_instrumentation_test_run.py b/android/pylib/local/device/local_device_instrumentation_test_run.py index 30118cf67..4b940dbd1 100644 --- a/android/pylib/local/device/local_device_instrumentation_test_run.py +++ b/android/pylib/local/device/local_device_instrumentation_test_run.py @@ -274,6 +274,15 @@ class LocalDeviceInstrumentationTestRun( if any(r.GetType() not in (base_test_result.ResultType.PASS, base_test_result.ResultType.SKIP) 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) for l in output: logging.info(' %s', l) diff --git a/android/test_runner.py b/android/test_runner.py index 4fc470015..c1f1e2a5b 100755 --- a/android/test_runner.py +++ b/android/test_runner.py @@ -337,7 +337,7 @@ def AddJavaTestOptions(argument_group): help=('Comma-separated list of annotations. Exclude tests with these ' 'annotations.')) argument_group.add_argument( - '--screenshot', dest='screenshot_failures', action='store_true', + '--screenshot-directory', dest='screenshot_dir', help='Capture screenshots of test failures') argument_group.add_argument( '--save-perf-json', action='store_true',