summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorvadimt <vadimt@google.com>2019-08-23 12:11:00 -0700
committervadimt <vadimt@google.com>2019-08-23 14:18:32 -0700
commitf13eaa02427ea536d9a3be077aa267f706f0a5e1 (patch)
tree3a6b513e9e4b5606f4c2d33956c20584d2a58a92 /tests
parent197ae725a0c59b56c55be27a82086fd3ad531399 (diff)
downloadandroid_packages_apps_Trebuchet-f13eaa02427ea536d9a3be077aa267f706f0a5e1.tar.gz
android_packages_apps_Trebuchet-f13eaa02427ea536d9a3be077aa267f706f0a5e1.tar.bz2
android_packages_apps_Trebuchet-f13eaa02427ea536d9a3be077aa267f706f0a5e1.zip
Saving screenshots for failures in NavigationModeSwitchRule
Change-Id: I732076a5eb14b181f560024e2780e2012a81fd95
Diffstat (limited to 'tests')
-rw-r--r--tests/src/com/android/launcher3/util/rule/FailureWatcher.java16
1 files changed, 10 insertions, 6 deletions
diff --git a/tests/src/com/android/launcher3/util/rule/FailureWatcher.java b/tests/src/com/android/launcher3/util/rule/FailureWatcher.java
index e7a2bcab6..cdda0f0dc 100644
--- a/tests/src/com/android/launcher3/util/rule/FailureWatcher.java
+++ b/tests/src/com/android/launcher3/util/rule/FailureWatcher.java
@@ -21,10 +21,10 @@ public class FailureWatcher extends TestWatcher {
mDevice = device;
}
- private void dumpViewHierarchy() {
+ private static void dumpViewHierarchy(UiDevice device) {
final ByteArrayOutputStream stream = new ByteArrayOutputStream();
try {
- mDevice.dumpWindowHierarchy(stream);
+ device.dumpWindowHierarchy(stream);
stream.flush();
stream.close();
for (String line : stream.toString().split("\\r?\\n")) {
@@ -37,7 +37,11 @@ public class FailureWatcher extends TestWatcher {
@Override
protected void failed(Throwable e, Description description) {
- if (mDevice == null) return;
+ onError(mDevice, description, e);
+ }
+
+ public static void onError(UiDevice device, Description description, Throwable e) {
+ if (device == null) return;
final String pathname = getInstrumentation().getTargetContext().
getFilesDir().getPath() + "/TestScreenshot-" + description.getMethodName()
+ ".png";
@@ -45,15 +49,15 @@ public class FailureWatcher extends TestWatcher {
", screenshot will be saved to " + pathname +
", track trace is below, UI object dump is further below:\n" +
Log.getStackTraceString(e));
- dumpViewHierarchy();
+ dumpViewHierarchy(device);
try {
- final String dumpsysResult = mDevice.executeShellCommand(
+ final String dumpsysResult = device.executeShellCommand(
"dumpsys activity service TouchInteractionService");
Log.d(TAG, "TouchInteractionService: " + dumpsysResult);
} catch (IOException ex) {
}
- mDevice.takeScreenshot(new File(pathname));
+ device.takeScreenshot(new File(pathname));
}
}