From cf1c28ef736170a4e6a21f242466f6e94eaa953a Mon Sep 17 00:00:00 2001 From: vadimt Date: Thu, 22 Jul 2021 16:00:53 -0700 Subject: [PATCH] Dump accessibility hierarchy on test failure This will allow seeing exactly what the test sees. Test: local runs Bug: 187761685 Change-Id: Ibf4b97bd9b99d4b40def4eb3db9a2cd1b47defb1 --- .../android/launcher3/util/rule/FailureWatcher.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/src/com/android/launcher3/util/rule/FailureWatcher.java b/tests/src/com/android/launcher3/util/rule/FailureWatcher.java index dc59bddabd..5fbf847ec6 100644 --- a/tests/src/com/android/launcher3/util/rule/FailureWatcher.java +++ b/tests/src/com/android/launcher3/util/rule/FailureWatcher.java @@ -61,13 +61,23 @@ public class FailureWatcher extends TestWatcher { out.putNextEntry(new ZipEntry("visible_windows.zip")); dumpCommand("cmd window dump-visible-window-views", out); out.closeEntry(); - } catch (IOException ex) { } + } catch (IOException ex) { + } Log.e(TAG, "Failed test " + description.getMethodName() + ",\nscreenshot will be saved to " + sceenshot + ",\nUI dump at: " + hierarchy + " (use go/web-hv to open the dump file)", e); device.takeScreenshot(sceenshot); + + // Dump accessibility hierarchy + final File accessibilityHierarchyFile = new File(parentFile, + "AccessibilityHierarchy-" + description.getMethodName() + ".uix"); + try { + device.dumpWindowHierarchy(accessibilityHierarchyFile); + } catch (IOException ex) { + Log.e(TAG, "Failed to save accessibility hierarchy", ex); + } } private static void dumpStringCommand(String cmd, OutputStream out) throws IOException {