summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuang Zhu <guangzhu@google.com>2012-06-19 14:39:01 -0700
committerThe Android Automerger <android-build@android.com>2012-06-19 16:29:56 -0700
commitc0ab5adadc869f4c97f01322960b018498f5c516 (patch)
tree80fe391878d8df53f599e69b4a0d40a03f03bd53
parent6ac3f28e72bc05dce35a3f8d2b6b095a3f4056da (diff)
downloadtesting-c0ab5adadc869f4c97f01322960b018498f5c516.tar.gz
consolidate uidump and uidebug command into uiautomator
uidump becomes 'uiautomator dump', it creates an XML dump of current UI tree uidebug becomes 'uiautomator events', it prints out accessibility events received from accessibility service Change-Id: I57bbb8cbac6965cc230b4c5c1df32e4dc6ab9dde
-rw-r--r--uiautomator/cmds/uiautomator/src/com/android/commands/uiautomator/DumpCommand.java72
-rw-r--r--uiautomator/cmds/uiautomator/src/com/android/commands/uiautomator/EventsCommand.java71
-rw-r--r--uiautomator/cmds/uiautomator/src/com/android/commands/uiautomator/Launcher.java2
3 files changed, 145 insertions, 0 deletions
diff --git a/uiautomator/cmds/uiautomator/src/com/android/commands/uiautomator/DumpCommand.java b/uiautomator/cmds/uiautomator/src/com/android/commands/uiautomator/DumpCommand.java
new file mode 100644
index 0000000..81c6489
--- /dev/null
+++ b/uiautomator/cmds/uiautomator/src/com/android/commands/uiautomator/DumpCommand.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.commands.uiautomator;
+
+import android.accessibilityservice.UiTestAutomationBridge;
+import android.os.Environment;
+
+import com.android.commands.uiautomator.Launcher.Command;
+import com.android.uiautomator.core.AccessibilityNodeInfoDumper;
+
+import java.io.File;
+
+/**
+ * Implementation of the dump subcommand
+ *
+ * This creates an XML dump of current UI hierarchy
+ */
+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()));
+ }
+
+}
diff --git a/uiautomator/cmds/uiautomator/src/com/android/commands/uiautomator/EventsCommand.java b/uiautomator/cmds/uiautomator/src/com/android/commands/uiautomator/EventsCommand.java
new file mode 100644
index 0000000..79428e9
--- /dev/null
+++ b/uiautomator/cmds/uiautomator/src/com/android/commands/uiautomator/EventsCommand.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.commands.uiautomator;
+
+import android.accessibilityservice.UiTestAutomationBridge;
+import android.view.accessibility.AccessibilityEvent;
+
+import com.android.commands.uiautomator.Launcher.Command;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+/**
+ * Implementation of the events subcommand
+ *
+ * Prints out accessibility events until process is stopped.
+ */
+public class EventsCommand extends Command {
+
+ private Object mQuitLock = new Object();
+
+ public EventsCommand() {
+ super("events");
+ }
+
+ @Override
+ public String shortHelp() {
+ return "prints out accessibility events until terminated";
+ }
+
+ @Override
+ public String detailedOptions() {
+ return null;
+ }
+
+ @Override
+ public void run(String[] args) {
+ final UiTestAutomationBridge bridge = new UiTestAutomationBridge() {
+ @Override
+ public void onAccessibilityEvent(AccessibilityEvent event) {
+ SimpleDateFormat formatter = new SimpleDateFormat("MM-dd HH:mm:ss.SSS");
+ System.out.println(String.format("%s %s",
+ formatter.format(new Date()), event.toString()));
+ }
+ };
+ bridge.connect();
+ // there's really no way to stop, essentially we just block indefinitely here and wait
+ // for user to press Ctrl+C
+ synchronized (mQuitLock) {
+ try {
+ mQuitLock.wait();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+}
diff --git a/uiautomator/cmds/uiautomator/src/com/android/commands/uiautomator/Launcher.java b/uiautomator/cmds/uiautomator/src/com/android/commands/uiautomator/Launcher.java
index 27c782b..bc1d948 100644
--- a/uiautomator/cmds/uiautomator/src/com/android/commands/uiautomator/Launcher.java
+++ b/uiautomator/cmds/uiautomator/src/com/android/commands/uiautomator/Launcher.java
@@ -129,5 +129,7 @@ public class Launcher {
private static Command[] COMMANDS = new Command[] {
HELP_COMMAND,
new RunTestCommand(),
+ new DumpCommand(),
+ new EventsCommand(),
};
} \ No newline at end of file