Skip to content

Instantly share code, notes, and snippets.

@enijkamp
Created May 23, 2014 15:21
Show Gist options
  • Save enijkamp/34f6b9d659b694578f2b to your computer and use it in GitHub Desktop.
Save enijkamp/34f6b9d659b694578f2b to your computer and use it in GitHub Desktop.
public class DumpCommand extends Command {
private static final File DEFAULT_DUMP_FILE = new File(
Environment.getExternalStorageDirectory(), "window_dump.xml");
public DumpCommand() {
super("dump");
}
@Override
public String shortHelp() {
return "creates an XML dump of current UI hierarchy";
}
@Override
public String detailedOptions() {
return " dump [file]\n"
+ " [file]: the location where the dumped XML should be stored, default is\n "
+ DEFAULT_DUMP_FILE.getAbsolutePath() + "\n";
}
@Override
public void run(String[] args) {
File dumpFile = DEFAULT_DUMP_FILE;
if (args.length > 0) {
dumpFile = new File(args[0]);
}
UiTestAutomationBridge bridge = new UiTestAutomationBridge();
bridge.connect();
// It appears that the bridge needs time to be ready. Making calls to the
// bridge immediately after connecting seems to cause exceptions. So let's also
// do a wait for idle in case the app is busy.
bridge.waitForIdle(1000, 1000 * 10);
AccessibilityNodeInfoDumper.dumpWindowToFile(
bridge.getRootAccessibilityNodeInfoInActiveWindow(), dumpFile);
bridge.disconnect();
System.out.println(
String.format("UI hierchary dumped to: %s", dumpFile.getAbsolutePath()));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment